Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize checkerboard points #3

Open
sourishg opened this issue Nov 13, 2017 · 1 comment
Open

Visualize checkerboard points #3

sourishg opened this issue Nov 13, 2017 · 1 comment

Comments

@sourishg
Copy link
Owner

For every stereo pair visualize the checkboard points detected using imshow. Ideally, this visualization should be triggered by a command-line flag argument.

@blazczak
Copy link

This is easily done with cv::findChessboardCorners() and cv::drawChessboardCorners() from calib3d. The detectAndParseChessboard() routine in opencv_interactive-calibration does this already - simply as a wrapper over those two functions - and can be used verbatim. In addition, the output of the wrapper can be used to determine if you have a parse-able image of the chessboard in both channels before making them candidates for saving, increasing the quality of input data for the subsequent calibration stages.

direct patch as a starting point:

index 5279fee..fefac40 100644
--- read_images.cpp
+++ read_images.cpp
@@ -1,3 +1,4 @@
+#include <opencv2/calib3d.hpp>
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
@@ -9,6 +10,25 @@ using namespace std;
 using namespace cv;
 
 int x = 0;
+Size mBoardSize = Size(7, 10);
+std::vector<cv::Point2f> mCurrentImagePoints;
+std::vector<cv::Point2f> mTemplateLocations;
+
+bool detectAndParseChessboard(const cv::Mat &frame)
+{
+    int chessBoardFlags = cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE | cv::CALIB_CB_FAST_CHECK;
+    bool isTemplateFound = cv::findChessboardCorners(frame, mBoardSize, mCurrentImagePoints, chessBoardFlags);
+
+    if (isTemplateFound) {
+        cv::Mat viewGray;
+        cv::cvtColor(frame, viewGray, cv::COLOR_BGR2GRAY);
+        cv::cornerSubPix(viewGray, mCurrentImagePoints, cv::Size(11,11),
+            cv::Size(-1,-1), cv::TermCriteria( cv::TermCriteria::EPS+cv::TermCriteria::COUNT, 30, 0.1 ));
+        cv::drawChessboardCorners(frame, mBoardSize, cv::Mat(mCurrentImagePoints), isTemplateFound);
+        mTemplateLocations.insert(mTemplateLocations.begin(), mCurrentImagePoints[0]);
+    }
+    return isTemplateFound;
+}
 
 int main(int argc, char const *argv[])
 {
@@ -35,8 +55,12 @@ int main(int argc, char const *argv[])
   while (1) {
     cap1 >> img1;
     cap2 >> img2;
-    resize(img1, img_res1, Size(im_width, im_height));
-    resize(img2, img_res2, Size(im_width, im_height));
+    img_res1 = img1.clone();
+    img_res2 = img2.clone();
+    detectAndParseChessboard(img_res1);
+    detectAndParseChessboard(img_res2);
+    resize(img_res1, img_res1, Size(im_width, im_height));
+    resize(img_res2, img_res2, Size(im_width, im_height));
     imshow("IMG1", img_res1);
     imshow("IMG2", img_res2);
     if (waitKey(30) > 0) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants