1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| void CameraCalibration::findCorners(std::string filename, bool &found, int X, int Y) { std::stringstream imgfile; imgfile << filename << ".jpg"; cv::Mat img = cv::imread(imgfile.str().c_str()); cv::vector<cv::Point2f> cCam;
cv::Mat img_copy; cv::Mat img_grey; img.copyTo(img_copy);
cv::cvtColor(img, img_grey, CV_RGB2GRAY); img.copyTo(img_copy);
found=cv::findChessboardCorners(img_grey, cvSize(X,Y), cCam, CV_CALIB_CB_ADAPTIVE_THRESH );
if(!found) return; if(found) { cv::cvtColor( img, img_grey, CV_RGB2GRAY ); cv::cornerSubPix(img_grey, cCam, cvSize(20,20), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1)); }
void CameraCalibration::cameraCalibration() { cv::vector<cv::Mat> camRotationVectors; cv::vector<cv::Mat> camTranslationVectors;
cv::calibrateCamera(ObjCorners, CamCorners, camImageSize, camMatrix, distortion, camRotationVectors,camTranslationVectors,0, cv::TermCriteria( (cv::TermCriteria::COUNT)+(cv::TermCriteria::EPS), 30, DBL_EPSILON) );
exportTxtFiles("matrix.txt", CAMCALIB_OUT_MATRIX); exportTxtFiles("distortion.txt", CAMCALIB_OUT_DISTORTION); }
|