如何解决错误?
我使用了为OpenCV2.x制作的程序,但我在OpenCV3.0上编译了它,出现了错误。我将CvTermCriteria更改为TermCriteria::TermCriterias,但这不起作用。如何将CvTermCriteria更改为int?
希望有人能帮我。谢谢
此部分出现错误:
cvStereoCalibrate( &_objectPoints, &_imagePoints1, &_imagePoints2, &_npoints,&_M1calib, &_D1, &_M2calib, &_D2,imageSize, &_R, &_Tcalib, &_E, &_F,
cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_FIX_ASPECT_RATIO+CV_CALIB_ZERO_TANGENT_DIST + CV_CALIB_SAME_FOCAL_LENGTH );
这是源代码:
//--------------Compute for calibration-------------------
N = n_boards*n;
objectPoints.resize(N);
for( i = 0; i < ny; i++ )
for(j = 0; j < nx; j++ ) objectPoints[i*nx + j] = cvPoint3D32f(i*squareSize, j*squareSize, 0);
for( i = 1; i < n_boards; i++ ) copy( objectPoints.begin(), objectPoints.begin() + n, objectPoints.begin() + i*n );
npoints.resize(n_boards,n);
CvMat _objectPoints = cvMat(1, N, CV_32FC3, &objectPoints[0] );
CvMat _imagePoints1 = cvMat(1, N, CV_32FC2, &points[0][0] );
CvMat _imagePoints2 = cvMat(1, N, CV_32FC2, &points[1][0] );
CvMat _npoints = cvMat(1, npoints.size(), CV_32S, &npoints[0] );
cvSetIdentity(&_M1calib);
cvSetIdentity(&_M2calib);
cvZero(&_D1);
cvZero(&_D2);
printf("nRunning stereo calibration ...");
fflush(stdout);
cvStereoCalibrate( &_objectPoints, &_imagePoints1, &_imagePoints2, &_npoints,&_M1calib, &_D1, &_M2calib, &_D2,imageSize, &_R, &_Tcalib, &_E, &_F,
cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_FIX_ASPECT_RATIO+CV_CALIB_ZERO_TANGENT_DIST + CV_CALIB_SAME_FOCAL_LENGTH );
printf("nDone Calibration");
cvUndistortPoints( &_imagePoints1, &_imagePoints1,&_M1calib, &_D1, 0, &_M1calib );
cvUndistortPoints( &_imagePoints2, &_imagePoints2,&_M2calib, &_D2, 0, &_M2calib );
CvMat* mx1calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F );
CvMat* my1calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F );
CvMat* mx2calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F );
CvMat* my2calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F );
double R1[3][3], R2[3][3], P1[3][4], P2[3][4];
CvMat _R1 = cvMat(3, 3, CV_64F, R1);
CvMat _R2 = cvMat(3, 3, CV_64F, R2);
CvMat _P1 = cvMat(3, 4, CV_64F, P1);
CvMat _P2 = cvMat(3, 4, CV_64F, P2);
cvStereoRectify( &_M1calib, &_M2calib, &_D1, &_D2, imageSize,&_R, &_Tcalib,&_R1, &_R2, &_P1, &_P2, &_Qcalib,0/*CV_CALIB_ZERO_DISPARITY*/ );
cvInitUndistortRectifyMap(&_M1calib,&_D1,&_R1,&_P1,mx1calib,my1calib);
cvInitUndistortRectifyMap(&_M2calib,&_D2,&_R2,&_P2,mx2calib,my2calib);
printf("nSaving matries for later use ...n");
cvSave("CalibFile//M1.yml",&_M1calib);
// cvSave("CalibFile//D1.yml",&_D1);
// cvSave("CalibFile//R1.yml",&_R1);
// cvSave("CalibFile//P1.yml",&_P1);
cvSave("CalibFile//M2.yml",&_M2calib);
// cvSave("CalibFile//D2.yml",&_D2);
// cvSave("CalibFile//R2.yml",&_R2);
// cvSave("CalibFile//P2.yml",&_P2);
cvSave("CalibFile//Q.yml",&_Qcalib);
cvSave("CalibFile//T.yml",&_Tcalib);
cvSave("CalibFile//mx1.yml",mx1calib);
cvSave("CalibFile//my1.yml",my1calib);
cvSave("CalibFile//mx2.yml",mx2calib);
cvSave("CalibFile//my2.yml",my2calib);
交换stereoCalibrate
的最后两个参数
在OpenCV>=3.0中,stereoCalibrate
的签名发生了更改,并且您需要简单地交换最后两个参数,flags
和criteria
。
过时的C版本,OpenCV<3.0
C: 双cvStereoCalibrate),int标志=CV_CALIB_FIX_INCINIC)
C++版本,OpenCV<3.0
C++:双立体校准(InputArrayOfArrays objectPoints,InputArrayOfArrays imagePoints1,InputArrayOfArrays imagePoints2,InputOutputArray camera Matrix1,InputOutput Array distCoeffs1,InputOutoutputArray cameraMatrix2,InputOutputArray distCoffs2,Size imageSize,OutputArray R,OutputArray T,OutputArray E,Outputrray F,TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS,30,1e-6),int flags=CALIB_FIX_INTRINSIC)
C++版本,OpenCV>=3.0
double cv::stereoCalibrate(InputArrayOfArrays对象点,InputArrayOfArrays imagePoints1,InputArrayOfArrays imagePoints2,InputOutputArray cameraMatrix1,InputOutputArray distCoeffs1,InputOutputArray cameraMatrix2,InputOutputArray distCoeffs2,大小图像大小,输出阵列R,OutputArray T,输出阵列E,输出阵列F,int标志=CALIB_FIX_INTRINSIC,TermCriteria标准=TermCriteria(TermCriteria::COUNT+TermCriteria:EPS,30,1e-6))
您的代码使用的是C api,这是过时的。您现在真的应该考虑使用C++api了。