OpenCV
3.0.0-rc1
Open Source Computer Vision
|
The goal of this tutorial is to learn how to calibrate a camera given a set of chessboard images.
Test data: use images in your data/chess folder.
Now, let us write a code that detects a chessboard in a new image and finds its distance from the camera. You can apply the same method to any object with known 3D geometry that you can detect in an image.
Test data: use chess_test*.jpg images from your data folder.
Mat img = imread(argv[1], IMREAD_GRAYSCALE);
bool found = findChessboardCorners( img, boardSize, ptvec, CALIB_CB_ADAPTIVE_THRESH );
FileStorage fs(filename, FileStorage::READ); Mat intrinsics, distortion; fs["camera_matrix"] >> intrinsics; fs["distortion_coefficients"] >> distortion;
vector<Point3f> boardPoints; // fill the array ... solvePnP(Mat(boardPoints), Mat(foundBoardCorners), cameraMatrix, distCoeffs, rvec, tvec, false);
Question: how to calculate the distance from the camera origin to any of the corners?