open cv python error when trying to find chessboard corners

拥有回忆 提交于 2019-12-11 04:14:16

问题


I have to write a camera-calibration an wanted to use python and opencv. The current problem I have is the following:

I have the code written down below:

import sys
import numpy as np
import cv2

image = cv2.imread(sys.argv[1])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

ret = False
ret, corners = cv2.findChessboardCorners(image, (7,6), None)

print ret

okay so far so good, but it doesn't matter which image I am using my ret variable is turning False every single time, which basically means that there were no corners found.

There are some questions about this problem here on stack overflow but none of the solutions there would work for my problem. I tried using Images from 500x500 up to 8MP, I sharpened them afterwards, I even used the original Chessboards to get the corners. None of them worked.

Is there another way to get them or am I doing anything complete false from the ground up?

I also tried using the images without grayscale but the problem is the same.


回答1:


Okay, I found out what the problem was.

The thing I didn't know before was that the dimensions you have to enter are original dimensions of the chessboard minus 1:

So if you have a 10 x 7 board, the dimensions to use are 9 x 6.

Maybe this will be helpful for other people having the same problem.

Update: Fixed a critical typo. Dimensions to use are 9 x 6, not 9 x 7.




回答2:


thanks hGen. your answer was really helpful. but in my case 9X6 worked (not 9X7).

cv::Mat imgClr = cv::imread( "05-00.png" );
cv::Mat imgGray;
cv::cvtColor( imgClr, imgGray, CV_BGR2GRAY );
cv::namedWindow( "Image", cv::WINDOW_NORMAL );
cv::imshow( "Image", imgGray );
cv::waitKey(0);

cv::Size board_sz = cv::Size(9, 6);
std::vector < cv::Point2f > corners;
bool found = cv::findChessboardCorners(imgGray, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE
                                       | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_FILTER_QUADS );
if(found)
{
    cv::drawChessboardCorners(imgGray, board_sz, corners, found);
    cv::imshow( "Image", imgGray );
    cv::waitKey(0);
}


来源:https://stackoverflow.com/questions/27189893/open-cv-python-error-when-trying-to-find-chessboard-corners

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