I'm trying to calibrate my camera. For it as I read I need to make some test -> findChessboard; I have got real chess and I took it's picture(it is 8x4) and I set Size(8-1,4-1)->Size(7,3) Bot boards set to 32 (As 4 times 8 gives me 32(Or I should write 7*3->21)). And It says me false when I want to find ChessBoard;
There will be picture of this chessboard.:
I have tried all ways to findChessboardCorners->I gave it flags as CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FILTER_QUADS or CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_FILTER_QUADS. It didn't worked too. I have tried to give it image colored(non-gray) image it didn't worked too. What I should do?
Code what I have tried to do:
VideoCapture vc(0);
int numBoards = 0;
int numCornersHor;
int numCornersVer;
printf("Enter number of corners along width: ");
scanf("%d", &numCornersHor);
printf("Enter number of corners along height: ");
scanf("%d", &numCornersVer);
printf("Enter number of boards: ");
scanf("%d", &numBoards);
int numSquares = numCornersHor * numCornersVer;
Size board_sz = Size(numCornersHor, numCornersVer);
vector<vector<Point3f>> object_points;
vector<vector<Point2f>> image_points;
vector<Point2f> corners;
int successes = 0;
Mat image;
Mat gray_image;
vc >> image;
for (int j = 0; j < numSquares; j++)
obj.push_back(Point3f(j / numCornersHor, j % numCornersHor, 0.0f));
while (successes < numBoards)
{
if (image.empty())break;
cvtColor(image, gray_image, COLOR_BGR2GRAY);
bool found = findChessboardCorners
(image, board_sz, corners, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FILTER_QUADS);
if (found)
{
cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(TermCriteria::EPS | TermCriteria::MAX_ITER, 30, 0.1));
drawChessboardCorners(gray_image, board_sz, corners, found);
}
imshow("win1", image);
imshow("win2", gray_image);
if (image.empty())break;
vc >> image;
int key = waitKey(1);
if (key == 27)
return 0;
if (key == ' ' && found != 0)
{
image_points.push_back(corners);
object_points.push_back(obj);
printf("Snap stored!");
successes++;
if (successes >= numBoards)
break;
}
}
Looking at your input image I see two problems which likely cause the corner detection to fail.
First, the image is way to dark. Provide some diffuse lighting. Otherwise, even if the corners should be detected the sensor noise is so high that the precision of the detection will be abysmal.
Second, as is stated in the OpenCV documentation of findChessboardCorners()
:
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.
I would recommend to print out a high quality board image with sufficient white border like this, glue it to some sturdy flat surface (e.g. a wooden board) and perform the calibration in a well lit environment. This way it should not only detect the corners but the accuracy of the detection should be way better than with the setup you are using.
If you want additional hints for high quality camera calibration look at this answer.