通过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 = 14;
int sqYnum = 10;
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;
for (int i = 0; i < img.rows; i++) {
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) {
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 = x_st + radius + thicknum;
cir_y += space;
}
}
}
imwrite("dot_calib.png", img);
imshow("圆点标定图案", img);
waitKey(0);
return 0 ;
}
效果图
参考引用
- opencv生成圆形标定版程序
|