简体   繁体   中英

open cv python error when trying to find chessboard corners

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.

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM