IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.62k stars 4.83k forks source link

Getting / Setting ROI on MacOS 10.15.2 causing freeze #5562

Closed compscidr closed 4 years ago

compscidr commented 4 years ago

Have checked out for other issues, and looked through lots of example code.

Required Info
Camera Model { D435 and D415 }
Firmware Version 05.11.15.00 and 05.12.01.00
Operating System & Version {MacOS 10.15.2}
Kernel Version (Linux Only) 19.2.0
Platform MacOS 10.15.2
SDK Version { 2.31.0 (development branch) }
Language { Python }
Segment { Robot }

Issue Description

Having problems setting and getting the ROI from the RGB and Depth sensors. The code is working fine when I run it on Ubuntu, however with MacOS, it freezes at the lines where I try to get or set the sensor ROI. Doesn't seem to matter if I only do one sensor, or the other, or both.

Here is the relevant code lines stripped from a larger script:

import pyrealsense2 as rs

ctx = rs.context()
devices = {d.get_info(rs.camera_info.serial_number): d for d in ctx.query_devices()}
device_id, device = devices.popitem()
rsconfig = rs.config()
rsconfig.enable_device(str(device_id))
pipe = rs.pipeline(ctx)
profile = pipe.start(rsconfig)

for sensor in device.sensors:
    if not sensor.is_depth_sensor():
        print("RGB SENSOR")
        rgb_roi_sensor = sensor.as_roi_sensor()
        rgb_roi = rgb_roi_sensor.get_region_of_interest()
    else:
        print("DEPTH SENSOR")
        depth_roi_sensor = sensor.as_roi_sensor()
        depth_roi = depth_roi_sensor.get_region_of_interest()

print("GOT HERE")

Just curious if this is because not all the stuff for macOS is done yet, or if there is a bug? If there is a bug, if someone can point into the right direction, I don't mind submitting a PR.

compscidr commented 4 years ago

Was playing around with this a bit more today - if you get or set the ROI before you start the pipeline it doesn't freeze, but if you try to set the ROI after the pipeline has started, it freezes.

dorodnic commented 4 years ago

Hi @compscidr I'm having trouble reproducing this... Running MacOS 10.13.6 with 5.12 firmware and 2.31 SDK and the Viewer. Do you see this only in python or also when trying to use this functionality in Viewer / C++?

compscidr commented 4 years ago

So far only on python. Will try today with C++. Viewer seems to work fine, so I assume c++ will as well.

dorodnic commented 4 years ago

I'll try to check python as well... Perhaps something to do with python global lock... :/

compscidr commented 4 years ago

Confirmed it is not occurring in c++

RealSenseCustomerSupport commented 4 years ago

Please try to upgrade to new version. The following code works in my laptop (macOS 10.15.3, python3)

! /usr/bin/python3

import pyrealsense2 as rs2 import time

ctx = rs2.context() pipe = rs2.pipeline(ctx)

pp = pipe.start()

for sensor in pp.get_device().sensors: if sensor.is_depth_sensor(): print("DEPTH SENSOR") else: print("RGB SENSOR") roi_sensor = sensor.as_roi_sensor() print(roi_sensor) time.sleep(0.1) roi = roi_sensor.get_region_of_interest() time.sleep(0.1) print("BEFORE SET (",roi.min_x, ", ", roi.min_y, ") - (", roi.max_x, ", ", roi.max_y, ")") roi.min_x = roi.min_y = 100 roi.max_x = roi.max_y = 200 roi_sensor.set_region_of_interest(roi) time.sleep(0.1) roi = roi_sensor.get_region_of_interest() time.sleep(0.1) print("AFTER SET (",roi.min_x, ", ", roi.min_y, ") - (", roi.max_x, ", ", roi.max_y, ")") time.sleep(0.1)

pipe.stop()

compscidr commented 4 years ago

Just tried it, seems to be working - had to modify it a bit because it start the pipeline without a config - for future reference for anyone else - this is what I had to get it to work:

#! /usr/bin/python3
import pyrealsense2 as rs2
import time

ctx = rs2.context()
pipe = rs2.pipeline(ctx)

devices = {d.get_info(rs2.camera_info.serial_number): d for d in ctx.query_devices()}
device_id, device = devices.popitem()

rsconfig = rs2.config()
rsconfig.enable_device(str(device_id))

rsconfig.enable_stream(rs2.stream.color, 1920, 1080, rs2.format.any, 30)
rsconfig.enable_stream(rs2.stream.depth, 1280, 720, rs2.format.any, 30)
rsconfig.enable_stream(rs2.stream.infrared, 1, 1280, 720, rs2.format.any, 30)
rsconfig.enable_stream(rs2.stream.infrared, 2, 1280, 720, rs2.format.any, 30)

pp = pipe.start(rsconfig)

for sensor in pp.get_device().sensors:
    if sensor.is_depth_sensor():
        print("DEPTH SENSOR")
    else:
        print("RGB SENSOR")
    roi_sensor = sensor.as_roi_sensor()
    print(roi_sensor)

    time.sleep(0.1)
    roi = roi_sensor.get_region_of_interest()
    time.sleep(0.1)
    print("BEFORE SET (",roi.min_x, ", ", roi.min_y, ") - (", roi.max_x, ", ", roi.max_y, ")")
    roi.min_x = roi.min_y = 100
    roi.max_x = roi.max_y = 200
    roi_sensor.set_region_of_interest(roi)
    time.sleep(0.1)
    roi = roi_sensor.get_region_of_interest()
    time.sleep(0.1)
    print("AFTER SET (",roi.min_x, ", ", roi.min_y, ") - (", roi.max_x, ", ", roi.max_y, ")")
    time.sleep(0.1)

pipe.stop()

Thanks for the help!