I am using OpenCV’s findchessboardcornersSB function to find the corners in the image. I am using below code/ header file:
#pragma once #include"opencv2/opencv.hpp" #include<Eigen/core> #include<vector> namespace MAL_Vision_Dushyant { class ChessBoardDetector { public: int CB_Width, CB_Height; cv::Size patternSize; ChessBoardDetector(int Width, int Height) { CB_Width = Width; CB_Height = Height; patternSize = cv::Size(Width, Height); } //ChessBoardDetector(){} void get_CB_Corners(std::string filename, const bool ROI_needed = false, const bool show_img = false, const int resize_factor = 2) { //auto beg1 = std::chrono::high_resolution_clock::now(); cv::Mat src_image = cv::imread(filename); cv::Mat crop_image, gray_img; cv::Rect r; std::vector<cv::Point2f> corners(CB_Width*CB_Height); //crop image so that it fits on the screen. if (ROI_needed) { //select the ROI in the image cv::resize(src_image, src_image, cv::Size(src_image.cols / resize_factor, src_image.rows / resize_factor)); r = cv::selectROI(src_image); //resize the cropped image so that it represents pixel on original image crop_image = src_image(cv::Rect(resize_factor * r.x, resize_factor * r.y, resize_factor * r.width, resize_factor * r.height)); } else { //Use original image size crop_image = src_image.clone(); } //cv::cvtColor(crop_image, crop_image, cv::COLOR_BGR2GRAY); //bool found = cv::findChessboardCorners(src_image, patternSize, corners, cv::CALIB_CB_FAST_CHECK | cv::CALIB_CB_NORMALIZE_IMAGE | cv::CALIB_CB_EXHAUSTIVE); bool found = cv::findChessboardCornersSB(crop_image, patternSize, corners); } }; } When I run the get_CB_Corners function without any ROI selection, I am getting the function runtime of 4 + seconds. In my debug console project, I see a lot of OpenCL related lines. I don't know why that is necessary. Also when I run similar code in python, it takes less time than this C++ code block which is very disturbing for this basic function. Below is the main function:
#include"Chess_Board_Detection.h" using namespace std; using namespace cv; int CB_WIDTH = 9; int CB_HEIGHT = 6; int main() { int ang; cout << "Enter angle" << endl; cin >> ang; string input_dir = "C:\\Users\\DushyantPatil\\Documents\\Pose Estimation\\Input Data\\stereo\\images\\"; string test_number = "test1_B\\"; //string prefix = "1_"; string prefix = "1_"; string suffix = "d_6.bmp"; string filename = input_dir + test_number + prefix + to_string(ang) + suffix; MAL_Vision_Dushyant::ChessBoardDetector CB_Detect1(CB_WIDTH, CB_HEIGHT); CB_Detect1.get_CB_Corners(filename, false); }