librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

Recording both infrared streams via the Python wrapper

Open realsens01 opened this issue 7 years ago • 9 comments

Required Info
Camera Model D435
Firmware Version 5.11.1
Operating System & Version Windows 10
Kernel Version (Linux Only) NA
Platform PC
SDK Version 2.20.0
Language Python
Segment NA

Issue Description

Using the Python API, I would like to record a bag file that contains both IR streams. I thought this would be straightforward, based on prior experience, but something is going wrong. My code is very simple: it uses a config object to enable the streams that I'm interested in recording from, and then passes the config to pipeline.start. It works, in general, but fails when I try to add a second IR stream (telling me that there is a problem enabling a stream). What can I do?

Some notes:

  • The API How-To suggests using enable_stream with stream indices 0 and 1. I tried that (using Python, not C++), and it returned the same error.
  • A reply to another user question suggests using enable_stream with stream indices 1 and 2. This also didn't work. The only stream index that works is 1.
  • Recording the IR streams with Realsense Viewer worked.
  • rs2.context().devices[0].sensors[0].profiles contains profiles for Infrared(1) and depth only. There are no other infrared streams. I'm not sure if this is relevant.

realsens01 avatar Apr 30 '19 19:04 realsens01

@realsens01 , this commonly occurs when the device is enumerated as USB2. As with USB2 the device is designed to provide only a subset of streaming modes. Run realsense-viewer or rs-enumerate-devices -s to check the actual connection type details.

The other less common reason is that device's "advanced mode" is being turned off. Both tools will display the "advanced mode" status, with the Viewer being also able to toggle it if necessary.

ev-mp avatar Apr 30 '19 23:04 ev-mp

Thanks @ev-mp . I used Realsense Viewer to confirm that the device is recognized as USB 3.0 and that advanced mode is enabled. The problem persists.

Here is some sample output in an IPython terminal:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pyrealsense2 as rs2

In [2]: device = rs2.context().devices[0]
   ...: serial_number = device.get_info(rs2.camera_info.serial_number)
   ...: config = rs2.config()
   ...: config.enable_device(serial_number)
   ...: config.enable_stream(rs2.stream.infrared, 0)
   ...: config.enable_stream(rs2.stream.infrared, 1)
   ...: pipeline = rs2.pipeline()
   ...: pipeline.start(config)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-01583c32427f> in <module>()
      9 pipeline = rs2.pipeline()
---> 10 pipeline.start(config)

RuntimeError: Config couldn't configure all streams

In [4]: device.get_info(rs2.camera_info.advanced_mode)
Out[4]: 'YES'

I got the same result using indices 1 and 2, instead of 0 and 1. Fwiw, here are the available stream profiles:

In [5]: device.sensors[0].profiles
Out[5]:
[<pyrealsense2.video_stream_profile: Infrared(1) 1280x720 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 1280x720 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 1280x720 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 848x480 @ 90fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 848x480 @ 60fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 848x480 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 848x480 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 848x480 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x480 @ 90fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x480 @ 60fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x480 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x480 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x480 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x360 @ 90fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x360 @ 60fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x360 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x360 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 640x360 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 480x270 @ 90fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 480x270 @ 60fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 480x270 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 480x270 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 480x270 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 424x240 @ 90fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 424x240 @ 60fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 424x240 @ 30fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 424x240 @ 15fps Y8>,
 <pyrealsense2.video_stream_profile: Infrared(1) 424x240 @ 6fps Y8>,
 <pyrealsense2.video_stream_profile: Depth(0) 1280x720 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 1280x720 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 1280x720 @ 6fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 848x480 @ 90fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 848x480 @ 60fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 848x480 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 848x480 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 848x480 @ 6fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x480 @ 90fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x480 @ 60fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x480 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x480 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x480 @ 6fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x360 @ 90fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x360 @ 60fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x360 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x360 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 640x360 @ 6fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 480x270 @ 90fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 480x270 @ 60fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 480x270 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 480x270 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 480x270 @ 6fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 424x240 @ 90fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 424x240 @ 60fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 424x240 @ 30fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 424x240 @ 15fps Z16>,
 <pyrealsense2.video_stream_profile: Depth(0) 424x240 @ 6fps Z16>]

realsens01 avatar May 02 '19 21:05 realsens01

This issue might be the same as https://github.com/IntelRealSense/librealsense/issues/3885

realsens01 avatar May 02 '19 21:05 realsens01

Any suggestions @RealSenseCustomerSupport? I'd really like to be recording this data.

realsens01 avatar Jun 06 '19 19:06 realsens01


From your video profile output it does looks like the Advanced mode is not enabled. Is the IR 2 available via realsense-viewer?

@RealSenseCustomerSupport

  • I confirmed that Advanced Mode is enabled, via Realsense Viewer.
  • Both IR streams are available in Realsense Viewer

Both of these things were already stated in this short thread.

EDIT: What about the profile output tells you that Advanced Mode is not enabled? That might be helpful information.

realsens01 avatar Jun 19 '19 23:06 realsens01

@RealSenseCustomerSupport : Why would you close this? This is the 3rd issue that I've had that you've closed without resolving.

realsens01 avatar Jul 03 '19 20:07 realsens01

I stumbled across the following that seems to work. The upshot is that the IR cameras are numbered 1 and 2, not 0 and 1 (in the calls to enable_streams).

#%% imports
import pyrealsense2 as rs

#%% configure
ctx = rs.context()
device = ctx.devices[0]
serial_number = device.get_info(rs.camera_info.serial_number)
config = rs.config()
config.enable_device(serial_number)

#%% enable streams
config.enable_stream(rs.stream.infrared, 1, 1280,720, rs.format.y8, 6)
config.enable_stream(rs.stream.infrared, 2, 1280,720, rs.format.y8, 6)

#%% run pipeline
pipeline = rs.pipeline()
profile = pipeline.start(config)

bwilfley avatar Dec 29 '19 23:12 bwilfley

I stumbled across the following that seems to work. The upshot is that the IR cameras are numbered 1 and 2, not 0 and 1 (in the calls to enable_streams).

#%% imports
import pyrealsense2 as rs

#%% configure
ctx = rs.context()
device = ctx.devices[0]
serial_number = device.get_info(rs.camera_info.serial_number)
config = rs.config()
config.enable_device(serial_number)

#%% enable streams
config.enable_stream(rs.stream.infrared, 1, 1280,720, rs.format.y8, 6)
config.enable_stream(rs.stream.infrared, 2, 1280,720, rs.format.y8, 6)

#%% run pipeline
pipeline = rs.pipeline()
profile = pipeline.start(config)

Here is an explicit way to configure color, depth and IR streams specifically for D455

conf.enable_stream(stream_type=rs.stream.color, width = 1280, height = 720, format = rs.format.rgb8, framerate = 30)
conf.enable_stream(stream_type=rs.stream.depth, width = 848, height = 480, format = rs.format.z16,framerate = 30)
conf.enable_stream(stream_type=rs.stream.infrared, stream_index = 1, width = 848, height = 480, format = rs.format.y8,framerate = 30)
conf.enable_stream(stream_type=rs.stream.infrared,stream_index = 2, width = 848, height = 480, format = rs.format.y8,framerate = 30)

vstadnytskyi-FDA avatar Apr 04 '23 00:04 vstadnytskyi-FDA