OpenCV findChessboardCorners函数在一个(显然)简单的情况下失败 [英] OpenCV findChessboardCorners function is failing in a (apparently) simple scenario

查看:8975
本文介绍了OpenCV findChessboardCorners函数在一个(显然)简单的情况下失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用OpenCV找到棋盘的角落。

I'm trying to find the corners of a chessboard using OpenCV.

我使用的图像包含两个棋盘,但我只感兴趣子区域之一。
下面的图片显示了原始图片。

The image I'm using contains two chessboards, but I'm interested only in a sub-region of one of those.The following image shows the original image.

使用GIMP,我选择了感兴趣的区域,并将所有其他像素设置为默认值。

Using GIMP, I've then selected the area of interest and I've set all the other pixel to a default value.

我没有实际裁剪图像,因为我已经校准了使用这个图像大小的相机,我不想改变它。
该操作应该等效于更改图像矩阵中的值,但我更喜欢使用GIMP。

I haven't actually cropped the image because I've already calibrated the camera using this image size and I didn't want to change it.The operation should be equivalent to change the values in the image matrix, but I preferred to do it with GIMP. It is a one time experiment and it is faster to do that operation with a graphic tool instead of using the code.

生成的图片包含一个带有24x5角的棋盘,但是这个图片包含一个图形工具,而不是使用代码。函数findChessboardCorners找不到任何东西。

The resulting image contains a chessboard with 24x5 corners, but the function findChessboardCorners is not able to find anything.

这是我使用的Python代码:

Here is the Python code I'm using:

>>> img = cv2.imread('C:\\Path\\To\\C4-Cropped.png', 0)>>> cv2.findChessboardCorners(img, (24, 5))(False, None)>>> cv2.findChessboardCorners(img, (5, 24))(False, None)

我也尝试设置自适应阈值,但它仍然不工作

I also tried to set the adaptive threshold, but it is still not working

>>> cv2.findChessboardCorners(img, (24, 5), flags=cv2.cv.CV_CALIB_CB_ADAPTIVE_THRESH)(False, None)

这似乎很奇怪。我过去使用了OpenCV的这个功能很多次,它总是工作,即使图像看起来比这个更复杂的
该区域的照明不是均匀的,但是该函数应该足够强大以处理这个问题。

That seems really strange. I used this function of OpenCV many times in the past and it always worked, even with images that looked much more complicated than this one.The illumination of the area is not homogeneous but the function should be robust enough to handle that.

使用GIMP创建的图像?
如何找到角落?

Is there any problem with the artificial image created ad hoc with GIMP?How can I find the corners?

任何建议都将非常感激。

Any suggestion would be greatly appreciated.

推荐答案

我知道我晚了几个月的聚会,但有两个变化需要使这个图像可以接受的非常finicky cv2.findChessboardCorners函数。首先,棋盘需要一个白色背景。我只是通过调整您的图像的对比度获得这一点。第二,我也不得不把连接棋盘顶部和底部黑色方块的暗水平线变白。您可以在http://i.stack.imgur.com/ouyVc.png

I know I am a few months late to the party, but 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. You can see the resulting image at http://i.stack.imgur.com/ouyVc.png

通过这些增强功能,cv2.findChessboardCorners可以成功分析图像。结果是:

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]



正如你所说,cv2.findChessboardCorners接受旨在帮助棋盘识别的标志(自适应阈值,filter_quads和规范化)。我试过所有,但他们没有改变这里。

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.

这篇关于OpenCV findChessboardCorners函数在一个(显然)简单的情况下失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆