Code Monkey home page Code Monkey logo

Comments (1)

blazczak avatar blazczak commented on June 26, 2024

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) {

from stereo-calibration.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.