使用雙目攝像頭進行立體視覺算法時,攝像頭標定是必不可少的。通常採用黑白棋盤格的方法,本文采用opencv庫實現生成一張黑白棋盤格,棋盤格的格子數可以設定,圖片分辨率也可設定,圖片格式可以自己修改。代碼如下:
#include<iostream>
#include<opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>
using namespace std;
const int perBoardPixel = 1000;
const cv::Size boardSize(9,7);
const cv::Size resolution(9000,7000);
int main()
{
int basisHeight = (resolution.height - perBoardPixel*boardSize.height) / 2;
int basisWidth = (resolution.width - perBoardPixel*boardSize.width) / 2;
if( basisHeight < 0 || basisWidth < 0)
{
cout<<"Resolution doesn't match!"<<endl;
}
cv::Mat image(resolution,CV_8UC1,cv::Scalar::all(255));
int flag = 0;
for(int j = 0;j < boardSize.height;j++)
{
for(int i = 0;i < boardSize.width;i++)
{
flag = (i+j) % 2;
if(flag == 0)
{
for(int n = j * perBoardPixel;n < (j+1) * perBoardPixel;n++)
for(int m = i * perBoardPixel;m < (i+1) * perBoardPixel;m++)
image.at<uchar>(n + basisHeight,m + basisWidth) = 0;
}
}
}
//cv::imshow("haha",image);
cv::imwrite("chessBoard1.bmp",image);
//cv::waitKey(0);
return 0;
}