二维点的椭圆精度

时间:2019-04-03 18:49:26

标签: python opencv image-processing

我有一个椭圆,该椭圆是我使用opencv从图像中检测到的,其中椭圆定义为org 100h MOV AH, 1 ; Get user input INT 21H DEC AL ; Dec AL to satisfy the condition that it will print till < input MOV BL,31H ; Initialize BL so that the output starts printing from 1 MOV CL,Al ; set counter register CX MOV CH,00 Print: MOV AH, 2 ; for output printing MOV DL,0DH ; for output printing INT 21H ; for output printing MOV DL,0AH ; for output printing INT 21H ; for output printing MOV AH,2 MOV DL,BL ; print what is in BL INT 21H INC BL ; then increment BL LOOP Print ; supposed to run the loop on Print what is the value in CL times hlt 。我还有(x_centre,y_centre),(minor_axis,major_axis),angle形式的点列表,这些点定义了椭圆在图像中的位置。

如何从点定义的椭圆中找到所找到的椭圆的精度?

更新

为了更好地理解,这是我的实际脚本导致的: ellipse detection。从图像中检测到红色椭圆,而仅从文件中加载了绿点。

缺少准确的示例:ellipse detection 2

我需要一些方法来验证椭圆到外部点的精确度。

1 个答案:

答案 0 :(得分:0)

此答案描述了一种找到所找到的椭圆与点列表所定义的椭圆的匹配程度的方法。

第一步是创建蒙版图像,并在其上绘制椭圆。

mask = np.zeros((img.shape[0], img.shape[1]), np.uint8)
mask = cv2.ellipse(mask, ellipse, 255, 5)

接下来,遍历点列表并检查它们是否在蒙版图像的白色部分或黑色部分中。

hit, miss = 0,0
for point in cnt:
    if mask[point[0][1], point[0][0]] == 0: miss += 1
    else: hit += 1

这是一个非常适合的椭圆: good fit

这是一个不太适合的椭圆形: bad fit

可以在函数cv2.pointsPolygonTest的帮助下找到此RMSE

_,ellipse_contours,hierarchy = cv2.findContours(mask, 1, 2)
ellipse_contour = ellipse_contours[0]
for point in cnt:
    total_dist += cv2.pointPolygonTest(ellipse_contour, tuple(point[0]), True)**2
rmse = math.sqrt(total_dist/len(cnt))
相关问题