Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Both input images must have CV_8UC1 in function error

I plan to do a stereo image from the tutorial here, but the compiler reports errors with cv2.createStereoBM, I found out it was the problem of OpenCV version.

I followed this to change cv2.createStereoBM into cv2.StereoBM. It works well, but the following code:

disparity = stereo.compute(frame0,frame1)

shows error:

Both input images must have CV_8UC1 in function cv::findStereoCorrespondenceBM

Can anyone help me with this?

The environment is Python 2.7, OpenCV 2.4.11.

My code is:

cap0 = cv2.VideoCapture(0)
cap1 = cv2.VideoCapture(1)
while (cap0.isOpened() and cap1.isOpened()):
    ret0, frame0 = cap0.read()
    frame0_new=cv2.cvtColor(frame0, cv2.COLOR_BGR2GRAY)

    ret1, frame1 = cap1.read()
    frame1_new=cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)


    stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET,ndisparities=16, SADWindowSize=15)

    disparity = stereo.compute(frame0,frame1)
like image 222
Condo_programmer Avatar asked Mar 17 '16 17:03

Condo_programmer


1 Answers

You should use your frames converted to single channel, i.e. of type CV_8UC1:

disparity = stereo.compute(frame0_new, frame1_new)
like image 51
Miki Avatar answered Nov 18 '22 14:11

Miki