Both input images must have CV_8UC1 in function error
<p>I plan to do a stereo image from the tutorial <a href="https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html#py-depthmap" rel="nofollow noreferrer">here</a>, but the compiler reports errors with <code>cv2.createStereoBM</code>, I found out it was the problem of OpenCV version. </p>

<p>I followed <a href="https://stackoverflow.com/questions/21702945/attributeerror-module-object-has-no-attribute">this</a> to change <code>cv2.createStereoBM</code> into <code>cv2.StereoBM</code>. It works well, but the following code:</p>

<pre><code>disparity = stereo.compute(frame0,frame1)
</code></pre>

<p>shows error:</p>

<blockquote>
  <p>Both input images must have CV_8UC1 in function cv::findStereoCorrespondenceBM</p>
</blockquote>

<p>Can anyone help me with this? </p>

<p>The environment is Python 2.7, OpenCV 2.4.11.</p>

<p>My code is:</p>

<pre><code>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)
</code></pre>