gpt4 book ai didi

c - 什么是 OpenCV FindChessboardCorners 约定?

转载 作者:太空狗 更新时间:2023-10-29 15:42:06 27 4
gpt4 key购买 nike

我正在使用 OpenCV 2.2。

如果我使用 cvFindChessboardCorners 查找棋盘的角点,角点存储在变量 corners 中的顺序是什么(例如,先是左上角,然后是行然后列)?

Documentation (这并没有多大帮助)。

最佳答案

在我看来,该文档缺少此类详细信息。

对于 3.2.0-dev,在我看来这取决于棋盘的旋转角度。使用此代码段:

cv::Size patternsize(4,3); //number of centers
cv::Mat cal = cv::imread(cal_name);
std::vector<cv::Point2f> centers; //this will be filled by the detected centers

bool found = cv::findChessboardCorners( cal, patternsize, centers, cv::CALIB_CB_ADAPTIVE_THRESH );

std::cout << found << "\n";
if(found){
cv::drawChessboardCorners(cal,patternsize,centers,found);

你会得到这些结果:

第一张图片: enter image description here

第一张图像旋转 180 度: enter image description here

注意

colored corners connected with lines

drawChessboardCorners 绘制,它们的区别仅在于颜色:在原始图像中,红线在底部,在旋转后的图像中,红线在图像的顶部。如果您将灰度图像传递给 drawChessboardCorners,您将丢失这条信息。

如果我需要图像左上角的第一个角并且我可以假设:

  1. 场景中棋盘的角度只会接近0或接近180;
  2. 相机的倾斜可以忽略不计;

如果需要,下面的代码片段将重新排列角:

cv::Size patternsize(4,3); //number of centers
cv::Mat cal = cv::imread(cal_name);
std::vector<cv::Point2f> centers; //this will be filled by the detected centers

bool found = cv::findChessboardCorners( cal, patternsize, centers, cv::CALIB_CB_ADAPTIVE_THRESH );

std::cout << found << "\n";
if(found){
cv::drawChessboardCorners(cal,patternsize,centers,found);
// I need the first corner at top-left
if(centers.front().y > centers.back().y){
std::cout << "Reverse order\n";
std::reverse(centers.begin(),centers.end());
}
for(size_t r=0;r<patternsize.height;r++){
for(size_t c=0;c<patternsize.width;c++){
std::ostringstream oss;
oss << "("<<r<<","<<c<<")";
cv::putText(cal, oss.str(), centers[r*patternsize.width+c], cv::FONT_HERSHEY_PLAIN, 3, CV_RGB(0, 255, 0), 3);
}
}
}

enter image description here enter image description here

关于c - 什么是 OpenCV FindChessboardCorners 约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190484/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com