Camera calibration with square chessboard

The goal of this tutorial is to learn how to calibrate a camera given a set of chessboard images.

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

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

Pose estimation

Now, let us write a code that detects a chessboard in a new image and finds its distance from the camera. You can apply the same method to any object with known 3D geometry that you can detect in an image.

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

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

    Mat img = imread(argv[1], IMREAD_GRAYSCALE);
    
  2. Detect a chessboard in this image using findChessboard function.

    bool found = findChessboardCorners( img, boardSize, ptvec, CALIB_CB_ADAPTIVE_THRESH );
    
  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.

  4. Read camera parameters from XML/YAML file:

    FileStorage fs(filename, FileStorage::READ);
    Mat intrinsics, distortion;
    fs["camera_matrix"] >> intrinsics;
    fs["distortion_coefficients"] >> distortion;
    
  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);
    
  6. Calculate reprojection error like it is done in calibration sample (see opencv/samples/cpp/calibration.cpp, function computeReprojectionErrors).

Question: how to calculate the distance from the camera origin to any of the corners?

Fromhttps://docs.opencv.org/3.0-beta/doc/tutorials/calib3d/camera_calibration_square_chess/camera_calibration_square_chess.html#cameracalibrationsquarechessboardtutorial

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值