[Python] OpenCV error when trying to capture frames using a Pyrealsense camera

Discussão em 'Python' iniciado por Stack, Abril 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting this error in my terminal when trying to get streams from a pyrealsense camera.

    Error capturing frames: OpenCV(4.11.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\colormap.cpp:736: error: (-5:Bad argument) cv::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function 'cv::colormap::ColorMap::eek:perator ()'

    the code is as follows

    def get_frames(self): """Get frames from the camera""" try: self.log.debug("Waiting for frames...") self.frames = self.pipeline.wait_for_frames() depth_frame = self.frames.get_depth_frame() color_frame = self.frames.get_color_frame()

    # Check for valid frames
    if not depth_frame or not color_frame:
    return None, None, None

    #Convert images to numpy arrays for input to OpenCV
    depth_image = np.asanyarray(depth_frame.get_data())
    color_image = np.asanyarray(color_frame.get_data())

    # Apply colormap on depth image
    depth_colormap = cv2.normalize(depth_image, None, 0, 255, cv2.NORM_MINMAX)
    depth_colormap = np.uint8(depth_colormap)
    depth_colormap = cv2.applyColorMap(depth_colormap, cv2.COLORMAP_JET)

    combined_image = np.hstack((color_image, depth_colormap))
    return depth_image, color_image, combined_image

    except Exception as e:
    self.log.error(f"Error capturing frames: {e}")
    return None, None, None

    Continue reading...

Compartilhe esta Página