C++ OpenCV绘制非对称圆点标定图案
2022/1/3 20:16:33
本文主要是介绍C++ OpenCV绘制非对称圆点标定图案,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
- 原始代码
- 效果图
- 参考引用
通过OpenCV + C++绘制非对称圆点标定图案,注意,非对称圆点图案的维度中的一行实质是一组非对称圆点行(两行),其标定图案示意如下图所示:
原始代码
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/opencv.hpp> using namespace cv; using namespace std; int main() { // 图像宽高 int width = 1400; int height = 1000; // 边框大小 int thicknum = 2; // 标定图案两个维度的大小 int sqXnum = 11; int sqYnum = 4; // 非对称圆点图案的一行实质是一组非对称圆点行 sqYnum = 2 * sqYnum; // 根据输入的特征点数目,自适应计算圆点半径大小(此处预设两圆点圆心之间距离为4*半径) int radius = min(width / (4 * sqXnum + 2), height / (4 * sqYnum + 2)); if (radius <= 0.01 * min(height, width)) { cout << "警告:圆点过小,可能无法识别!" << endl; } int space = 4 * radius; // 生成两个维度方向上的边缘空白 int x_st = (width - 2 * radius * (2 * sqXnum - 1)) / 2; int y_st = (height - 2 * radius * (2 * sqYnum - 1)) / 2; // 生成空白画布 Mat img(height + 2 * thicknum, width + 2 * thicknum, CV_8UC4, Scalar(255, 255, 255, 255)); // 生成起始点圆心坐标 int cir_x = x_st + radius + thicknum; int cir_y = y_st + radius + thicknum; // 用于做非对称的偏移 int Asym_offset = 0; int y_count = 0; // 绘制非对称圆点图案 for (int i = 0; i < img.rows; i++) { if (y_count % 2 == 0) Asym_offset = space / 2; else Asym_offset = 0; for (int j = 0; j < img.cols; j++) { // 绘制边框 if (i < thicknum || i >= thicknum + height || j < thicknum || j >= thicknum + width) { img.at<Vec<uchar, 4>>(i, j) = Scalar(0, 0, 0, 255); continue; } // 绘制圆点 if (cir_y >= img.rows - y_st - thicknum) { continue; } if (i == cir_y && j == cir_x) { // 绘制圆点,LINE_AA得到的边缘最为光滑 circle(img, Point(j, i), radius, cv::Scalar(0, 0, 0, 255), -1, LINE_AA); cir_x += space; } if (cir_x >= img.cols - x_st - thicknum) { cir_x = Asym_offset + x_st + radius + thicknum; cir_y += space; y_count++; } } } imwrite("asymmetric_dot_calib.png", img); imshow("非对称圆点标定图案", img); waitKey(0); return 0 ; }
效果图
参考引用
- opencv生成圆形标定版程序
- MATLAB/OpenCV–基于棋盘格/对称圆点/非对称圆点–相机标定教程
这篇关于C++ OpenCV绘制非对称圆点标定图案的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享
- 2024-06-06基于 casdoor 的 ELK 开源登录认证解决方案: elk-auth-casdoor-icode9专业技术文章分享
- 2024-05-29Elasticsearch慢查询日志配置
- 2024-05-29揭秘华为如此多成功项目的产品关键——Charter模板
- 2024-05-29海外IDC业务拓展的7大挑战
- 2024-05-29InLine Chat功能优化对标Github Copilot,CodeGeeX带来更高效、更直观的编程体验!
- 2024-05-29CodeGeeX 智能编程助手 6 项功能升级,在Visual Studio插件市场霸榜2周!
- 2024-05-29AutoMQ 生态集成 Apache Doris
- 2024-05-292024年IDC行业的深度挖掘:机遇、挑战与未来展望