title: Why does my code not give a proper disp map in opencv2 for stereo cam measurement?
body: <p>I'm working on stereo camera distance measurement for a school project, however my disp map does not seem to be working. I have no idea what the problem is and I would appreciate some help!
  <a href="https://i.stack.imgur.com/aLw74.png" rel="nofollow noreferrer">My disp map</a></p>
  <p>It should show the disparity of a classroom, however I get some random dots. I should also mention that this is video, not an image.</p>
  <pre><code>CamL = cv2.VideoCapture(1)
  
  while True:
      # Start Reading Camera images
      retR, frameR = CamR.read()
      retL, frameL = CamL.read()
  
      cv2.imshow(&quot;frameL&quot;, frameL)
      cv2.imshow(&quot;frameR&quot;, frameR)
  
      # Rectify the images on rotation and alignement
      Left_nice = cv2.remap(frameL, Left_Stereo_Map[0], Left_Stereo_Map[1], cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT,
                            0)  # Rectify the image using the kalibration parameters founds during the initialisation
      Right_nice = cv2.remap(frameR, Right_Stereo_Map[0], Right_Stereo_Map[1], cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT, 0)
  
      ##    # Draw Red lines
      for line in range(0, int(Right_nice.shape[0]/20)): # Draw the Lines on the images Then numer of line is defines by the image Size/20
              Left_nice[line*20,:]= (0,0,255)
              Right_nice[line*20,:]= (0,0,255)
  
      for line in range(0, int(frameR.shape[0]/20)): # Draw the Lines on the images Then numer of line is defines by the image Size/20
             frameL[line*20,:]= (0,255,0)
             frameR[line*20,:]= (0,255,0)
  
      # Show the Undistorted images
      #cv2.imshow('Both Images', np.hstack([Left_nice, Right_nice]))
      #cv2.imshow('Normal', np.hstack([frameL, frameR]))
  
      #cv2.imshow(&quot;rightnice&quot;, Right_nice)
      #cv2.imshow(&quot;leftnice&quot;, Left_nice)
      # Convert from color(BGR) to gray
      grayR = cv2.cvtColor(Right_nice, cv2.COLOR_BGR2GRAY)
      grayL = cv2.cvtColor(Left_nice, cv2.COLOR_BGR2GRAY)
  
      #cv2.imshow(&quot;grayR&quot;, grayR)
      #cv2.imshow(&quot;grayL&quot;, grayL)
  
      # Compute the 2 images for the Depth_image
      disp = stereo.compute(grayL, grayR)  #.astype(np.float32)/ 16
  
      dispL = disp
      dispR = stereoR.compute(grayR, grayL)
      dispL = np.int16(dispL)
      dispR = np.int16(dispR)
  
      # Using the WLS filter
      filteredImg = wls_filter.filter(dispL, grayL, None, dispR)
      filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
      filteredImg = np.uint8(filteredImg)
      cv2.imshow('Disparity Map', filteredImg)
      disp = ((disp.astype(
          np.float32) / 16) - min_disp) / num_disp  # Calculation allowing us to have 0 for the most distant object able to detect
      cv2.imshow(&quot;disp&quot;, disp)
       # Resize the image for faster executions
      dispR= cv2.resize(disp,None,fx=0.7, fy=0.7, interpolation = cv2.INTER_AREA)
  
      # Filtering the Results with a closing filter
      closing = cv2.morphologyEx(disp, cv2.MORPH_CLOSE,
                                 kernel)  # Apply an morphological filter for closing little &quot;black&quot; holes in the picture(Remove noise)
  
      # Colors map
      dispc = (closing - closing.min()) * 255
      dispC = dispc.astype(
          np.uint8)  # Convert the type of the matrix from float32 to uint8, this way you can show the results with the function cv2.imshow()
      disp_Color = cv2.applyColorMap(dispC, cv2.COLORMAP_OCEAN)  # Change the Color of the Picture into an Ocean Color_Map
      filt_Color = cv2.applyColorMap(filteredImg, cv2.COLORMAP_OCEAN)
  
      # Show the result for the Depth_image
      cv2.imshow('Disparity', disp)
      cv2.imshow('Closing',closing)
      cv2.imshow('Color Depth',disp_Color)
      cv2.imshow('Filtered Color Depth', filt_Color)
  
      # Mouse click
      cv2.setMouseCallback(&quot;Filtered Color Depth&quot;, coords_mouse_disp, filt_Color)
  
      # End the Programme
      if cv2.waitKey(1) &amp; 0xFF == ord(' '):
          break
  
  # Save excel
  ##wb.save(&quot;data4.xlsx&quot;)
  
  # Release the Cameras
  CamR.release()
  CamL.release()
  </code></pre>