opencv 图像标定定checkerboard origin啥意思

高精度USB摄像头实现摄像机标定的问题! - OpenCV中文网站 - Powered by Discuz!
OpenCV中文网站
标题: 高精度USB摄像头实现摄像机标定的问题!
作者: yy& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!我用一个精度稍微高点的摄像头实现摄像头标定的例程,发现一个莫名的错误,错误见附件,请问这个是什么问题呀?
作者: yy& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!问题已经解决
作者: gaolitao& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!麻烦问一下楼主用的是什么摄像头?多少万像素的?清晰度如何?价格多少?最近做实验要用到摄像机标定,麻烦给点意见。
作者: yy& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!开始用的微视USB摄像头,500万像素,现在用微视工业CCD,800*600,希望对你有帮助。
作者: dickhook& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!麻烦楼主,我现在也同样遇到这个问题,请问是如何解决的
作者: liminghnau& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!可以把程序法给我学习一下吗?谢谢!
作者: giggsnet& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!楼主代码能分享出来学习学习么?
邮箱giggsnet@,谢谢
作者: xiaocuiman& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!各位师兄,可以把摄像机标定程序给我传一份吗?我正在做这方面的课题呢,谢谢!
作者: xiaocuiman& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!终于自己在Opencv下完成了该程序!
作者: xiaocuiman& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!/*基于OpenCV的自标定技术实现----------各个矩阵的作用--------------& && && && && &&&//内参矩阵[fx,0,0,fy,0,0,1]distortion_& && && &&&//形变参数向量4*1[k1,k2,p1,p2] &&rotation_& && && &&&//旋转向量 3*1translation_& && &&&//平移变量 3*1& & & & R,T为从世界坐标系到图像坐标系的旋转和平移变换矩阵*/#include &stdafx.h&#include &stdio.h&#include &stdlib.h&#include &string.h&// OpenCV#include &cxcore.h&#include &cv.h&#include &highgui.h&#include &cvaux.h&//生成角点三维空间的坐标void InitCorners3D(CvMat *Corners3D, CvSize ChessBoardSize, int Nimages, float SquareSize);void makeChessBoard();//函数myFindChessboardCorners寻找棋盘图的内角点位置int myFindChessboardCorners( const void* image, CvSize pattern_size,& & & & & & & & & & & & & & & & & & & & & & & & & & & & CvPoint2D32f* corners, int* corner_count=NULL,& & & & & & & & & & & & & & & & & & & & & & & & & & & & int flags=CV_CALIB_CB_ADAPTIVE_THRESH );//绘制一个十字标记inline int drawCorssMark(IplImage *dst,CvPoint pt)/*************************************************Function:& && &&&main_loopDescription:& &&&绘制一个十字标记& & & & & & & & & & & & & & & & & & & & Calls:& && && & Called By:& && &Input:& && && &&&RGB image,&&pt& && && && && &Output:& && && &Return:& && && &Others:& && && & 需要检查坐标是否越界 to do list*************************************************/{& & & & & & & & const int cross_len = 4;& & & & CvPoint pt1,pt2,pt3,pt4;& & & & pt1.x = pt.x;& & & & pt1.y = pt.y - cross_& & & & pt2.x = pt.x;& & & & pt2.y = pt.y + cross_& & & & pt3.x = pt.x - cross_& & & & pt3.y = pt.y;& & & & pt4.x = pt.x + cross_& & & & pt4.y = pt.y;& & & & & & & & cvLine(dst,pt1,pt2,CV_RGB(0,255,0),2,CV_AA, 0 );&&& & & & & & & & cvLine(dst,pt3,pt4,CV_RGB(0,255,0),2,CV_AA, 0 );&&& & & & & & & & return 0;}/* declarations for OpenCV */IplImage& && && && && &&&*current_frame_rgb,& & //RGB图IplImage& && && && && &&&*current_frame_& & & & & & & & //灰度图IplImage& && && && && &&&*chessBoard_I& & & & & & & & & & & & //棋盘图//int& && && && && && && &&&Thresholdness = 120;& && &//阈值, 二值化int& && && && && && && &&&Thresholdness = 1;int image_width = 320;& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //定义图像大小int image_height = 240;//bool verbose =const int ChessBoardSize_w = 8; //const int ChessBoardSize_h = 6; //图片中可标定的标角数// Calibration stuffbool& & & & & & & & & & & & calibration_done =const CvSize & & & & ChessBoardSize = cvSize(ChessBoardSize_w,ChessBoardSize_h); //以像素为单位 定义棋盘大小//float & & & & & & & & & & & & SquareWidth = 21.6f; //实际距离 毫米单位 在A4纸上为两厘米float & & & & & & & & SquareWidth = 17;& & & & //投影实际距离 毫米单位&&200;//棋盘格子的边长,可任意设定,不影响内参数,只影响内参数const& &int NPoints = ChessBoardSize_w*ChessBoardSize_h;const& &int NImages = 24; //& && && && && && && && && && &&&捕获图片数CvPoint2D32f corners[NPoints*NImages]; //三维浮点坐标int corner_count[NImages] = {0};int captured_frames = 0;CvMat *& && && && && &&&//内参矩阵[fx,0,0,fy,0,0,1]CvMat *distortion_& && && &&&//形变参数向量4*1[k1,k2,p1,p2]& &CvMat *rotation_& && && &&&//旋转向量 3*1CvMat *translation_& && &&&//平移变量 3*1CvMat *object_& & & & & & & & & & & && & //物体点的坐标--定标点的世界坐标 CvMat *point_& & & & & & & & & & & && & //向量数目& &CvMat *image_& & & & & & & & & & & && & //输出数组&&存储图像点的坐标---定标点的图象坐标int find_corners_result =0 ;/*void on_mouse( int event, int x, int y, int flags, void* param ){&&//&&if( event == CV_EVENT_LBUTTONDOWN )&&{& & & & & & & & //calibration_done = & & & & & & & & }& & & & & & & & }*//*&&主函数&&*/int main(int argc, char *argv[]){& & & & & & & & & & & & CvF& & & & cvInitFont( &font, CV_FONT_VECTOR0,5, 5, 0, 7, 8);& & & & & & & & intrinsics & & & & & & & & = cvCreateMat(3,3,CV_32FC1); //为新矩阵非配头和数据& & & & //& & & & distortion_coeff & & & & = cvCreateMat(1,4,CV_32FC1);& & & & distortion_coeff & & & & = cvCreateMat(4,1,CV_32FC1);& & & & rotation_vectors & & & & = cvCreateMat(NImages,3,CV_32FC1);& & & & translation_vectors & & & & = cvCreateMat(NImages,3,CV_32FC1);& & & & & & & & point_counts & & & & & & & & = cvCreateMat(NImages,1,CV_32SC1);& & & & & & & & object_points & & & & =& & & & cvCreateMat(NImages*NPoints,3,CV_32FC1);& & & & image_points = cvCreateMat(NImages*NPoints,2,CV_32FC1);& & & & & & & & & & & & // Function to fill in the real-world points of the checkerboard& & & & //生成角点三维空间的坐标& & & & InitCorners3D(object_points, ChessBoardSize, NImages, SquareWidth);& & & & & & & & & & & & CvCapture* capture = 0;& & & & & & & & & & & & //摄像头& & & & if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))& & & & & & & & capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - \'0\' : 0 );& & & & //视频流& & & & else if( argc == 2 )& & & & & & & & capture = cvCaptureFromAVI( argv[1] );& & & & //无摄像头& & & & if( !capture )& & & & {& & & & & & & & fprintf(stderr,&Could not initialize capturing...\\n&);& & & & & & & & return -1;& & & & }& & & & & & & & & & & & // Initialize all of the IplImage structures& & & & current_frame_rgb = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);& & & & & & & & IplImage *current_frame_rgb2 = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);& & & & current_frame_gray = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);& & & & & & & & chessBoard_Img& &= cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);&&& & & & current_frame_rgb2-&origin = chessBoard_Img-&origin&&= current_frame_gray-&origin = current_frame_rgb-&origin = 1;& & & & & & & & makeChessBoard();& & & & & & & & cvNamedWindow( &result&, 0);& & & & cvNamedWindow( &Window 0&, 0);& & & & cvNamedWindow( &grid&, 0);& & & & & & & & & & & & cvNamedWindow(&src&,0);& & & & cvMoveWindow(&src&,300,450);& & & & & & & & & & & & cvMoveWindow( &grid&, 20,20);& & & & & & & & /* 设定阈值 二值化& & & & cvSetMouseCallback( &Window 0&, on_mouse, 0 );&&/& & & & cvCreateTrackbar(&Thresholdness&,&Window 0&,&Thresholdness, 255,0); & & & & */& & & & & & & & cvCreateTrackbar(&Thresholdness&,&Window 0&,&Thresholdness, 50,0);& & & & while (!calibration_done)& & & & {& & & & & & & & & & & & & & & & while (captured_frames & NImages)& & & & & & & & {& & & & & & & & & & & & current_frame_rgb = cvQueryFrame( capture );& & & & & & & & & & & & // cvShowImage(&Window 0&,current_frame_rgb); //+++++& & & & & & & & & & & & //current_frame_rgb = cvLoadImage( &c:\\\\BoardStereoL3.jpg& );& & & & & & & & & & & & //cvCopy(chessBoard_Img,current_frame_rgb);& & & & /*& & & & & & & & char filename[]=&00.jpg&; //说明:我把待标定的图片的名子依次命名为:01.jpg, 02.jpg, 03.jpg, 04.jpg,…… & & & & & & & & & & & & & & & & & & & & & & & & filename[1]=(char)(captured_frames+49); & & & & */& & & & & & & & & & & & & & & & & & & & if( !current_frame_rgb )& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & && & & & & & & & & & & & /*& & & & & & & & & & & & & & & & ////////////////////////////////////////////////////////////& & & & & & & & & & & & int captured_frames=0; & & & & & & & & & & & & for(captured_frames=0;captured_frames&NIcaptured_frames++) & & & & & & & & & & & & { & & & & & & & & & & & & & & & & char filename[]=&00.jpg&; //说明:我把待标定的图片的名子依次命名为:01.jpg, 02.jpg, 03.jpg, 04.jpg,…… & & & & & & & & & & & & & & & & if(captured_frames&9) & & & & & & & & & & & & & & & & & & & & filename[1]=(char)(captured_frames+49); & & & & & & & & & & & & & & & & else printf(&error, too many images.......\\n&); //load images end & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & current_frame_rgb=cvLoadImage( filename, CV_LOAD_IMAGE_COLOR ); & & & & & & & & & & & & & & & & ////////////////////////////////////////////////////////////& & & & & & & & */& & & & & & & & & & & & //& & & & & & & & current_frame_rgb=cvLoadImage( filename, CV_LOAD_IMAGE_COLOR ); & & & & & & & & & & & & & & & & cvCopy(current_frame_rgb,current_frame_rgb2); //current_frame_rgb--&current_frame_rgb2& & & & & & & & & & & & & & & & cvCvtColor(current_frame_rgb, current_frame_gray, CV_BGR2GRAY);//current_frame_rgb--&current_frame_gray& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & && & /* 二值化& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & && & //cvThreshold(current_frame_gray,current_frame_gray,Thresholdness,255,CV_THRESH_BINARY);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & && & //cvThreshold(current_frame_gray,current_frame_gray,150,255,CV_THRESH_BINARY_INV);& & & & & & & & & & & & & & & & */& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & /*& & & & & & & & & & & & & & & & int pos = 1;& & & & & & & & & & & & & & & & IplConvKernel* element = 0;& & & & & & & & & & & & & & & & const int element_shape = CV_SHAPE_ELLIPSE;& & & & & & & & & & & & & & & & element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, 0 );& & & & & & & & & & & & & & & & cvDilate(current_frame_gray,current_frame_gray,element,1);& & & & & & & & & & & & & & & & cvErode(current_frame_gray,current_frame_gray,element,1);& & & & & & & & & & & & & & & & cvReleaseStructuringElement(&element);& & & & & & & & & & & & & & & & */& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & /* 寻找棋盘图的内角点位置 */& & & & & & & & & & & & & & & & find_corners_result = cvFindChessboardCorners(current_frame_gray,//image 输入的其盘图& & & & & & & & & & & & & & & & & & & & ChessBoardSize,& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //其盘图中每行和每列角点的个数& & & & & & & & & & & & & & & & & & & & &corners[captured_frames*NPoints],& & & & & & & & & & & & & & & & & & & & & & & & & & & & //检测到的角点& & & & & & & & & & & & & & & & & & & & &corner_count[captured_frames],& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //输出变量,角点的个数& & & & & & & & & & & & & & & & & & & & 0);& & & & & & & & & & & & & & & & /* 精确查找角点 */& & & & & & & & & & & & & & & & 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_rgb2,& & & & & & & & & & & & & & & & & & & & & & & & //结果图像 ,彩色& & & & & & & & & & & & & & & & & & & & ChessBoardSize,& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //每行和每列角点的个数& & & & & & & & & & & & & & & & & & & & &corners[captured_frames*NPoints],& & & & & & & & & & & & & & & & & & & & & & & & & & & & //检测到的角点数组& & & & & & & & & & & & & & & & & & & & & & & & NPoints,& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //角点数目& & & & & & & & & & & & & & & & & & & & find_corners_result);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & //指示完整棋盘被发现与否(非0 or 0)& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & cvShowImage(&Window 0&,current_frame_rgb2);& & & & & & & & & & & & & & & & cvShowImage(&grid&,chessBoard_Img);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & cvWaitKey(500); & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & /*& & & & & & & & & & & & & & & & if(captured_frames&NImages-1)& & & & & & & & & & & & & & & && & & & & & & & & & & & & & & & */& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & if(find_corners_result==1) //完整棋盘被发现& & & & & & & & & & & & & & & & {& & & & & & & & & & & & & & & & & & & & cvWaitKey(2000);& & & & & & & & & & & & & & & & & & & & /*& &write picture&&*/& & & & & & & & & & & & & & & & & & & & cvSaveImage(&c:\\\\hardyinCV.jpg&,current_frame_rgb2);//cvSaveImage(&c:\\\\hardyinCV.jpg&,current_frame_gray);& & & & & & & & & & & & & & & & & & & & captured_frames++;& & & & & & & & & & & & & & & & & & & & cvSetTrackbarPos(&Thresholdness&,&Window 0&,++Thresholdness);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & printf(&-----Captured_Number=%d------\\n&,captured_frames);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & cvShowImage(&result&,current_frame_gray);& & & & & & & & & & & & & & & & cvShowImage(&src&,current_frame_rgb);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & intrinsics-&data.fl[0] = float(256.8093262);& &//fx& & & & & & & & & & & & & & & & & & & & & & & & intrinsics-&data.fl[2] = float(160.2826538);& &//cx& & & & & & & & & & & & & & & & intrinsics-&data.fl[4] = float(254.7511139);& &//fy& & & & & & & & & & & & & & & & intrinsics-&data.fl[5] = float(127.6264572);& &//cy& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & intrinsics-&data.fl[1] = float(0.0);& && & & & & & & & & & & & & & & & intrinsics-&data.fl[3] = float(0.0);& && & & & & & & & & & & & & & & & intrinsics-&data.fl[6] = float(0.0);& && & & & & & & & & & & & & & & & intrinsics-&data.fl[7] = float(0.0);& && & & & & & & & & & & & & & & & intrinsics-&data.fl[8] = float(1.0);& && & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & distortion_coeff-&data.fl[0] = float(-0.193740);&&//k1& & & & & & & & & & & & & & & & distortion_coeff-&data.fl[1] = float(-0.378588);&&//k2& & & & & & & & & & & & & & & & distortion_coeff-&data.fl[2] = float(0.028980);& &//p1& & & & & & & & & & & & & & & & distortion_coeff-&data.fl[3] = float(0.008136);& &//p2& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & cvWaitKey(40);& & & & & & & & & & & & & & & & //& & & & & & & & find_corners_result = 0;& & & & & & & & }&&& & & & & & & & & & & & & & & & //if (find_corners_result !=0)& & & & & & & & {& & & & & & & & & & & & & & & & & & & & & & & & printf(&\\n&);& & & & & & & & & & & & & & & & & & & & & & & & cvSetData( image_points, corners, sizeof(CvPoint2D32f));& & & & & & & & & & & & cvSetData( point_counts, &corner_count, sizeof(int));& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & cvCalibrateCamera2( object_points,& & & & & & & & //定标点的坐标 N*3& & & & & & & & & & & & & & & & image_points,& & & & & & & & & & & & & & & & & & & & & & & & //定标点在图像内的坐标N*2& & & & & & & & & & & & & & & & point_counts,& & & & & & & & & & & & & & & & & & & & & & & & //向量,指定不同视图里点的数目& & & & & & & & & & & & & & & & cvSize(image_width,image_height),& & & & //image_size图像大小& & & & & & & & & & & & & & & & intrinsics,& & & & & & & & & & & & & & & & & & & & & & & & & & & & //输出内参矩阵A [fx,0, 0,fy, 0,0,1]& & & & & & & & & & & & & & & & distortion_coeff,& & & & & & & & & & & & & & & & & & & & //输出大小为4*1 [k1,k2,p1,p2]& & & & & & & & & & & & & & & & rotation_vectors,& & & & & & & & & & & & & & & & & & & & //输出大小为3*1 旋转向量& & & & & & & & & & & & & & & & translation_vectors,& & & & & & & & & & & & & & & & //输出大小为3*1 平移向量& & & & & & & & & & & & & & & & 0);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & // [fx 0 0 0 0 1].& & & & & & & & & & & & cvUndistort2(current_frame_rgb,current_frame_rgb2,intrinsics,distortion_coeff);//校正图像因摄像机镜头引起的变形& & & & & & & & & & & & //& & & & cvShowImage(&result&,current_frame_rgb);& & & & & & & & & & & & cvShowImage(&dst&,current_frame_rgb);& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & float intr[3][3] = {0.0};& & & & & & & & & & & & float dist[4] = {0.0};& & & & & & & & & & & & float tranv[3] = {0.0};& & & & & & & & & & & & float rotv[3] = {0.0};& & & & & & & & & & & & & & & & & & & & & & & & for ( int i = 0; i & 3; i++)& & & & & & & & & & & & {//?& & & & & & & & & & & & & & & & for ( int j = 0; j & 3; j++)& & & & & & & & & & & & & & & & {& & & & & & & & & & & & & & & & & & & & intr[i][j] = ((float*)(intrinsics-&data.ptr + intrinsics-&step*i))[j];& & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & dist[i] = ((float*)(distortion_coeff-&data.ptr))[i];& & & & & & & & & & & & & & & & tranv[i] = ((float*)(translation_vectors-&data.ptr))[i];& & & & & & & & & & & & & & & & rotv[i] = ((float*)(rotation_vectors-&data.ptr))[i];& & & & & & & & & & & & }& & & & & & & & & & & & dist[3] = ((float*)(distortion_coeff-&data.ptr))[3];& & & & & & & & & & & & & & & & & & & & & & & & //******************************& & & & & & & & & & & & /*& & & & & & & & & & & & float RotaVec[9]={0.0}; & & & & & & & & & & & & CvMat *rotation=cvCreateMat(1,3,CV_32FC1); & & & & & & & & & & & & for(int m=0;i&3;m++) & & & & & & & & & & & & (rotation-&data.fl)[m]=rotv[m]; & & & & & & & & & & & & rotation-&type=rotation_vectors-& & & & & & & & & & & & & rotation-&step=rotation_vectors-& & & & & & & & & & & & & rotation-&refcount=rotation_vectors-& & & & & & & & & & & & & rotation-&data.ptr=rotation_vectors-&data. & & & & & & & & & & & & CvMat *RotationVec= cvCreateMat(3,3,CV_32FC1); & & & & & & & & & & & & cvRodrigues2(rotation,RotationVec,0); & & & & & & & & & & & & for(int k=0;k&9;k++) & & & & & & & & & & & & RotaVec[k]=((float*)(RotationVec-&data.ptr))[k]; & & & & & & & & & & & & */& & & & & & & & & & & & //******************************& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & printf(&-----------------------------------------\\n&);& & & & & & & & & & & & printf(&INTRINSIC MATRIX: \\n&);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f ] \\n&, intr[0][0], intr[0][1], intr[0][2]);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f ] \\n&, intr[1][0], intr[1][1], intr[1][2]);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f ] \\n&, intr[2][0], intr[2][1], intr[2][2]);& & & & & & & & & & & & printf(&-----------------------------------------\\n&);& & & & & & & & & & & & printf(&DISTORTION VECTOR: \\n&);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f %6.4f ] \\n&, dist[0], dist[1], dist[2], dist[3]);& & & & & & & & & & & & printf(&-----------------------------------------\\n&);& & & & & & & & & & & & printf(&ROTATION VECTOR: \\n&);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f ] \\n&, rotv[0], rotv[1], rotv[2]);& & & & & & & & & & & & printf(&TRANSLATION VECTOR: \\n&);& & & & & & & & & & & & printf(&[ %6.4f %6.4f %6.4f ] \\n&, tranv[0], tranv[1], tranv[2]);& & & & & & & & & & & & printf(&-----------------------------------------\\n&);& & & & & & & & & & & & printf(&-----------------Good Luck!--------------\\n&);& & & & & & & & & & & & & & & & & & & & & & & & & & & & cvWaitKey(0);& & & & & & & & & & & & & & & & & & & & & & & & calibration_done =& && & & & & & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & cvReleaseCapture(&capture);& & & & & & & & &&}&&&&&&exit(0);&&cvReleaseCapture(&capture);&&cvDestroyAllWindows();}//生成角点三维空间的坐标void InitCorners3D(CvMat *Corners3D, CvSize ChessBoardSize, int NImages, float SquareSize){& & & & int CurrentImage = 0;& & & & int CurrentRow = 0;& & & & int CurrentColumn = 0;& & & & int NPoints = ChessBoardSize.height*ChessBoardSize.& & & & float * temppoints = new float[NImages*NPoints*3]; //坐标数组& & & & & & & & // for now, assuming we\'re row-scanning& & & & for (CurrentImage = 0 ; CurrentImage & NI CurrentImage++)& & & & {& & & & & & & & for (CurrentRow = 0; CurrentRow & ChessBoardSize. CurrentRow++) //行& & & & & & & & {& & & & & & & & & & & & for (CurrentColumn = 0; CurrentColumn & ChessBoardSize. CurrentColumn++) //列& & & & & & & & & & & & {& & & & & & & & & & & & & & & & temppoints[(CurrentImage*NPoints*3)+(CurrentRow*ChessBoardSize.width + CurrentColumn)*3]=(float)CurrentRow*SquareS& & & & & & & & & & & & & & & & temppoints[(CurrentImage*NPoints*3)+(CurrentRow*ChessBoardSize.width + CurrentColumn)*3+1]=(float)CurrentColumn*SquareS& & & & & & & & & & & & & & & & temppoints[(CurrentImage*NPoints*3)+(CurrentRow*ChessBoardSize.width + CurrentColumn)*3+2]=0.0;& & & & & & & & & & & & }& & & & & & & & }& & & & }& & & & (*Corners3D) = cvMat(NImages*NPoints,3,CV_32FC1, temppoints);}//实现 角点检测int myFindChessboardCorners( const void* image, CvSize pattern_size,& & & & & & & & & & & & & & & & & & & & & & & & & & & & CvPoint2D32f* corners, int* corner_count,& & & & & & & & & & & & & & & & & & & & & & & & & & & & int flags )& & & & & & & & & & & & & & & & & & & & & & & & & & & & {& & & & & & & & & & & & IplImage* eig = cvCreateImage( cvGetSize(image), 32, 1 );//创建图像头并分配空间& & & & IplImage* temp = cvCreateImage( cvGetSize(image), 32, 1 );& & & & double quality = 0.01;& & & & double min_distance = 5;& & & & int win_size =10;& & & & & & & & int count = pattern_size.width * pattern_size. //角点数& & & & cvGoodFeaturesToTrack( image, eig, temp, corners, &count, //在图像中找寻具有最大特征点的角点& & & & & & & & quality, min_distance, 0, 3, 0, 0.04 );& & & & cvFindCornerSubPix( image, corners, count,& && && && && &//寻找精确的角点位置& & & & & & & & cvSize(win_size,win_size), cvSize(-1,-1),& & & & & & & & cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03));& & & & & & & & cvReleaseImage( &eig );& & & & cvReleaseImage( &temp );& & & & & & & & return 1;}//画 棋盘图void makeChessBoard(){& & & & & & & & CvS & & & & e.val[0] =255;& & & & e.val[1] =255;& & & & e.val[2] =255;& & & & cvSet(chessBoard_Img,e,0);& & & & for(int i = 0;i&ChessBoardSize.width+1;i++)& & & & & & & & for(int j = 0;j&ChessBoardSize.height+1;j++)& & & & & & & & {& & & & & & & & & & & & int w =(image_width)/2/(ChessBoardSize.width);& & & & & & & & & & & & int h = //(image_height)/2/(ChessBoardSize.height);& & & & & & & & & & & & & & & & & & & & & & & & int ii = i+1;& & & & & & & & & & & & int iii = ii+1;& & & & & & & & & & & & int jj =j+1;& & & & & & & & & & & & int jjj =jj+1;& & & & & & & & & & & & int s_x = image_width/6;& & & & & & & && && & & & & & & & & & & & & & & & & & & & & & & & if((i+j)%2==1)& & & & & & & & & & & & & & & & cvRectangle( chessBoard_Img, & & & & & & & & & & & & & & & & cvPoint(w*i+s_x,h*j+s_x),& & & & & & & & & & & & & & & & cvPoint(w*ii-1+s_x,h*jj-1+s_x), & & & & & & & & & & & & & & & & CV_RGB(0,0,0),CV_FILLED, & & & & & & & & & & & & & & & & 8, & & & & & & & & & & & & & & & & 0 );& & & & & & & & }}复制代码记得将Opencv库连接上!OK!
作者: ollydbg23& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!这个一定要赞的!不错不错!
不过我看了一下,你的代码里面,中文很多错别字。
另外,这么好的文章,建议你放到wiki里面去!
作者: zousong& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!intrinsics-&data.fl[0] = float(256.8093262); //fx
intrinsics-&data.fl[2] = float(160.2826538); //cx
intrinsics-&data.fl[4] = float(254.7511139); //fy
intrinsics-&data.fl[5] = float(127.6264572); //cy
请问为什么用上面的参数初始化呢?
作者: xiaoniug12& & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!弱弱的问一声 这里的摄像头可以是QQ视频那种吗?
我用的是大恒的USB摄像头,运行程序怎么说找不到呢
作者: & & 时间:
标题: 高精度USB摄像头实现摄像机标定的问题!为什么官网上程序编译连接都没问题,但是运行后死掉,dos提示
Assertion failed (src.depth()==des.depth() && src.size==des.size ) is unkown function
程序是不是还需要什么输入啊。
作者: Jstar& & 时间:
请问想跟踪一个物体运动的角度需要摄像机标定吗?
欢迎光临 OpenCV中文网站 (http://www./)
Powered by Discuz! X3.2

我要回帖

更多关于 opencv 图像标定 的文章

 

随机推荐