码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV Tutorials —— Camera calibration with square chessboard

时间:2014-11-26 11:14:06      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   sp   for   strong   文件   on   cti   

获取摄像机内部参数矩阵和摄像机畸变参数

Test data: use images in your data/chess folder.

  1. 1,Compile opencv with samples by setting BUILD_EXAMPLES to ON in cmake configuration.
  2. 2,Go to bin folder and use imagelist_creator to create an XML/YAML list of your images.
  3. 3,Then, run calibration sample to get camera parameters. Use square size equal to 3cm.

 

获取到的摄像机参数信息存放在XML /YAML 文件中,然后对失真图像进行矫正

Test data: use chess_test*.jpg images from your data folder.

  1. 1,Create an empty console project. Load a test image:

    Mat img = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
  2. 2,Detect a chessboard in this image using findChessboard function.
  3. bool found = findChessboardCorners( img, boardSize, ptvec, CV_CALIB_CB_ADAPTIVE_THRESH );
  4. 3,Now, write a function that generates a vector<Point3f> array of 3d coordinates of a chessboard in any coordinate system. For simplicity, let us choose a system such that one of the chessboard corners is in the origin and the board is in the plane z = 0.

  5. 4,Read camera parameters from XML/YAML file:

  6. FileStorage fs(filename, FileStorage::READ);
    Mat intrinsics, distortion;
    fs["camera_matrix"] >> intrinsics;
    fs["distortion_coefficients"] >> distortion;
  7. 5,Now we are ready to find chessboard pose by running solvePnP:

    vector<Point3f> boardPoints;
    // fill the array
    ...
    
    solvePnP(Mat(boardPoints), Mat(foundBoardCorners), cameraMatrix,
                         distCoeffs, rvec, tvec, false);
  8. Calculate reprojection error like it is done in calibration sample (see opencv/samples/cpp/calibration.cpp, function computeReprojectionErrors).

OpenCV Tutorials —— Camera calibration with square chessboard

标签:io   ar   os   sp   for   strong   文件   on   cti   

原文地址:http://www.cnblogs.com/sprint1989/p/4122521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!