Opencv学习笔记 ---opencv生成摄像头标定棋盘

由于3D重建跟双目视觉的需要,
对标定棋盘图的生成C++代码如下(只需修改棋盘的角点数x、y即可改变棋盘大小):

Opencv 1.x版本:

#include   
#include   

void main()
{
	int y = 6;			//所生成的棋盘格的角点个数y
	int x = 4;			//所生成的棋盘格的角点个数x 
	IplImage *img;
	int cube = 150;        //棋盘格大小,像素为单位 
	int dy = y + 1;       //棋盘格数目dy
	int dx = x + 1; 	  //棋盘格数目dx
	img = cvCreateImage(cvSize(dy * cube,dx * cube), IPL_DEPTH_8U, 1);
	//初始化图像
	for (int i = 0; i< dx; i++)
		for (int j = 0; j< dy; j++)
		{
			for (int m = i*cube; m<(i + 1)*cube; m++)
				for (int n = j*cube; n<(j + 1)*cube; n++)
					((uchar *)(img->imageData + m * img->widthStep))[n] = 255;
			//*(img->imageData+m*img->widthStep+n)=255;  
		}
	//绘画棋盘格
	int flag = 0;
	for (int i = 0; i< dx; i++)
	for (int j = 0; j< dy; j++)
	{
		flag = (i + j) % 2;
		if (flag == 0)
		{
			for (int m = i*cube; m<(i + 1)*cube; m++)
			for (int n = j*cube; n<(j + 1)*cube; n++)
				((uchar *)(img->imageData + m * img->widthStep))[n] = 0;
			//*(img->imageData+m*img->widthStep+n)=255;  
		}
	}
	//生成标定图
	//cvSaveImage("ChessBoard.bmp", img);
	cvNamedWindow("ChessBoard", 1);
	cvShowImage("ChessBoard", img);
	cvWaitKey(0);

	cvReleaseImage(&img);
	cvDestroyWindow("ChessBoard");
}

Opencv 2.x版本:(可以根据需要自己调节角点个数)

#include 
#include 
using namespace cv;
using namespace std;

int main(int argc,char* argv[])
{
	//A4纸大小  cols*rows = 630*891
	Mat img(630, 891, CV_8UC1, Scalar::all(0));
	int channel = img.channels();
	int cube = 90;

	for (int j = 0; j(j);
		for (int i = 0; i

Opencv学习笔记 ---opencv生成摄像头标定棋盘_第1张图片


你可能感兴趣的:(opencv,opencv)