1. 基于findChessboardCorners的双目精度评估
原理:
代码:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
// 加载图像
auto srcimage = imread("/home/oem/data/steroe_precision_evo/left1.jpg");
if(srcimage.empty())
{
cout << "Image not found." << endl;
return -1;
}
// 棋盘格尺寸
Size patternSize(6, 8); // 直接指定棋盘格内角点数量,减1已在此处处理
// 检测棋盘格角点
vector<Point2f> corners;
bool found = findChessboardCorners(srcimage, patternSize, corners);
cout << " ret:" << found << endl;
cout << " corners_size:" << corners.size() << endl;
// 如果找到足够角点,进行亚像素精确化
if(found)
{
cvtColor(srcimage, srcimage, COLOR_BGR2GRAY); // 重用srcimage, 减少Mat对象的创建
cornerSubPix(srcimage, corners, Size(11,11), Size(-1,-1),
TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 30, 0.1));
cvtColor(srcimage, srcimage, COLOR_GRAY2BGR); // 转回彩色图用于显示
}
// 绘制检测到的角点
drawChessboardCorners(srcimage, patternSize, corners, found);
// 显示图像
namedWindow("chessboard corners", WINDOW_AUTOSIZE);
imshow("chessboard corners", srcimage);
waitKey(0);
return 0;
}
cmakelists:
find_package(OpenCV 4)
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
)
add_executable(stereo_evo Examples/stereo_evo.cc)
target_link_libraries(stereo_evo
${PROJECT_NAME})
输入:
输出:
注意点:
其中棋盘格尺寸尤其容易出错!!!,且注意检查
// 棋盘格尺寸
Size patternSize(6, 8); // 直接指定棋盘格内角点数量,减1已在此处处理