OpenCV标定板 OpenCV实现简易标定板
Elvin_Chen 人气:0想了解OpenCV实现简易标定板的相关内容吗,Elvin_Chen在本文为您仔细讲解OpenCV标定板的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:OpenCV,标定板,下面大家一起来学习吧。
使用OpenCV生成标定板图片,然后找高精度打印机进行打印,贴在硬板上,就可以得到一个简易的标定板。
废话不多说,代码如下:
//编程环境:VS2013, X64,OpenCV3.0.0 #include <iostream> #include <opencv2\core\core.hpp> #include <opencv2\opencv.hpp> using namespace std; using namespace cv; int main(){ //单位转换 int dot_per_inch = 96; //我的电脑是96DPI(dot per inch) double cm_to_inch = 0.3937; //1cm=0.3937inch double inch_to_cm = 2.54; //1inch = 2.54cm double inch_per_dot = 1.0 / 96.0; //自定义标定板 double blockSize_cm = 1.3; //方格尺寸:边长1.3cm的正方形 int blockNum = 8; //8*8个方格 int blockSize = (int)(blockSize_cm /inch_to_cm *dot_per_inch); cout << blockSize << endl; int imageSize = blockSize * blockNum; cout << imageSize << endl; Mat chessBoard(imageSize, imageSize, CV_8UC3, Scalar::all(0)); unsigned char color = 0; for (int i = 0; i < imageSize; i = i + blockSize){ color = ~color; for (int j = 0; j < imageSize; j = j + blockSize){ Mat ROI = chessBoard(Rect(i, j, blockSize, blockSize)); ROI.setTo(Scalar::all(color)); color = ~color; } } imshow("Chess board", chessBoard); imwrite("C:\\Users\\ComputerName\\Pictures\\chessBoard.jpg",chessBoard); cvWaitKey(3000); return 0; }
声明:代码红色部分是标定板生成的主要代码,参考的 是别人的,具体出处找不到了。单位换算是我后来添加的,方便大家根据镜头视场生成合理的标定板。
加载全部内容