Depth map shows everything grey! OpenCV- Python [closed]

asked 2018-06-06 09:02:08 -0600

Hello! My code:

import cv2
import numpy as np

imgL = cv2.imread('Blender_Suzanne1.jpg')
img1 = cv2.cvtColor(imgL, cv2.COLOR_BGR2GRAY)
imgR = cv2.imread('Blender_Suzanne2.jpg')
img2 = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY)

stereo = cv2.StereoBM_create(numDisparities = 16, blockSize = 17)
disparity = stereo.compute(img2, img1)

cv2.imshow('DepthMap', disparity)
cv2.waitKey()
cv2.destroyAllWindows()

When I run it, I see a window which is all grey? I think it is wrong. I used this code from the OpenCV docs website. Can anyone help?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by iamnirbhay
close date 2018-06-06 10:16:23.037221

Comments

depth maps are CV_16U [0..0xffff]. you probably have to filter it a bit, like subtract some offset, scale it, convert to CV_8U to see the disparity properly

berak gravatar imageberak ( 2018-06-06 09:50:10 -0600 )edit

But this is converted to Gray form. i.e. CV_8U right? or How do you propose changes?

iamnirbhay gravatar imageiamnirbhay ( 2018-06-06 09:53:22 -0600 )edit

the input, yes, but you're looking at the disparity image, which needs some treatment.

berak gravatar imageberak ( 2018-06-06 09:57:20 -0600 )edit

stereo_match.cpp (from the samples) has a line like:

        disp.convertTo(disp8, CV_8U, 255/(numberOfDisparities*16.));

also note, that the python tuts/samples use matplotlib for displaying, which might handle things differently

berak gravatar imageberak ( 2018-06-06 10:01:04 -0600 )edit
1

Thanks. I posted the docs code as it is i.e. with matplotlib and it finally showed something. I guess that must have something to do with the correct from to display.

iamnirbhay gravatar imageiamnirbhay ( 2018-06-06 10:12:51 -0600 )edit