Using findCirclesGrid() in large images

落花浮王杯 提交于 2019-12-11 05:04:04

问题


I am using OpenCV 3 in Python 2.7 to calibrate different cameras. I use the findCirclesGrid() function, which succesfully finds a 4 by 11 circle pattern in a 1 Megapixel image. However, when I try to detect the pattern up close in an image with a higher resolution, the function fails. When the object is farther away in the image, it is still detected. I use the function as follows:

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

With larger images, it returns False, None. It seems that the function can't handle circles that have a too large area. I tried adding cv2.CALIB_CB_CLUSTERING, but this doesn't seem to make a difference. Also, it seems that in C++ the user can signify the use of blobdetector, but not in Python. Details: http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findcirclesgrid

Can I increase the maximum detection size somehow or make the function detect the pattern in another way?

Edit: I found out how to edit parameters of the blobDetector by using

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)

Still the same issue, though.

Edit2: Now adding cv2.CALIB_CB_CLUSTERING resolves the issue!


回答1:


The main thing you probably need to do is tweak the min area and max area of the blob detector. Create a blob detector with params (don't use the default parameters), and adjust the minarea and max area that the detector will accept. You can first just show all the found blobs before you pass the detector that you have created into the findcirclesgrid function.

Python Sample code

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 )


来源:https://stackoverflow.com/questions/39703407/using-findcirclesgrid-in-large-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!