Ask Your Question
0

findCirclesGrid in Python

asked 2012-10-14 03:54:10 -0600

jlsb gravatar image

updated 2012-10-30 23:34:18 -0600

I am having some difficulty finding out how to get findCirclesGrid() in the cv2 module working in Python. Here's what I'm using for parameters:

image: an image in the form of a numpy ndarray. patternSize: tuple containing my width and height of the pattern; my case is (4,11) flags: cv2.CALIB_CB_ASYMMETRIC_GRID since my grid is asymmetric

The function executes without an error. The first return value is always False, which seems to indicate that the pattern could not be detected. The second return value, centers, is an numpy ndarray. It looks like this typically:

[[[ 150.26068115 149.73667908]] [[179.99241638 150.15336609]] [[ 210.01210022 149.9016571 ]] [[ 240.06182861 149.86331177]] [[ 149.89584351 180.01303101]] [[ 179.57373047 180.05331421]] [[ 210.33233643 180.1463623 ]] [[ 239.53469849 180.49691772]] [[ 150.08843994 210.23040771]] [[ 180.15136719 209.93945312]] [[ 209.52470398 209.71012878]] [[ 240.57177734 209.7552948 ]]]

Although the first return value is False, I still try to display to the centers using drawChessboardCorners(image,patternSize,True). Then I display the results using cv.ShowImage(), where I first convert the image from an ndarray to an image using cv.fromarray(). The centers are certainly in the wrong locations.

I have tried using a sample image. Even the results from this are not working. The code I am using looks like this:

img = scipy.misc.imread('/mypath/myimage.png')    
cv2.findCirclesGrid(img, (3,11), flags=cv2.CALIB_CB_ASYMMETRIC_GRID)

I am not sure if the problem is due to my images or due to my code. Any advice would be greatly appreciated. Thanks!

JL

Sample image: image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-10-30 23:33:15 -0600

Hi,

Your pattern in the sample image is either too distorted or it was generated incorrectly (points have to be in specific locations, just visual similarity to the OpenCV pattern is not enough). According to documentation the flag CALIB_CB_CLUSTERING is suitable in such cases because you have distortion but don't have background clutter. Code becomes:

image = cv2.imread('/mypath/myimage.png')
shape = (3, 11)
[isFound, centers] = cv2.findCirclesGrid(image, shape, flags = cv2.CALIB_CB_ASYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING)

This code works for me and your sample image: isFound is True and detected centers have correct locations.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-10-14 03:54:10 -0600

Seen: 10,875 times

Last updated: Oct 30 '12