Left and right images taken from stereo cameras calibrated in parallel. This code creates a depth map using these images.
- Identify a pixel (P) in the left image.
- Take the 3x3 area around it with P being the center.
- Find where this region corresponds in the right image. Cameras parallel to each other Since P is the center of the 3x3 region in the right image, where this region coincides. will have the same horizontal coordinate.
- Sum to calculate similarity of regions in left and right images. Use Squared Distance (SSD) . The SSD superimposes both regions and it is calculated by the sum of the squares of the difference of pixels.
- Calculate the depth according to section below.
disparity=x−x′=Bf/Z
x and x′ are the distance between points in image plane corresponding to the scene point 3D and their camera center. B is the distance between two cameras (which we know) and f is the focal length of camera (already known). So in short, the above equation says that the depth of a point in a scene is inversely proportional to the difference in distance of corresponding image points and their camera centers. So with this information, we can derive the depth of all pixels in an image.
Focal Length=10 | Focal Length=20 |
---|---|
Focal Length=30 | Focal Length=40 |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.