From 8a4b99a5f4442c2cc6440c23d8d763f1e2d372e0 Mon Sep 17 00:00:00 2001 From: Barun Date: Thu, 14 Dec 2017 14:15:07 +0530 Subject: [PATCH 1/4] Added visualize.cpp to visualize chessboard corners and updated CMakeLists.txt accordingly --- CMakeLists.txt | 5 +- visualize.cpp | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 visualize.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edb1d2..5288c29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,5 +15,8 @@ target_link_libraries(read ${OpenCV_LIBS} "-lpopt") add_executable(calibrate_stereo calib_stereo.cpp) target_link_libraries(calibrate_stereo ${OpenCV_LIBS} "-lpopt") +add_executable(visualize_chessboard visualize.cpp) +target_link_libraries(visualize_chessboard ${OpenCV_LIBS} "-lpopt") + add_executable(undistort_rectify undistort_rectify.cpp) -target_link_libraries(undistort_rectify ${OpenCV_LIBS} "-lpopt") \ No newline at end of file +target_link_libraries(undistort_rectify ${OpenCV_LIBS} "-lpopt") diff --git a/visualize.cpp b/visualize.cpp new file mode 100644 index 0000000..0a4be0f --- /dev/null +++ b/visualize.cpp @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include +#include +#include +#include "popt_pp.h" + +using namespace std; +using namespace cv; + +vector< vector< Point3f > > object_points; +vector< vector< Point2f > > imagePoints1, imagePoints2; +vector< Point2f > corners1, corners2; +vector< vector< Point2f > > left_img_points, right_img_points; + +Mat img1, img2, gray1, gray2; + +void visualize(Mat iml, Mat imr, int board_width, int board_height, bool found_l, bool found_r) /*this function visualizes the chessboard + corners in the images passed to it*/ +{ + Size board_size = Size(board_width, board_height); + cv::drawChessboardCorners(imr, board_size, corners2, found_r); + cv::drawChessboardCorners(iml, board_size, corners1, found_l); + namedWindow("Left Chessboard Corner", WINDOW_AUTOSIZE); + namedWindow("Right Chessboard Corner", WINDOW_AUTOSIZE); + imshow("Left Chessboard Corner", iml); + imshow("Right Chessboard Corner", imr); +} + +void load_image_points(int board_width, int board_height, int num_imgs, float square_size, + char* leftimg_dir, char* rightimg_dir, char* leftimg_filename, char* rightimg_filename, char* visual) { + + Size board_size = Size(board_width, board_height); + int board_n = board_width * board_height; + + for (int i = 1; i <= num_imgs; i++) { + char left_img[100], right_img[100]; + sprintf(left_img, "%s%s%d.jpg", leftimg_dir, leftimg_filename, i); + sprintf(right_img, "%s%s%d.jpg", rightimg_dir, rightimg_filename, i); + img1 = imread(left_img, CV_LOAD_IMAGE_COLOR); + img2 = imread(right_img, CV_LOAD_IMAGE_COLOR); + cvtColor(img1, gray1, CV_BGR2GRAY); + cvtColor(img2, gray2, CV_BGR2GRAY); + + bool found1 = false, found2 = false; + + found1 = cv::findChessboardCorners(img1, board_size, corners1, + CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); + found2 = cv::findChessboardCorners(img2, board_size, corners2, + CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); + + if (found1) + { + cv::cornerSubPix(gray1, corners1, cv::Size(5, 5), cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(gray1, board_size, corners1, found1); + } + if (found2) + { + cv::cornerSubPix(gray2, corners2, cv::Size(5, 5), cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(gray2, board_size, corners2, found2); + } + + vector< Point3f > obj; + for (int i = 0; i < board_height; i++) + for (int j = 0; j < board_width; j++) + obj.push_back(Point3f((float)j * square_size, (float)i * square_size, 0)); + + if (found1 && found2) { + cout << i << ". Found corners!" << endl; + imagePoints1.push_back(corners1); + imagePoints2.push_back(corners2); + object_points.push_back(obj); + } + if (strcmp(visual, "y") == 0 && found1 && found2 ) //calling the visualize function if both left and right images are present + visualize(gray1, gray2, board_width, board_height, found1, found2); + } + for (int i = 0; i < imagePoints1.size(); i++) { + vector< Point2f > v1, v2; + for (int j = 0; j < imagePoints1[i].size(); j++) { + v1.push_back(Point2f((double)imagePoints1[i][j].x, (double)imagePoints1[i][j].y)); + v2.push_back(Point2f((double)imagePoints2[i][j].x, (double)imagePoints2[i][j].y)); + } + left_img_points.push_back(v1); + right_img_points.push_back(v2); + } + } + + +int main(int argc, char const *argv[]) +{ + char* leftcalib_file; + char* rightcalib_file; + char* leftimg_dir; + char* rightimg_dir; + char* leftimg_filename; + char* rightimg_filename; + char* out_file; + char* v_check; + int num_imgs; + + static struct poptOption options[] = { + { "num_imgs",'n',POPT_ARG_INT,&num_imgs,0,"Number of checkerboard images","NUM" }, + { "leftcalib_file",'u',POPT_ARG_STRING,&leftcalib_file,0,"Left camera calibration","STR" }, + { "rightcalib_file",'v',POPT_ARG_STRING,&rightcalib_file,0,"Right camera calibration","STR" }, + { "leftimg_dir",'L',POPT_ARG_STRING,&leftimg_dir,0,"Directory containing left images","STR" }, + { "rightimg_dir",'R',POPT_ARG_STRING,&rightimg_dir,0,"Directory containing right images","STR" }, + { "leftimg_filename",'l',POPT_ARG_STRING,&leftimg_filename,0,"Left image prefix","STR" }, + { "rightimg_filename",'r',POPT_ARG_STRING,&rightimg_filename,0,"Right image prefix","STR" }, + { "out_file",'o',POPT_ARG_STRING,&out_file,0,"Output calibration filename (YML)","STR" }, + { "v_check", 'v' , POPT_ARG_STRING, &v_check, 0, "Visualize chessboard corners? (y/n)", "STR"}, + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0, NULL, NULL } + }; + + POpt popt(NULL, argc, argv, options, 0); + int c; + while((c = popt.getNextOpt()) >= 0) {} + + FileStorage fsl(leftcalib_file, FileStorage::READ); + FileStorage fsr(rightcalib_file, FileStorage::READ); + + load_image_points(fsl["board_width"], fsl["board_height"], num_imgs, fsl["square_size"], + leftimg_dir, rightimg_dir, leftimg_filename, rightimg_filename, v_check); + + printf("Starting Calibration\n"); + Mat K1, K2, R, F, E; + Vec3d T; + Mat D1, D2; + fsl["K"] >> K1; + fsr["K"] >> K2; + fsl["D"] >> D1; + fsr["D"] >> D2; + int flag = 0; + flag |= CV_CALIB_FIX_INTRINSIC; + + cout << "Read intrinsics" << endl; + + stereoCalibrate(object_points, left_img_points, right_img_points, K1, D1, K2, D2, img1.size(), R, T, E, F); + + cv::FileStorage fs1(out_file, cv::FileStorage::WRITE); + fs1 << "K1" << K1; + fs1 << "K2" << K2; + fs1 << "D1" << D1; + fs1 << "D2" << D2; + fs1 << "R" << R; + fs1 << "T" << T; + fs1 << "E" << E; + fs1 << "F" << F; + + printf("Done Calibration\n"); + + printf("Starting Rectification\n"); + + cv::Mat R1, R2, P1, P2, Q; + stereoRectify(K1, D1, K2, D2, img1.size(), R, T, R1, R2, P1, P2, Q); + + fs1 << "R1" << R1; + fs1 << "R2" << R2; + fs1 << "P1" << P1; + fs1 << "P2" << P2; + fs1 << "Q" << Q; + + printf("Done Rectification\n"); + + return 0; +} From c4744b7e7b631b2bbf9278585ead34d3ce612cce Mon Sep 17 00:00:00 2001 From: Barun Date: Fri, 15 Dec 2017 09:37:23 +0530 Subject: [PATCH 2/4] Added changes to visualize chessboard corners in calib_stereo.cpp --- CMakeLists.txt | 3 - calib_stereo.cpp | 26 ++++++-- visualize.cpp | 170 ----------------------------------------------- 3 files changed, 22 insertions(+), 177 deletions(-) delete mode 100644 visualize.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5288c29..5dbc972 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,5 @@ target_link_libraries(read ${OpenCV_LIBS} "-lpopt") add_executable(calibrate_stereo calib_stereo.cpp) target_link_libraries(calibrate_stereo ${OpenCV_LIBS} "-lpopt") -add_executable(visualize_chessboard visualize.cpp) -target_link_libraries(visualize_chessboard ${OpenCV_LIBS} "-lpopt") - add_executable(undistort_rectify undistort_rectify.cpp) target_link_libraries(undistort_rectify ${OpenCV_LIBS} "-lpopt") diff --git a/calib_stereo.cpp b/calib_stereo.cpp index 5955f8a..0a4be0f 100644 --- a/calib_stereo.cpp +++ b/calib_stereo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "popt_pp.h" using namespace std; @@ -16,8 +17,20 @@ vector< vector< Point2f > > left_img_points, right_img_points; Mat img1, img2, gray1, gray2; +void visualize(Mat iml, Mat imr, int board_width, int board_height, bool found_l, bool found_r) /*this function visualizes the chessboard + corners in the images passed to it*/ +{ + Size board_size = Size(board_width, board_height); + cv::drawChessboardCorners(imr, board_size, corners2, found_r); + cv::drawChessboardCorners(iml, board_size, corners1, found_l); + namedWindow("Left Chessboard Corner", WINDOW_AUTOSIZE); + namedWindow("Right Chessboard Corner", WINDOW_AUTOSIZE); + imshow("Left Chessboard Corner", iml); + imshow("Right Chessboard Corner", imr); +} + void load_image_points(int board_width, int board_height, int num_imgs, float square_size, - char* leftimg_dir, char* rightimg_dir, char* leftimg_filename, char* rightimg_filename) { + char* leftimg_dir, char* rightimg_dir, char* leftimg_filename, char* rightimg_filename, char* visual) { Size board_size = Size(board_width, board_height); int board_n = board_width * board_height; @@ -62,6 +75,8 @@ void load_image_points(int board_width, int board_height, int num_imgs, float sq imagePoints2.push_back(corners2); object_points.push_back(obj); } + if (strcmp(visual, "y") == 0 && found1 && found2 ) //calling the visualize function if both left and right images are present + visualize(gray1, gray2, board_width, board_height, found1, found2); } for (int i = 0; i < imagePoints1.size(); i++) { vector< Point2f > v1, v2; @@ -72,7 +87,8 @@ void load_image_points(int board_width, int board_height, int num_imgs, float sq left_img_points.push_back(v1); right_img_points.push_back(v2); } -} + } + int main(int argc, char const *argv[]) { @@ -83,8 +99,9 @@ int main(int argc, char const *argv[]) char* leftimg_filename; char* rightimg_filename; char* out_file; + char* v_check; int num_imgs; - + static struct poptOption options[] = { { "num_imgs",'n',POPT_ARG_INT,&num_imgs,0,"Number of checkerboard images","NUM" }, { "leftcalib_file",'u',POPT_ARG_STRING,&leftcalib_file,0,"Left camera calibration","STR" }, @@ -94,6 +111,7 @@ int main(int argc, char const *argv[]) { "leftimg_filename",'l',POPT_ARG_STRING,&leftimg_filename,0,"Left image prefix","STR" }, { "rightimg_filename",'r',POPT_ARG_STRING,&rightimg_filename,0,"Right image prefix","STR" }, { "out_file",'o',POPT_ARG_STRING,&out_file,0,"Output calibration filename (YML)","STR" }, + { "v_check", 'v' , POPT_ARG_STRING, &v_check, 0, "Visualize chessboard corners? (y/n)", "STR"}, POPT_AUTOHELP { NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -106,7 +124,7 @@ int main(int argc, char const *argv[]) FileStorage fsr(rightcalib_file, FileStorage::READ); load_image_points(fsl["board_width"], fsl["board_height"], num_imgs, fsl["square_size"], - leftimg_dir, rightimg_dir, leftimg_filename, rightimg_filename); + leftimg_dir, rightimg_dir, leftimg_filename, rightimg_filename, v_check); printf("Starting Calibration\n"); Mat K1, K2, R, F, E; diff --git a/visualize.cpp b/visualize.cpp deleted file mode 100644 index 0a4be0f..0000000 --- a/visualize.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "popt_pp.h" - -using namespace std; -using namespace cv; - -vector< vector< Point3f > > object_points; -vector< vector< Point2f > > imagePoints1, imagePoints2; -vector< Point2f > corners1, corners2; -vector< vector< Point2f > > left_img_points, right_img_points; - -Mat img1, img2, gray1, gray2; - -void visualize(Mat iml, Mat imr, int board_width, int board_height, bool found_l, bool found_r) /*this function visualizes the chessboard - corners in the images passed to it*/ -{ - Size board_size = Size(board_width, board_height); - cv::drawChessboardCorners(imr, board_size, corners2, found_r); - cv::drawChessboardCorners(iml, board_size, corners1, found_l); - namedWindow("Left Chessboard Corner", WINDOW_AUTOSIZE); - namedWindow("Right Chessboard Corner", WINDOW_AUTOSIZE); - imshow("Left Chessboard Corner", iml); - imshow("Right Chessboard Corner", imr); -} - -void load_image_points(int board_width, int board_height, int num_imgs, float square_size, - char* leftimg_dir, char* rightimg_dir, char* leftimg_filename, char* rightimg_filename, char* visual) { - - Size board_size = Size(board_width, board_height); - int board_n = board_width * board_height; - - for (int i = 1; i <= num_imgs; i++) { - char left_img[100], right_img[100]; - sprintf(left_img, "%s%s%d.jpg", leftimg_dir, leftimg_filename, i); - sprintf(right_img, "%s%s%d.jpg", rightimg_dir, rightimg_filename, i); - img1 = imread(left_img, CV_LOAD_IMAGE_COLOR); - img2 = imread(right_img, CV_LOAD_IMAGE_COLOR); - cvtColor(img1, gray1, CV_BGR2GRAY); - cvtColor(img2, gray2, CV_BGR2GRAY); - - bool found1 = false, found2 = false; - - found1 = cv::findChessboardCorners(img1, board_size, corners1, - CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); - found2 = cv::findChessboardCorners(img2, board_size, corners2, - CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); - - if (found1) - { - cv::cornerSubPix(gray1, corners1, cv::Size(5, 5), cv::Size(-1, -1), - cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(gray1, board_size, corners1, found1); - } - if (found2) - { - cv::cornerSubPix(gray2, corners2, cv::Size(5, 5), cv::Size(-1, -1), - cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(gray2, board_size, corners2, found2); - } - - vector< Point3f > obj; - for (int i = 0; i < board_height; i++) - for (int j = 0; j < board_width; j++) - obj.push_back(Point3f((float)j * square_size, (float)i * square_size, 0)); - - if (found1 && found2) { - cout << i << ". Found corners!" << endl; - imagePoints1.push_back(corners1); - imagePoints2.push_back(corners2); - object_points.push_back(obj); - } - if (strcmp(visual, "y") == 0 && found1 && found2 ) //calling the visualize function if both left and right images are present - visualize(gray1, gray2, board_width, board_height, found1, found2); - } - for (int i = 0; i < imagePoints1.size(); i++) { - vector< Point2f > v1, v2; - for (int j = 0; j < imagePoints1[i].size(); j++) { - v1.push_back(Point2f((double)imagePoints1[i][j].x, (double)imagePoints1[i][j].y)); - v2.push_back(Point2f((double)imagePoints2[i][j].x, (double)imagePoints2[i][j].y)); - } - left_img_points.push_back(v1); - right_img_points.push_back(v2); - } - } - - -int main(int argc, char const *argv[]) -{ - char* leftcalib_file; - char* rightcalib_file; - char* leftimg_dir; - char* rightimg_dir; - char* leftimg_filename; - char* rightimg_filename; - char* out_file; - char* v_check; - int num_imgs; - - static struct poptOption options[] = { - { "num_imgs",'n',POPT_ARG_INT,&num_imgs,0,"Number of checkerboard images","NUM" }, - { "leftcalib_file",'u',POPT_ARG_STRING,&leftcalib_file,0,"Left camera calibration","STR" }, - { "rightcalib_file",'v',POPT_ARG_STRING,&rightcalib_file,0,"Right camera calibration","STR" }, - { "leftimg_dir",'L',POPT_ARG_STRING,&leftimg_dir,0,"Directory containing left images","STR" }, - { "rightimg_dir",'R',POPT_ARG_STRING,&rightimg_dir,0,"Directory containing right images","STR" }, - { "leftimg_filename",'l',POPT_ARG_STRING,&leftimg_filename,0,"Left image prefix","STR" }, - { "rightimg_filename",'r',POPT_ARG_STRING,&rightimg_filename,0,"Right image prefix","STR" }, - { "out_file",'o',POPT_ARG_STRING,&out_file,0,"Output calibration filename (YML)","STR" }, - { "v_check", 'v' , POPT_ARG_STRING, &v_check, 0, "Visualize chessboard corners? (y/n)", "STR"}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0, NULL, NULL } - }; - - POpt popt(NULL, argc, argv, options, 0); - int c; - while((c = popt.getNextOpt()) >= 0) {} - - FileStorage fsl(leftcalib_file, FileStorage::READ); - FileStorage fsr(rightcalib_file, FileStorage::READ); - - load_image_points(fsl["board_width"], fsl["board_height"], num_imgs, fsl["square_size"], - leftimg_dir, rightimg_dir, leftimg_filename, rightimg_filename, v_check); - - printf("Starting Calibration\n"); - Mat K1, K2, R, F, E; - Vec3d T; - Mat D1, D2; - fsl["K"] >> K1; - fsr["K"] >> K2; - fsl["D"] >> D1; - fsr["D"] >> D2; - int flag = 0; - flag |= CV_CALIB_FIX_INTRINSIC; - - cout << "Read intrinsics" << endl; - - stereoCalibrate(object_points, left_img_points, right_img_points, K1, D1, K2, D2, img1.size(), R, T, E, F); - - cv::FileStorage fs1(out_file, cv::FileStorage::WRITE); - fs1 << "K1" << K1; - fs1 << "K2" << K2; - fs1 << "D1" << D1; - fs1 << "D2" << D2; - fs1 << "R" << R; - fs1 << "T" << T; - fs1 << "E" << E; - fs1 << "F" << F; - - printf("Done Calibration\n"); - - printf("Starting Rectification\n"); - - cv::Mat R1, R2, P1, P2, Q; - stereoRectify(K1, D1, K2, D2, img1.size(), R, T, R1, R2, P1, P2, Q); - - fs1 << "R1" << R1; - fs1 << "R2" << R2; - fs1 << "P1" << P1; - fs1 << "P2" << P2; - fs1 << "Q" << Q; - - printf("Done Rectification\n"); - - return 0; -} From 7cdaa725f7946f6a22b8d1bcf5d224bbddcd9d07 Mon Sep 17 00:00:00 2001 From: Barun Date: Sat, 23 Dec 2017 14:22:41 +0530 Subject: [PATCH 3/4] Worked on imshow and POPT issues --- calib_stereo.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/calib_stereo.cpp b/calib_stereo.cpp index 0a4be0f..44da887 100644 --- a/calib_stereo.cpp +++ b/calib_stereo.cpp @@ -15,18 +15,29 @@ vector< vector< Point2f > > imagePoints1, imagePoints2; vector< Point2f > corners1, corners2; vector< vector< Point2f > > left_img_points, right_img_points; -Mat img1, img2, gray1, gray2; +Mat img1, img2, gray1, gray2, left_array[30], right_array[30]; +int i_v = 0; void visualize(Mat iml, Mat imr, int board_width, int board_height, bool found_l, bool found_r) /*this function visualizes the chessboard corners in the images passed to it*/ { Size board_size = Size(board_width, board_height); cv::drawChessboardCorners(imr, board_size, corners2, found_r); - cv::drawChessboardCorners(iml, board_size, corners1, found_l); + cv::drawChessboardCorners(iml, board_size, corners1, found_l);a + + Mat left_chessboard, right_chessboard; + + left_array[i_v] = iml; + right_array[i_v] = imr; + ++i_v; + + cv::hconcat(left_array, (i_v + 1), left_chessboard); + cv::hconcat(right_array, (i_v + 1), right_chessboard); + namedWindow("Left Chessboard Corner", WINDOW_AUTOSIZE); namedWindow("Right Chessboard Corner", WINDOW_AUTOSIZE); - imshow("Left Chessboard Corner", iml); - imshow("Right Chessboard Corner", imr); + imshow("Left Chessboard Corner", left_chessboard); + imshow("Right Chessboard Corner", right_chessboard); } void load_image_points(int board_width, int board_height, int num_imgs, float square_size, @@ -55,19 +66,17 @@ void load_image_points(int board_width, int board_height, int num_imgs, float sq { cv::cornerSubPix(gray1, corners1, cv::Size(5, 5), cv::Size(-1, -1), cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(gray1, board_size, corners1, found1); } if (found2) { cv::cornerSubPix(gray2, corners2, cv::Size(5, 5), cv::Size(-1, -1), cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(gray2, board_size, corners2, found2); } vector< Point3f > obj; - for (int i = 0; i < board_height; i++) - for (int j = 0; j < board_width; j++) - obj.push_back(Point3f((float)j * square_size, (float)i * square_size, 0)); + for (int k = 0; k < board_height; i++) + for (int l = 0; l < board_width; j++) + obj.push_back(Point3f((float)l * square_size, (float)l * square_size, 0)); if (found1 && found2) { cout << i << ". Found corners!" << endl; @@ -75,8 +84,11 @@ void load_image_points(int board_width, int board_height, int num_imgs, float sq imagePoints2.push_back(corners2); object_points.push_back(obj); } - if (strcmp(visual, "y") == 0 && found1 && found2 ) //calling the visualize function if both left and right images are present + if (strcmp(visual, "y") == 0 && found1 && found2 ) { //calling the visualize function if both left and right images are present visualize(gray1, gray2, board_width, board_height, found1, found2); + + + } } for (int i = 0; i < imagePoints1.size(); i++) { vector< Point2f > v1, v2; @@ -111,9 +123,9 @@ int main(int argc, char const *argv[]) { "leftimg_filename",'l',POPT_ARG_STRING,&leftimg_filename,0,"Left image prefix","STR" }, { "rightimg_filename",'r',POPT_ARG_STRING,&rightimg_filename,0,"Right image prefix","STR" }, { "out_file",'o',POPT_ARG_STRING,&out_file,0,"Output calibration filename (YML)","STR" }, - { "v_check", 'v' , POPT_ARG_STRING, &v_check, 0, "Visualize chessboard corners? (y/n)", "STR"}, + { "v_check", 'c' , POPT_ARG_NONE, &v_check, 0, "Visualize chessboard corners? (y/n)", "NONE"}, POPT_AUTOHELP - { NULL, 0, 0, NULL, 0, NULL, NULL } + { NULL, 0, 0, NULL, 0, NULL, NULL, NULL } }; POpt popt(NULL, argc, argv, options, 0); @@ -125,6 +137,9 @@ int main(int argc, char const *argv[]) load_image_points(fsl["board_width"], fsl["board_height"], num_imgs, fsl["square_size"], leftimg_dir, rightimg_dir, leftimg_filename, rightimg_filename, v_check); + + int ikey = waitKey(50); + waitKey(0); printf("Starting Calibration\n"); Mat K1, K2, R, F, E; From a89ccc2d7a8f1951850a779066cc8c37259df942 Mon Sep 17 00:00:00 2001 From: Barun Date: Sat, 23 Dec 2017 14:30:00 +0530 Subject: [PATCH 4/4] Worked on popt issues, added waitKey and implemented hconcat to display images --- calib_stereo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/calib_stereo.cpp b/calib_stereo.cpp index 44da887..e940205 100644 --- a/calib_stereo.cpp +++ b/calib_stereo.cpp @@ -23,7 +23,7 @@ void visualize(Mat iml, Mat imr, int board_width, int board_height, bool found_l { Size board_size = Size(board_width, board_height); cv::drawChessboardCorners(imr, board_size, corners2, found_r); - cv::drawChessboardCorners(iml, board_size, corners1, found_l);a + cv::drawChessboardCorners(iml, board_size, corners1, found_l); Mat left_chessboard, right_chessboard; @@ -74,8 +74,8 @@ void load_image_points(int board_width, int board_height, int num_imgs, float sq } vector< Point3f > obj; - for (int k = 0; k < board_height; i++) - for (int l = 0; l < board_width; j++) + for (int k = 0; k < board_height; k++) + for (int l = 0; l < board_width; l++) obj.push_back(Point3f((float)l * square_size, (float)l * square_size, 0)); if (found1 && found2) { @@ -125,7 +125,7 @@ int main(int argc, char const *argv[]) { "out_file",'o',POPT_ARG_STRING,&out_file,0,"Output calibration filename (YML)","STR" }, { "v_check", 'c' , POPT_ARG_NONE, &v_check, 0, "Visualize chessboard corners? (y/n)", "NONE"}, POPT_AUTOHELP - { NULL, 0, 0, NULL, 0, NULL, NULL, NULL } + { NULL, 0, 0, NULL, 0, NULL, NULL } }; POpt popt(NULL, argc, argv, options, 0);