简体   繁体   中英

How to get camera focal length with OpenCV

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

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).

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 (eg millimeters).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM