Hi, I have calibrated the camera of my LG phone using 30 checkerboard images. I have checked the found corners on the calibration images one by one, they are ok, on the right place between the squares. But when I use the camera intrinsic matrix, and the distortion coefficient matrix( which I obtained by the calibrateCamera() function) to undistort an image I get strange results.
Original image:
"undistorted" image:
the calibration code snippet :
void calibrateCamera(vector<string> imagefilePaths){
int numBoards = 30;
int numCornersHor = 9;
int numCornersVer = 7;
vector<vector<Point3f>> object_points;
vector<vector<Point2f>> image_points;
vector<Point2f> corners;
vector<Point3f> obj;
int numSquares = numCornersHor * numCornersVer;
Size board_sz = Size(numCornersHor, numCornersVer);
float scale =0.04;
for(int j=0;j<numSquares;j++){
obj.push_back(Point3f( (j/numCornersHor)*scale , (j%numCornersHor)*scale, 0.0f));
}
Mat image;
for(int i = 0; i < imagefilePaths.size(); i++ ){
image = imread( imagefilePaths[i], IMREAD_COLOR);
Mat gray_image;
cvtColor(image, gray_image, CV_BGR2GRAY);
bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);
if(found){
cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(gray_image, board_sz, corners, found);
}
imwrite( ("/home/gabor/cpp/ocv_test/chess_" + to_string(i) + ".jpg") , gray_image );
//imshow("win2", gray_image);
//int key = waitKey(1000);
if(found!=0){
image_points.push_back(corners);
object_points.push_back(obj);
}
}
Mat intrinsic = Mat(3, 3, CV_32FC1);
Mat distCoeffs;
vector<Mat> rvecs;
vector<Mat> tvecs;
calibrateCamera(object_points, image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs);
/*FileStorage fs("/home/gabor/cpp/ocv_test/calibration/LGK5_.yml", FileStorage::WRITE);
fs << "intrinsics" << intrinsic;
fs << "distortion_coefficients" << distCoeffs;
fs << "translation vectors" << tvecs;
fs.release();
*/
}
Is it something with the corner finding parameters? Thanks.