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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With