Reputation: 100
I work on a project that I need the focal length to calculate the distance from the image. so is there any way to get is automatically form camera properties
Upvotes: 5
Views: 16707
Reputation: 2082
The proper way is to do camera calibration which is not easy but well documented. https://learnopencv.com/camera-calibration-using-opencv/
In the past I have used a desktop-application by BoofCV. Tutorial Camera Calibration - BoofCV
The tutorial will guide you step by step. It involves:
Downloading their app. printing a checkerboard and sticking it on a hard surface which is fun. Following the calibration process. Remember: this has to be done only once (for each camera).
Upvotes: 2
Reputation: 1715
You can calibrate your camera using OpenCV. See this tutorial for details. As a result you'll get the camera matrix in the form of
fx 0 cx
0 fy cy
0 0 1
where:
fx
, fy
focal length of the camera in x and y direction in pixels
cx
, cy
principal point (the point that all rays converge) coordinates in pixels
then if you know the physical diameters of the sensor you can call calibrationMatrixValues
function to get focal length of the camera in real world units (e.g. millimeters).
Upvotes: 5