OpenCV(cv2)Python findChessboardCorners在看似简单的棋盘上失败 [英] OpenCV (cv2) Python findChessboardCorners failing on seemingly simple chessboard

查看:1256
本文介绍了OpenCV(cv2)Python findChessboardCorners在看似简单的棋盘上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从相机上拍摄了以下棋盘图像:

I have the following images of a chessboard taken from a camera:

这是我最小的工作示例代码:

Here is my minimal working example code:

import cv2
print(cv2.__version__)
left_gray = cv2.imread('left_raw.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
print(left_gray.shape)
ret, left_corners  = cv2.findChessboardCorners(left_gray, (6,5))
print(left_corners)

以下是输出,指示未找到任何角点:

And here is the output, indicating that no corners were found:

2.4.13.1
(1080, 1920)
None

我阅读了其他StackOverflow问题:

I read several other StackOverflow questions:

  1. 此问题与opencv2有关在看似简单的场景"中失败,但是我相信我拥有的图像要简单得多,因为该图像具有完全裁剪的棋盘版本.就我而言,我有一个棋chess,放在白色打印机纸上面.
  2. 此问题是关于高分辨率图像.我不确定我使用的相机是否是高分辨率的,但是我的图像与该问题有所不同,因为这里的棋盘(大致)居中且没有完全歪斜.
  3. 这个问题是关于完美"棋盘的故障.但是,那是对称的,而我的图像却不是对称的(它有6行7列),我在棋盘上使用(5,6)的输入.我还尝试了(6,5)以防万一我倒退但没有运气.
  4. 此问题是关于有人弄错了尺寸.用户声称如果我们有(10,7)板,则该函数的输入应为(9,7),其中10 =列数,7 =原始板上的行数.但是,我认为我们必须从两个维度中减去一个.无论如何,我都尝试对图像使用(7,5)和其他一些变体,但是没有一种情况有效.
  5. 这个问题是关于MATLAB的,但是代码不应该与Python截然不同,即使在比我复杂得多的情况下,该用户也能成功检测到图像.
  1. This question is about opencv2 failing in a "seemingly simple scenario" but I believe that the images I have are much more simple because this one had a completely cropped out chessboard version. In my case I have a chessboard which I put on top of some white printer paper.
  2. This question is about a failure on high-resolution images. I'm not sure if the camera I'm using is high-res but my image is different from that question since the chessboard here is (roughly) centered and isn't completely skewed.
  3. This question is about a failure on a "perfect" chessboard. However, that one was symmetric, whereas my image is not symmetric (it has 6 rows and 7 columns) and I'm using the input of (5,6) for my chessboard. I also tried (6,5) in case I got it backward but no luck.
  4. This question was about someone getting the dimensions wrong. The user claims that if we have a (10,7) board, the input to the function should be (9,7) where 10=number of columns, 7=number of rows in original board. However, I think we have to subtract one from both dimensions. In any case, I tried using (7,5) and a few other variants for my image but none of the cases work.
  5. This question is about MATLAB but the code shouldn't be too different from Python, and that user saw some success in detecting images even for a much more complicated scenario than what I have.

在这一点上,我对如何找到弯角有些迷茫.有没有人想分享一些建议?图像和代码就在这里,以防您需要对其进行测试.我还应该指出,在拍摄图像时我尝试增加原始相机的亮度,但是没有运气.

I'm a little lost at this point about how to find the corners. Does anyone have some advice they would like to share? The image and code are right here in case you wish to test them out. I should also point out that I tried increasing the brightness of the original camera when taking the image but no luck.

推荐答案

使用cv2.goodFeaturesToTrack()我能够获得令人满意的结果.

I was able to obtain a satisfactory result using cv2.goodFeaturesToTrack().

代码:

corners = cv2.goodFeaturesToTrack(gray_img,25,0.01,10)
corners = np.int0(corners)

for i in corners:
    x,y = i.ravel()
    cv2.circle(img,(x,y),3,(0,0,255),-1)

cv2.imshow('Corners',img)

我知道它不准确,但是通过一些预处理,您应该可以获得更好的结果.

I know it is not accurate, but with some pre-processing you should be able to obtain a better result.

:D

这篇关于OpenCV(cv2)Python findChessboardCorners在看似简单的棋盘上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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