OpenCV findChessboardCorners function is failing in a (apparently) simple scenario

こ雲淡風輕ζ 提交于 2019-11-29 07:33:59

There are two changes needed to make that image acceptable to the very finicky cv2.findChessboardCorners function. First, the chess board needs a white background. I obtained this simply by adjusting the contrast on your image. Second, I also had to white-out the dark horizontal line that connects the black squares at the top and bottom of your chess board. This is the resulting image:

With these enhancements, cv2.findChessboardCorners can successfully analyze the image. The results were:

camera matrix =
    [[  1.67e+04   0.00e+00   1.02e+03]
    [  0.00e+00   1.70e+04   5.45e+02]
    [  0.00e+00   0.00e+00   1.00e+00]]

distortion coefficients = [ -4.28e+00   1.38e+03  -8.59e-03  -1.49e-02   6.93e+00]

(Small changes to how the image is enhanced can change the above results greatly. With only one image of a small chess board, these results are not to be trusted.)

As you noted, cv2.findChessboardCorners accepts flags (adaptive threshold, filter_quads, and normalization) that are intended to help with chess board recognition. I tried all but they made no difference here.

I bet you $5 that the image thresholding inside findChessboardCorners is producing garbage because of the background in the masked image.

I recommend doing a crop, extracting the chessboard, then offsetting the coordinates of the found corners by the crop window position.

Add white space around the chess pattern. "Note: The function requires white space (like a square-thick border, the wider the better) around the board to make the detection more robust in various environments. Otherwise, if there is no border and the background is dark, the outer black squares cannot be segmented properly and so the square grouping and ordering algorithm fails. "

Engine

I'm working on almost the same problem, but in c++. The function findChessboardCorners doesn't always recognized the chessboard with the given size, and seeing as your image's lighting isn't spread on the chessboard, I think this makes a difference. My suggestion is to decreasethe size of your chessboard until you find something. !!

The detectCheckerboardPoints function in the Computer Vision System Toolbox for Matlab detects it, but it gives you an extra column:

You should be able to get rid of the extra column on the right but moving the right edge of the selected region a little to the left.

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