The objective is to reconstruct a 3D equivalent, given the pair of images.
git clone https://github.com/FlagArihant2000/stereo.git
cd stereo
- Execute
python3 stereo.py
- Result is obtained in
stereo.ply
, which can be viewed using MeshLab, Open3D, or any other related software or library to view point clouds.
- Acquire left and right image.
- Feature Extraction using SIFT.
- Feature Matching using Brute Force KNN and rejecting outliers.
- Finding essential matrix of point correspondance and reject outliers using RANSAC.
- Recover Pose.
- Perform stereo rectification using the recovered poses. The intrinsic camera matrix and distortion coefficients are known and present in
calib.txt
. - Calculate the Disparity map with Semi Global Block Matching (SGBM). Number of disparities are mentioned in
calib.txt
, whereas the other parmeter are taken in the code itself. - Finding left and right disparity map, followed by performing Weighted Least Square (WLS Filtering). The filtered image is considered as the final disparity map.
- Defining reprojection matrix Q to get the 3D equivalent of disparity matrix.
- Generating the point cloud, which is stored in
stereo.ply
.
- Disparity Map with SGBM
max_disparity = 199
min_disparity = 23
num_disparities = max_disparity - min_disparity
window_size = 5
stereo = cv2.StereoSGBM_create(minDisparity = min_disparity, numDisparities = num_disparities, blockSize = 5, uniquenessRatio = 5, speckleWindowSize = 5, speckleRange = 5, disp12MaxDiff = 2, P1 = 8*3*window_size**2, P2 = 32*3*window_size**2)
- WLS Filter
lamb = 8000
sig = 1.5
visual_multiplier = 1.0
wls_filter = cv2.ximgproc.createDisparityWLSFilter(stereo)
wls_filter.setLambda(lamb)
wls_filter.setSigmaColor(sig)
My Point Cloud: Click \ Ground Truth Point Cloud: Click
NOTE: Check my repository (Link) for multiview stereo.