Challenge

Project 4

!pip install opencv-python

import cv2 as cv
from matplotlib import pyplot as plt
# Here we are importing the requried libraries for computing the disparity map
# Opencv is a library of Python bindings designed to solve computer vision problems

imgL = cv.imread('left.jfif', 0)
imgR = cv.imread('right.jfif', 0)
#Reading the two images using CV

left1 = cv.resize(imgL, (1050, 1610))
right1 = cv.resize(imgR, (1050, 1610))
#The functions requires that the two images need to be of the same dimensions. Hence we are resizing the images

stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
#StereoBM class calculates a disparity map for a pair of rectified stereo images.
#Various combinations of a stereo camera setup are possible depending on the type of camera sensors, the distance between the cameras, and many other factors.
disparity = stereo.compute(left1,right1)
plt.imshow(disparity,'gray')
plt.show()

cv2.imwrite('result.png',disparity)

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.