python opencv 圆形roi
【摘要】
拟合圆:
#! /usr/bin/env python# -*- coding: utf-8 -*-import cv2from numpy import *from scipy import optimizeimport functools def countcalls(fn): @functools.wraps(fn) ...
拟合圆:
-
#! /usr/bin/env python
-
# -*- coding: utf-8 -*-
-
import cv2
-
from numpy import *
-
from scipy import optimize
-
import functools
-
-
def countcalls(fn):
-
@functools.wraps(fn)
-
def wrapped(*args):
-
wrapped.ncalls +=1
-
return fn(*args)
-
-
wrapped.ncalls = 0
-
return wrapped
-
-
def calc_R(xc, yc):
-
return sqrt((xx - xc) ** 2 + (yy - yc) ** 2)
-
@countcalls
-
def f_2(c):
-
Ri = calc_R(*c)
-
return Ri - Ri.mean()
-
-
def nihe(xx,yy):
-
# 质心坐标
-
x_m = mean(xx)
-
y_m = mean(yy)
-
#圆心估计
-
center_estimate = x_m, y_m
-
center_2, _ = optimize.leastsq(f_2, center_estimate)
-
-
xc_2, yc_2 = center_2
-
Ri_2 = calc_R(xc_2, yc_2)
-
#拟合圆的半径
-
R_2 = Ri_2.mean()
-
residu_2 = sum((Ri_2 - R_2)**2)
-
residu2_2 = sum((Ri_2**2-R_2**2)**2)
-
ncalls_2= f_2.ncalls
-
-
#输出列表
-
# fmt = '%-22s %10.5f %10.5f %10.5f %10d %10.6f %10.6f %10.
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/122182707
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)