opencv 圆形标定板 自带例程 大坑之路

项目要用圆形标定板做实验,于是开始入坑。

一、生成圆形标定版程序

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>


using namespace cv;
using namespace std;


#define WINDOW_WIDTH 1200 //定义窗口大小的宏
#define WINDOW_LENTH 1700
#define WINDOW_NAME1 "【绘制图1】" //为窗口标题定义的宏
#define WINDOW_NAME2 "【绘制图2】" //为窗口标题定义的宏


void drawFilledCircle(cv::Mat img, cv::Point center) {
int thickness = -1;
int lineType = 8;


cv::circle(img,
center,
WINDOW_WIDTH / 12,
cv::Scalar(0, 0, 0),
thickness,
lineType);
}


int main(void) 
{
//cv::Mat src1(300, 400, CV_8UC3, Scalar(255, 255, 255));
//cv::imshow("test", src1);
//创建空白的Mat图像
//cv::Mat atomImage = cv::Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3, Scalar(255, 255, 255));
cv::Mat atomImage(WINDOW_WIDTH, WINDOW_LENTH, CV_8UC3, Scalar(255, 255, 255));
for (int i =180+ WINDOW_WIDTH / 12; i < WINDOW_LENTH; i = i + WINDOW_WIDTH / 4)
{
for (int j = 50+WINDOW_WIDTH / 12; j < WINDOW_WIDTH; j = j+ WINDOW_WIDTH /4)
{
drawFilledCircle(atomImage, cv::Point(i,j));
}
}


//drawFilledCircle(atomImage, cv::Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2));
cv::imwrite("圆形图案.png", atomImage);
cv::imshow(WINDOW_NAME1, atomImage);
cv::waitKey(0);
return(0);

}

二、与棋盘格标定步骤类似,拍摄一定数量的标定图。得到标定图之后使用opencv自带例程中的calibration.cpp和imagelist_creator.cpp进行标定。

第一步编译imagelist_creator.cpp,在同一个工程项目中得到**.exe文件,使用cmd命令行运行**.exe,参数格式为:**  image_list.xml circle_Img1.png circle_Img2.png circle_Img3.png circle_Img4.png circle_Img5.png circle_Img6.png circle_Img7.png;

第二步移除imagelist_creator.cpp,添加calibration.cpp得到**.exe,使用cmd命令运行**.exe  参数格式为:** -w=8 -h=8 -pt=circles -o=camera.yml -op -oe -su image_list.xml

标定的结果就在camera.yml中。结果如下:

%YAML:1.0
---
calibration_time: "Wed May 16 20:51:57 2018"
nframes: 9
image_width: 1920
image_height: 1080
board_width: 7
board_height: 7
square_size: 1.
aspectRatio: 1.
flags: 2
camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 1.0362490335230739e+03, 0., 9.7108613159540334e+02, 0.,
       1.0362490335230739e+03, 5.4090209369614661e+02, 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
   rows: 5
   cols: 1
   dt: d
   data: [ -8.9469853035599213e-03, 4.5811280795862797e-01,
       2.6981460333257727e-05, -7.3334428215945067e-04,
       -1.3256267500188861e+00 ]
avg_reprojection_error: 1.0445166304508596e-01
per_view_reprojection_errors: !!opencv-matrix
   rows: 9


阅读更多
文章标签: o'
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭