diff --git a/src/charuco.cpp b/src/charuco.cpp index 14f8b2b..48b8ef4 100644 --- a/src/charuco.cpp +++ b/src/charuco.cpp @@ -20,9 +20,10 @@ #include "uvosunwrap/charuco.h" #include #include +#include "uvosunwrap/log.h" -static constexpr unsigned int X_BOARD_SIZE = 18; -static constexpr unsigned int Y_BOARD_SIZE = 10; +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) @@ -30,9 +31,65 @@ void createCharucoBoard(unsigned int size, const std::string& fileName) cv::Ptr board = cv::aruco::CharucoBoard::create(X_BOARD_SIZE, Y_BOARD_SIZE, 0.03f, 0.02f, cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_250 )); - cv::Mat charucoImage; - board->draw(cv::Size((size*18)/10, size), charucoImage, 0, 1); - cv::imwrite(fileName, charucoImage); + cv::Mat charucoImage; + 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::Rect roi(cellSize, cellSize, charucoImage.cols, charucoImage.rows); + charucoImage.copyTo(charucoImageWithBorder(roi)); + cv::imwrite(fileName, charucoImageWithBorder); +} + +static void seamAjust(std::vector& detections) +{ + int xMin = std::numeric_limits::max(); + int xMax = std::numeric_limits::min(); + + for(auto& point : detections) + { + if(point.coordinate.x > xMax) + xMax = point.coordinate.x; + else if(point.coordinate.x < xMin) + xMin = point.coordinate.x; + } + + if(xMax - xMin < static_cast(X_BOARD_SIZE/2)) + return; + + Log(Log::DEBUG)<<"Image contains seam"; + + bool extantCol[X_BOARD_SIZE] = {0}; + for(auto& point : detections) + { + if(!extantCol[point.coordinate.x]) + extantCol[point.coordinate.x] = true; + } + + int leftCoordinate = 0; + int maxDeadrange = 0; + int deadRange = 0; + for(unsigned int i = 0; i < X_BOARD_SIZE-1; ++i) + { + if(!extantCol[i]) + { + ++deadRange; + if(extantCol[i+1] && maxDeadrange < deadRange) + { + leftCoordinate = i+1; + maxDeadrange = deadRange; + deadRange = 0; + } + } + } + + Log(Log::DEBUG)<<"Left coordinate before seam "< detectCharucoPoints(cv::Mat image, bool verbose) @@ -86,6 +143,8 @@ std::vector detectCharucoPoints(cv::Mat image, bool verbose) detections.push_back(DetectedPoint(charucoCorners[i], coordiante)); } + seamAjust(detections); + return detections; } return std::vector(); diff --git a/src/main.cpp b/src/main.cpp index 3ec1c41..0ac8aef 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*14, fileName); + createCharucoBoard(config.size*42, fileName); Log(Log::INFO)<<"Exported charuco map of size "<