Clean up calibrate.cc

This commit is contained in:
Razvan Mihalyi 2012-09-18 15:33:49 +02:00
parent a4c92b0896
commit 7482fe9360

View file

@ -25,8 +25,7 @@ int main(int argc, char** argv)
int specified_boards; int specified_boards;
if (argc > 2) if (argc > 2)
cerr << "Usage: ./calibrate [number of frames]\n"; cerr << "Usage: ./calibrate [number of frames]\n";
else else if (argc == 1)
if (argc == 1)
{ {
user_mode = INTERACTIVE_MODE; user_mode = INTERACTIVE_MODE;
cout << "Camera calibration using interactive behavior. Press SPACE to grab frame.\n"; cout << "Camera calibration using interactive behavior. Press SPACE to grab frame.\n";
@ -50,11 +49,12 @@ int main(int argc, char** argv)
vector< vector <Point3f> > object_points; vector< vector <Point3f> > object_points;
vector< vector <Point2f> > image_points; vector< vector <Point2f> > image_points;
Mat frame; Mat frame, gray_frame;
for(int count = 0; ; ++count) for(int count = 0; ; ++count)
{ {
cout << "Frame: " << count << "\n"; cout << "Frame: " << count << "\n";
capture >> frame; // get a new frame from camera capture >> frame; // get a new frame from camera
cvtColor(frame, gray_frame, CV_BGR2GRAY);
imshow("Camera Image", frame); imshow("Camera Image", frame);
int key_pressed = waitKey(0); int key_pressed = waitKey(0);
@ -65,23 +65,23 @@ int main(int argc, char** argv)
{ {
Size pattern_size(COUNT_SQUARES_X, COUNT_SQUARES_Y); //interior number of corners Size pattern_size(COUNT_SQUARES_X, COUNT_SQUARES_Y); //interior number of corners
vector<Point2f> corners; //this will be filled by the detected corners vector<Point2f> corners; //this will be filled by the detected corners
bool pattern_found = findChessboardCorners( frame, pattern_size, corners, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CALIB_CB_FAST_CHECK); bool pattern_found = findChessboardCorners( gray_frame, pattern_size, corners, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CALIB_CB_FAST_CHECK);
if (pattern_found) // to tweak params: http://bit.ly/QyoU3k if (pattern_found) // to tweak params: http://bit.ly/QyoU3k
cornerSubPix(frame, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); {
cornerSubPix(gray_frame, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(frame, pattern_size, Mat(corners), pattern_found); drawChessboardCorners(frame, pattern_size, Mat(corners), pattern_found);
vector< Point3f > obj; vector< Point3f > obj;
for(int j = 0; j < COUNT_SQUARES_X * COUNT_SQUARES_Y; ++j) for(int j = 0; j < COUNT_SQUARES_X * COUNT_SQUARES_Y; ++j)
obj.push_back(Point3f(j/COUNT_SQUARES_X, j%COUNT_SQUARES_X, 0.0f)); obj.push_back(Point3f(j/COUNT_SQUARES_X, j%COUNT_SQUARES_X, 0.0f));
if (pattern_found) {
image_points.push_back(corners); image_points.push_back(corners);
object_points.push_back(obj); object_points.push_back(obj);
cout << "Frame " << count << " grabbed.\n"; cout << "Frame " << count << " grabbed.\n";
} }
} }
} }