Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object distance to camera, using opencv

I want to estimate the distance of an object to my camera. This must be using Opencv. I read that I have to use 2 cameras in stead of one and I found some code with Matlab, but I don't have any experience in it. Any help will be appreciated.

like image 821
Houssem Badri Avatar asked Mar 16 '26 01:03

Houssem Badri


1 Answers

Yes, It is definitely possible to calculate depth with two cameras using a simple pinhole camera model:

depth = bcm*fcm/(sensorWidthCm*disparity/(float)horizontalResolution);

Here, in order to find average disparity (horizontal pixel location difference of keypoints) you can use SurfDescriptorExtractor and to find match pairs, you can use BFMatcher as in the link: http://docs.opencv.org/doc/tutorials/features2d/feature_description/feature_description.html

fcm, bcm, sensorWidthCm, and horizontalResolution are all camera parameters: fcm is camera focal length, bcm is the separation of cameras, sensorWidthCm is camera sensor width, and horizontalResolution is pixel number in horizontal direction. In fact you do not separately need all these parameters. You just need to experiment with some known depth to find the ratio:bcm*fcm/sensorWidthCm Horizontal image resolution is already known during image capture.

like image 110
fatihk Avatar answered Mar 18 '26 15:03

fatihk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!