在大图像中使用findCirclesGrid()

时间:2016-09-26 12:52:56

标签: python opencv camera-calibration

我在Python 2.7中使用OpenCV 3来校准不同的相机。我使用findCirclesGrid()函数,它在100万像素的图像中成功找到4 by 11 circle pattern。但是,当我尝试在具有更高分辨率的图像中近距离检测图案时,该功能失败。当物体在图像中更远时,仍然会检测到它。我使用如下函数:

ret, corners = cv2.findCirclesGrid(image, (4, 11), flags=cv2.CALIB_CB_ASYMMETRIC_GRID)

对于较大的图片,它会返回False, None。似乎该函数无法处理具有太大区域的圆。我尝试添加cv2.CALIB_CB_CLUSTERING,但这似乎没有什么区别。此外,似乎在C ++中,用户可以表示使用blobdetector,但不能在Python中使用。详情:http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findcirclesgrid

我可以以某种方式增加最大检测大小或使功能以另一种方式检测模式吗?

编辑:我找到了如何使用

编辑blobDetector的参数
params = cv2.SimpleBlobDetector_Params()
params.maxArea = 100000
detector = cv2.SimpleBlobDetector_create(params)
ret, corners = cv2.findCirclesGrid(self.gray, (horsq, versq), None,
                flags=cv2.CALIB_CB_ASYMMETRIC_GRID, blobDetector=detector)

但问题仍然存在。

EDIT2: 现在添加cv2.CALIB_CB_CLUSTERING可以解决问题!

1 个答案:

答案 0 :(得分:0)

您可能需要做的主要是调整斑点检测器的最小区域和最大区域。 使用参数创建斑点检测器(不要使用默认参数),并调整检测器将接受的minarea和max区域。在将已创建的检测器传递给findcirclesgrid函数之前,您可以先显示所有找到的blob。

Python示例代码

params = cv2.SimpleBlobDetector_Params()
# Setup SimpleBlobDetector parameters.
print('params')
print(params)
print(type(params))


# Filter by Area.
params.filterByArea = True
params.minArea = 200
params.maxArea = 18000

params.minDistBetweenBlobs = 20


params.filterByColor = True
params.filterByConvexity = False

# tweak these as you see fit
# Filter by Circularity
# params.filterByCircularity = False
params.minCircularity = 0.2

# # # Filter by Convexity
# params.filterByConvexity = True
# params.minConvexity = 0.87

# Filter by Inertia
params.filterByInertia = True
# params.filterByInertia = False
params.minInertiaRatio = 0.01

detector = cv2.SimpleBlobDetector_create(params)

# Detect blobs.
keypoints = detector.detect(gray)

im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)



fig = plt.figure()
im_with_keypoints = cv2.drawKeypoints(gray, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
plt.imshow(cv2.cvtColor(im_with_keypoints, cv2.COLOR_BGR2RGB),
           interpolation='bicubic')

titlestr = '%s found %d keypoints' % (fname, len(keypoints))
plt.title(titlestr)

fig.canvas.set_window_title(titlestr)


ret, corners = cv2.findCirclesGrid(gray, (cbcol, cbrow), flags=(cv2.CALIB_CB_ASYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING ), blobDetector=detector )