Items with no label
3335 Discussions

How to show d435 IR image using python wrapper pyrealsense2?

NCacc
Beginner
5,539 Views

Hi, 

I'm currently working with a d435 and I want to display IR images (both left and right but for the moments just focus on one), following my code:

import pyrealsense2 as rs import numpy as np import cv2   # We want the points object to be persistent so we can display the #last cloud when a frame drops points = rs.points()   # Create a pipeline pipeline = rs.pipeline() #Create a config and configure the pipeline to stream config = rs.config() config.enable_stream(rs.stream.infrared, 1, 1280, 720, rs.format.y8, 30) # Start streaming profile = pipeline.start(config)   # Streaming loop try: while True: # Get frameset of color and depth frames = pipeline.wait_for_frames() ir1_frame = frames.get_infrared_frame(1) # Left IR Camera, it allows 1, 2 or no input image = np.asanyarray(ir1_frame) cv2.namedWindow('IR Example', cv2.WINDOW_AUTOSIZE) cv2.imshow('IR Example', image) key = cv2.waitKey(1) # Press esc or 'q' to close the image window if key & 0xFF == ord('q') or key == 27: cv2.destroyAllWindows() break finally: pipeline.stop()

everything works fine till the line:

cv2.imshow('IR Example', image)

I get the error:

TypeError: mat data type = 17 is not supported

so, my question is: how can I display IR images (using cv2 or matplotlib or whatever)?

Hope I was clear since this is my first question.

Cheers

 

0 Kudos
4 Replies
MartyG
Honored Contributor III
4,088 Views

The link below has a short, simple script for getting the infrared frame with Pyrealsense2.

 

https://github.com/IntelRealSense/librealsense/issues/958

0 Kudos
NCacc
Beginner
4,088 Views

thank you for the quick reply, but I'm already able to get the infrared frame, what i want to do is to display it on the screen.

Basically what a really want is the IR stream as a matrix and not as a pyrealsense.video_frame object in order to do further manipulations.

0 Kudos
NCacc
Beginner
4,088 Views

Actually i just solved my problem, i just substituted this line:

image = np.asanyarray(ir1_frame)

with this one:

image = np.asanyarray(ir1_frame.get_data())

 

0 Kudos
MartyG
Honored Contributor III
4,088 Views

I'm very glad you found a solution! :)

0 Kudos
Reply