diff --git a/src/charuco.cpp b/src/charuco.cpp index 48b8ef4..8628e0e 100644 --- a/src/charuco.cpp +++ b/src/charuco.cpp @@ -22,10 +22,6 @@ #include #include "uvosunwrap/log.h" -static constexpr unsigned int X_BOARD_SIZE = 20; -static constexpr unsigned int Y_BOARD_SIZE = 12; - - void createCharucoBoard(unsigned int size, const std::string& fileName) { cv::Ptr board = @@ -35,7 +31,7 @@ void createCharucoBoard(unsigned int size, const std::string& fileName) double cellSize = size/(double)Y_BOARD_SIZE; board->draw(cv::Size((size*X_BOARD_SIZE)/Y_BOARD_SIZE, size), charucoImage, 0, 1); cv::Mat charucoImageWithBorder = - cv::Mat::zeros(cv::Size(cellSize*(X_BOARD_SIZE+2), cellSize*(Y_BOARD_SIZE+2)), CV_8UC1); + cv::Mat::zeros(cv::Size(cellSize*(X_BOARD_SIZE+1), cellSize*(Y_BOARD_SIZE+2)), CV_8UC1); cv::Rect roi(cellSize, cellSize, charucoImage.cols, charucoImage.rows); charucoImage.copyTo(charucoImageWithBorder(roi)); cv::imwrite(fileName, charucoImageWithBorder); diff --git a/src/main.cpp b/src/main.cpp index 0ac8aef..d1395e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,7 +143,7 @@ int perfromOperation(int operation, char** fileNames, const Config& config) if(operation == CREATE_CHARUCO) { std::string fileName = config.output.empty() ? "out.png" : config.output; - createCharucoBoard(config.size*42, fileName); + createCharucoBoard(config.size*X_BOARD_SIZE, fileName); Log(Log::INFO)<<"Exported charuco map of size "< cols; - cols.reserve(mat.cols); - - for(int x = 0; x < mat.cols; x++) - { - bool empty = true; - for(int y = 0; y < mat.rows; y++) - { - if(mat.at(x,y) > 0) - { - empty = false; - break; - } - } - - if(!empty) - cols.push_back(x); - } - - if(mat.cols < static_cast(cols.size())) - { - cv::Mat tmp(cv::Size(cols.size(), mat.rows), CV_32FC1); - - for(auto& col : cols) - { - cv::Rect roi(cv::Point2i(col, 0), cv::Size(1, mat.rows)); - mat.copyTo(tmp(roi)); - } - mat.release(); - mat = tmp; - - return true; - } - - return false; -} - -void removeSparseCols(cv::Mat& mat, bool front) +void removeSparseCols(cv::Mat& mat, float reject, bool front) { assert(mat.type() == CV_32FC1); @@ -339,14 +299,14 @@ void removeSparseCols(cv::Mat& mat, bool front) else if(mat.at(y,mat.cols-1) >= 0) ++count; } cv::Rect roi; - bool rej = (count < mat.rows/2); + bool rej = (count < mat.rows*reject); roi.x=front ? rej : 0; roi.y=0; roi.width = mat.cols - rej; roi.height = mat.rows; mat = mat(roi); if(rej) - removeSparseCols(mat, front); + removeSparseCols(mat, reject, front); } static float linInterpolate(float A, float B, float x) diff --git a/src/matutils.h b/src/matutils.h index 3e96024..3d711e9 100644 --- a/src/matutils.h +++ b/src/matutils.h @@ -43,9 +43,7 @@ void fillMissing(cv::Mat& mat); bool findDeadSpace(const cv::Mat& mat, cv::Rect& roi); -bool deleteEmptyCols(cv::Mat& mat); - -void removeSparseCols(cv::Mat& mat, bool front); +void removeSparseCols(cv::Mat& mat, float reject, bool front); bool bilinearResize(const cv::Mat& inImage, cv::Mat& outImage, cv::Size size); diff --git a/src/unwrap.cpp b/src/unwrap.cpp index 707ba5d..7414c96 100644 --- a/src/unwrap.cpp +++ b/src/unwrap.cpp @@ -97,11 +97,11 @@ bool createRemapMap(const cv::Mat& image, RemapMap& out, const std::vector #include "detectedpoint.h" +static constexpr unsigned int X_BOARD_SIZE = 20; +static constexpr unsigned int Y_BOARD_SIZE = 12; + void createCharucoBoard(unsigned int size, const std::string& fileName); std::vector detectCharucoPoints(cv::Mat image, bool verbose = true);