Ask Your Question

Revision history [back]

imgL = cv.imread('left_image_path',0)  
imgR = cv.imread('right_image_path',0)

stereo = cv.StereoBM_create(numDisparities=32, blockSize=15)
disparity = stereo.compute(imgL,imgR)

vdisp = np.zeros((disparity.shape[0],np.amax(disparity)))

for x in range(0, disparity.shape[0]):
    for y in range(0, disparity.shape[1]):
        if disparity[x, y] > 0:
            vdisp[x, disparity[x,y]-1] += 1

edges = cv.Canny(vdisp.astype(np.uint8),0,10,apertureSize = 3)
lines = cv.HoughLines(edges, 10, np.pi/90, 100)

for rho,theta in lines[0]:
    a = np.cos(theta)
    b = np.sin(theta)
    y1 = int(rho/b)
    x1 = int(rho/a)
    y2 = int((rho - (a*lines.shape[1]) )/b)
    x2 = int((rho - (b*lines.shape[0]) )/a)    
    cv.line(lines,(x1,y1),(x2,y2),(255,0,0),1)

This seems to be working.