added flag to treat input file as a videofile (patch by Ethan Rublee; ticket #392)
This commit is contained in:
parent
bad4ca2a51
commit
2b660bf554
@ -60,6 +60,8 @@ void help()
|
|||||||
" [-a <aspectRatio>] # fix aspect ratio (fx/fy)\n"
|
" [-a <aspectRatio>] # fix aspect ratio (fx/fy)\n"
|
||||||
" [-p] # fix the principal point at the center\n"
|
" [-p] # fix the principal point at the center\n"
|
||||||
" [-v] # flip the captured images around the horizontal axis\n"
|
" [-v] # flip the captured images around the horizontal axis\n"
|
||||||
|
" [-V] # use a video file, and not an image list, uses\n"
|
||||||
|
" # [input_data] string for the video file name\n"
|
||||||
" [-su] # show undistorted images after calibration\n"
|
" [-su] # show undistorted images after calibration\n"
|
||||||
" [input_data] # input data, one of the following:\n"
|
" [input_data] # input data, one of the following:\n"
|
||||||
" # - text file with a list of the images of the board\n"
|
" # - text file with a list of the images of the board\n"
|
||||||
@ -126,10 +128,11 @@ static bool runCalibration( vector<vector<Point2f> > imagePoints,
|
|||||||
vector<vector<Point3f> > objectPoints(1);
|
vector<vector<Point3f> > objectPoints(1);
|
||||||
calcChessboardCorners(boardSize, squareSize, objectPoints[0]);
|
calcChessboardCorners(boardSize, squareSize, objectPoints[0]);
|
||||||
|
|
||||||
objectPoints.resize(imagePoints.size(),objectPoints[0]);
|
objectPoints.resize(imagePoints.size(),objectPoints[0]);
|
||||||
|
|
||||||
calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
|
calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
|
||||||
distCoeffs, rvecs, tvecs, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);///*|CV_CALIB_FIX_K3*/|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);
|
distCoeffs, rvecs, tvecs, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);
|
||||||
|
///*|CV_CALIB_FIX_K3*/|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);
|
||||||
|
|
||||||
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
|
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
|
||||||
|
|
||||||
@ -277,6 +280,7 @@ int main( int argc, char** argv )
|
|||||||
VideoCapture capture;
|
VideoCapture capture;
|
||||||
bool flipVertical = false;
|
bool flipVertical = false;
|
||||||
bool showUndistorted = false;
|
bool showUndistorted = false;
|
||||||
|
bool videofile = false;
|
||||||
int delay = 1000;
|
int delay = 1000;
|
||||||
clock_t prevTimestamp = 0;
|
clock_t prevTimestamp = 0;
|
||||||
int mode = DETECTION;
|
int mode = DETECTION;
|
||||||
@ -284,11 +288,10 @@ int main( int argc, char** argv )
|
|||||||
vector<vector<Point2f> > imagePoints;
|
vector<vector<Point2f> > imagePoints;
|
||||||
vector<string> imageList;
|
vector<string> imageList;
|
||||||
|
|
||||||
|
|
||||||
if( argc < 2 )
|
if( argc < 2 )
|
||||||
{
|
{
|
||||||
help();
|
help();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 1; i < argc; i++ )
|
for( i = 1; i < argc; i++ )
|
||||||
@ -327,11 +330,11 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
else if( strcmp( s, "-op" ) == 0 )
|
else if( strcmp( s, "-op" ) == 0 )
|
||||||
{
|
{
|
||||||
writePoints = 1;
|
writePoints = true;
|
||||||
}
|
}
|
||||||
else if( strcmp( s, "-oe" ) == 0 )
|
else if( strcmp( s, "-oe" ) == 0 )
|
||||||
{
|
{
|
||||||
writeExtrinsics = 1;
|
writeExtrinsics = true;
|
||||||
}
|
}
|
||||||
else if( strcmp( s, "-zt" ) == 0 )
|
else if( strcmp( s, "-zt" ) == 0 )
|
||||||
{
|
{
|
||||||
@ -343,7 +346,11 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
else if( strcmp( s, "-v" ) == 0 )
|
else if( strcmp( s, "-v" ) == 0 )
|
||||||
{
|
{
|
||||||
flipVertical = 1;
|
flipVertical = true;
|
||||||
|
}
|
||||||
|
else if( strcmp( s, "-V" ) == 0 )
|
||||||
|
{
|
||||||
|
videofile = true;
|
||||||
}
|
}
|
||||||
else if( strcmp( s, "-o" ) == 0 )
|
else if( strcmp( s, "-o" ) == 0 )
|
||||||
{
|
{
|
||||||
@ -355,18 +362,18 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
else if( s[0] != '-' )
|
else if( s[0] != '-' )
|
||||||
{
|
{
|
||||||
if( isdigit(s[0]) )
|
if( isdigit(s[0]) )
|
||||||
sscanf(s, "%d", &cameraId);
|
sscanf(s, "%d", &cameraId);
|
||||||
else
|
else
|
||||||
inputFilename = s;
|
inputFilename = s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return fprintf( stderr, "Unknown option %s", s ), -1;
|
return fprintf( stderr, "Unknown option %s", s ), -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( inputFilename )
|
if( inputFilename )
|
||||||
{
|
{
|
||||||
if( readStringList(inputFilename, imageList) )
|
if( !videofile && readStringList(inputFilename, imageList) )
|
||||||
mode = CAPTURING;
|
mode = CAPTURING;
|
||||||
else
|
else
|
||||||
capture.open(inputFilename);
|
capture.open(inputFilename);
|
||||||
@ -415,27 +422,25 @@ int main( int argc, char** argv )
|
|||||||
flip( view, view, 0 );
|
flip( view, view, 0 );
|
||||||
|
|
||||||
vector<Point2f> pointbuf;
|
vector<Point2f> pointbuf;
|
||||||
|
|
||||||
|
|
||||||
cvtColor(view, viewGray, CV_BGR2GRAY);
|
cvtColor(view, viewGray, CV_BGR2GRAY);
|
||||||
|
|
||||||
|
|
||||||
bool found = findChessboardCorners( view, boardSize, pointbuf, CV_CALIB_CB_ADAPTIVE_THRESH & CV_CALIB_CB_FAST_CHECK & CV_CALIB_CB_NORMALIZE_IMAGE);
|
|
||||||
|
|
||||||
// improve the found corners' coordinate accuracy
|
bool found = findChessboardCorners( view, boardSize, pointbuf,
|
||||||
if(found) cornerSubPix( viewGray, pointbuf, Size(11,11),
|
CV_CALIB_CB_ADAPTIVE_THRESH & CV_CALIB_CB_FAST_CHECK & CV_CALIB_CB_NORMALIZE_IMAGE);
|
||||||
Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
|
|
||||||
|
|
||||||
if( mode == CAPTURING && found &&
|
// improve the found corners' coordinate accuracy
|
||||||
(!capture.isOpened() || clock() - prevTimestamp > delay*1e-3*CLOCKS_PER_SEC) )
|
if(found) cornerSubPix( viewGray, pointbuf, Size(11,11),
|
||||||
{
|
Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
|
||||||
imagePoints.push_back(pointbuf);
|
|
||||||
prevTimestamp = clock();
|
if( mode == CAPTURING && found &&
|
||||||
blink = capture.isOpened();
|
(!capture.isOpened() || clock() - prevTimestamp > delay*1e-3*CLOCKS_PER_SEC) )
|
||||||
}
|
{
|
||||||
if(found) drawChessboardCorners( view, boardSize, Mat(pointbuf), found );
|
imagePoints.push_back(pointbuf);
|
||||||
|
prevTimestamp = clock();
|
||||||
|
blink = capture.isOpened();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found)
|
||||||
|
drawChessboardCorners( view, boardSize, Mat(pointbuf), found );
|
||||||
|
|
||||||
string msg = mode == CAPTURING ? "100/100" :
|
string msg = mode == CAPTURING ? "100/100" :
|
||||||
mode == CALIBRATED ? "Calibrated" : "Press 'g' to start";
|
mode == CALIBRATED ? "Calibrated" : "Press 'g' to start";
|
||||||
@ -445,11 +450,11 @@ int main( int argc, char** argv )
|
|||||||
|
|
||||||
if( mode == CAPTURING )
|
if( mode == CAPTURING )
|
||||||
{
|
{
|
||||||
if(undistortImage)
|
if(undistortImage)
|
||||||
msg = format( "%d/%d Undist", (int)imagePoints.size(), nframes );
|
msg = format( "%d/%d Undist", (int)imagePoints.size(), nframes );
|
||||||
else
|
else
|
||||||
msg = format( "%d/%d", (int)imagePoints.size(), nframes );
|
msg = format( "%d/%d", (int)imagePoints.size(), nframes );
|
||||||
}
|
}
|
||||||
|
|
||||||
putText( view, msg, textOrigin, 1, 1,
|
putText( view, msg, textOrigin, 1, 1,
|
||||||
mode != CALIBRATED ? Scalar(0,0,255) : Scalar(0,255,0));
|
mode != CALIBRATED ? Scalar(0,0,255) : Scalar(0,255,0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user