be more picky about front and back cols

This commit is contained in:
2021-07-02 00:26:20 +02:00
parent 2e3d0d2938
commit f3d2a19781
6 changed files with 15 additions and 58 deletions

View File

@ -22,10 +22,6 @@
#include <opencv2/highgui.hpp>
#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<cv::aruco::CharucoBoard> 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);

View File

@ -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 "<<config.size*14<<" to "<<fileName;
return 0;
}

View File

@ -250,7 +250,8 @@ void fillMissing(cv::Mat& mat)
}
}
}
if(!finished) fillMissing(mat);
if(!finished)
fillMissing(mat);
}
bool findDeadSpace(const cv::Mat& mat, cv::Rect& roi)
@ -287,48 +288,7 @@ bool findDeadSpace(const cv::Mat& mat, cv::Rect& roi)
return true;
}
bool deleteEmptyCols(cv::Mat& mat)
{
assert(mat.type() == CV_32FC1);
std::vector<size_t> 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<float>(x,y) > 0)
{
empty = false;
break;
}
}
if(!empty)
cols.push_back(x);
}
if(mat.cols < static_cast<long int>(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<float>(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)

View File

@ -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);

View File

@ -97,11 +97,11 @@ bool createRemapMap(const cv::Mat& image, RemapMap& out, const std::vector<Detec
Log(Log::DEBUG)<<__func__<<": xMat raw\n"<<out.xMat;
int cols = out.xMat.cols;
removeSparseCols(out.xMat, true);
removeSparseCols(out.xMat, 0.75,true);
out.topLeftCoordinate.x += cols-out.xMat.cols;
removeSparseCols(out.xMat, false);
removeSparseCols(out.yMat, true);
removeSparseCols(out.yMat, false);
removeSparseCols(out.xMat, 0.75, false);
removeSparseCols(out.yMat, 0.75, true);
removeSparseCols(out.yMat, 0.75, false);
Log(Log::DEBUG)<<__func__<<": xMat rejcted\n"<<out.xMat;
fillMissing(out.xMat);
Log(Log::DEBUG)<<__func__<<": xMat filled\n"<<out.xMat;

View File

@ -23,6 +23,9 @@
#include <opencv2/core/ocl.hpp>
#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<DetectedPoint> detectCharucoPoints(cv::Mat image, bool verbose = true);