OpenCV  3.4.7
Open Source Computer Vision
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.

Pose estimation

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

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

Question: how would you calculate distance from the camera origin to any one of the corners? Answer: As our image lies in a 3D space, firstly we would calculate the relative camera pose. This would give us 3D to 2D correspondences. Next, we can apply a simple L2 norm to calculate distance between any point (end point for corners).