fixed 3calibration sample
This commit is contained in:
parent
caa3076018
commit
18ce63ffdb
@ -42,9 +42,13 @@ static bool run3Calibration( vector<vector<Point2f> > imagePoints1,
|
|||||||
{
|
{
|
||||||
const vector<vector<Point2f> >& imgpt0 = c == 1 ? imagePoints1 : c == 2 ? imagePoints2 : imagePoints3;
|
const vector<vector<Point2f> >& imgpt0 = c == 1 ? imagePoints1 : c == 2 ? imagePoints2 : imagePoints3;
|
||||||
imgpt.clear();
|
imgpt.clear();
|
||||||
|
int N = 0;
|
||||||
for( i = 0; i < (int)imgpt0.size(); i++ )
|
for( i = 0; i < (int)imgpt0.size(); i++ )
|
||||||
if( !imgpt0[i].empty() )
|
if( !imgpt0[i].empty() )
|
||||||
|
{
|
||||||
imgpt.push_back(imgpt0[i]);
|
imgpt.push_back(imgpt0[i]);
|
||||||
|
N += (int)imgpt0[i].size();
|
||||||
|
}
|
||||||
|
|
||||||
if( imgpt.size() < 3 )
|
if( imgpt.size() < 3 )
|
||||||
{
|
{
|
||||||
@ -60,17 +64,16 @@ static bool run3Calibration( vector<vector<Point2f> > imagePoints1,
|
|||||||
|
|
||||||
Mat distCoeffs = Mat::zeros(5, 1, CV_64F);
|
Mat distCoeffs = Mat::zeros(5, 1, CV_64F);
|
||||||
|
|
||||||
if( c == 3 )
|
double err = calibrateCamera(objpt, imgpt, imageSize, cameraMatrix,
|
||||||
|
distCoeffs, rvecs, tvecs,
|
||||||
|
flags|CV_CALIB_FIX_K3/*|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5|CV_CALIB_FIX_K6*/);
|
||||||
|
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
|
||||||
|
if(!ok)
|
||||||
{
|
{
|
||||||
calibrateCamera(objpt, imgpt, imageSize, cameraMatrix,
|
printf("Error: camera %d was not calibrated\n", c);
|
||||||
distCoeffs, rvecs, tvecs, flags|CV_CALIB_FIX_K3);
|
return false;
|
||||||
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
|
|
||||||
if(!ok)
|
|
||||||
{
|
|
||||||
printf("Error: camera %d was not calibrated\n", c);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
printf("Camera %d calibration reprojection error = %g\n", c, sqrt(err/N));
|
||||||
|
|
||||||
if( c == 1 )
|
if( c == 1 )
|
||||||
cameraMatrix1 = cameraMatrix, distCoeffs1 = distCoeffs;
|
cameraMatrix1 = cameraMatrix, distCoeffs1 = distCoeffs;
|
||||||
@ -89,12 +92,14 @@ static bool run3Calibration( vector<vector<Point2f> > imagePoints1,
|
|||||||
|
|
||||||
imgpt.clear();
|
imgpt.clear();
|
||||||
imgpt_right.clear();
|
imgpt_right.clear();
|
||||||
|
int N = 0;
|
||||||
|
|
||||||
for( i = 0; i < (int)std::min(imagePoints1.size(), imgpt0.size()); i++ )
|
for( i = 0; i < (int)std::min(imagePoints1.size(), imgpt0.size()); i++ )
|
||||||
if( !imagePoints1.empty() && !imgpt0[i].empty() )
|
if( !imagePoints1.empty() && !imgpt0[i].empty() )
|
||||||
{
|
{
|
||||||
imgpt.push_back(imagePoints1[i]);
|
imgpt.push_back(imagePoints1[i]);
|
||||||
imgpt_right.push_back(imgpt0[i]);
|
imgpt_right.push_back(imgpt0[i]);
|
||||||
|
N += (int)imgpt0[i].size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( imgpt.size() < 3 )
|
if( imgpt.size() < 3 )
|
||||||
@ -107,10 +112,12 @@ static bool run3Calibration( vector<vector<Point2f> > imagePoints1,
|
|||||||
Mat cameraMatrix = c == 2 ? cameraMatrix2 : cameraMatrix3;
|
Mat cameraMatrix = c == 2 ? cameraMatrix2 : cameraMatrix3;
|
||||||
Mat distCoeffs = c == 2 ? distCoeffs2 : distCoeffs3;
|
Mat distCoeffs = c == 2 ? distCoeffs2 : distCoeffs3;
|
||||||
Mat R, T, E, F;
|
Mat R, T, E, F;
|
||||||
stereoCalibrate(objpt, imgpt, imgpt_right, cameraMatrix1, distCoeffs1, cameraMatrix, distCoeffs,
|
double err = stereoCalibrate(objpt, imgpt, imgpt_right, cameraMatrix1, distCoeffs1,
|
||||||
imageSize, R, T, E, F,
|
cameraMatrix, distCoeffs,
|
||||||
TermCriteria(TermCriteria::COUNT, 30, 0),
|
imageSize, R, T, E, F,
|
||||||
(c == 3 ? CV_CALIB_FIX_INTRINSIC : 0) | CV_CALIB_FIX_K3);
|
TermCriteria(TermCriteria::COUNT, 30, 0),
|
||||||
|
CV_CALIB_FIX_INTRINSIC);
|
||||||
|
printf("Pair (1,%d) calibration reprojection error = %g\n", c, sqrt(err/(N*2)));
|
||||||
if( c == 2 )
|
if( c == 2 )
|
||||||
{
|
{
|
||||||
cameraMatrix2 = cameraMatrix;
|
cameraMatrix2 = cameraMatrix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user