opencv摄像机标定代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
// cvCalib.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include
void InitCorners3D(CvMat *Corners3D, CvSize ChessBoardSize, int Nimages, float SquareSize);
int image_width = 768;
int image_height = 576;//待标定图片的大小
const int ChessBoardSize_w = 7;
const int ChessBoardSize_h = 7;//图片中可标定的角数
const CvSize ChessBoardSize = cvSize(ChessBoardSize_w,ChessBoardSize_h);
const int NPoints = ChessBoardSize_w*ChessBoardSize_h;//角点个数
const int NImages=6;//待标定的图片数
int corner_count[NImages] = {0};
float SquareWidth = 10; //棋盘格子的边长,可任意设定,不影响内参数
CvMat *intrinsics;
CvMat *distortion_coeff;
CvMat *rotation_vectors;
CvMat *translation_vectors;
CvMat *object_points;
CvMat *point_counts;
CvMat *image_points;
void main()
{
IplImage *current_frame_rgb;
IplImage *current_frame_gray;
IplImage *chessBoard_Img;
CvPoint2D32f corners[NPoints*NImages];
chessBoard_Img =cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);
current_frame_gray = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);
current_frame_rgb = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);
int captured_frames=0;
for(captured_frames=0;captured_frames { char filename[]="cal20Img00.bmp"; //说明:我把待标定的图片的名子依次命名为:01.jpg, 02.jpg, 03.jpg, 04.jpg,…… if(captured_frames<9) filename[9]=(char)(captured_frames+49); else if(captured_frames>=9&&captured_frames<=99) { int j,jj; jj=(captured_frames+1)/10; j=(captured_frames+1)%10; filename[8]=jj+48; filename[9]=j+48; } else printf("error, too many images.......\n"); //load images end chessBoard_Img=cvLoadImage( filename, CV_LOAD_IMAGE_COLOR ); cvCvtColor(chessBoard_Img, current_frame_gray, CV_BGR2GRAY); cvCopy(chessBoard_Img,current_frame_rgb); int find_corners_result; find_corners_result = cvFindChessboardCorners(current_frame_gray, ChessBoardSize, &corners[captured_frames*NPoints], &corner_count[captured_frames],//int corner_count[NImages] = {0}; CV_CALIB_CB_ADAPTIVE_THRESH ); cvFindCornerSubPix( current_frame_gray, &corners[captured_frames*NPoints], NPoints, cvSize(2,2),cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03) ); cvDrawChessboardCorners(current_frame_rgb, ChessBoardSize, //绘制检测到的棋盘角点 &corners[captured_frames*NPoints], NPoints, find_corners_result); cvNamedWindow("Window 0", 1); cvNamedWindow("result", 1); cvShowImage("Window 0",chessBoard_Img); cvShowImage("result",current_frame_rgb);