Skip to content

Commit

Permalink
SR306 demos fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nohayassin committed May 10, 2021
1 parent 5adce15 commit bc82331
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 31 deletions.
5 changes: 3 additions & 2 deletions examples/align/rs-align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ void render_slider(rect location, float* alpha, direction* dir);

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_COLOR);
std::string serial;
device_with_streams(RS2_STREAM_COLOR, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with RGB sensor";
return EXIT_SUCCESS;;
return EXIT_SUCCESS;
}

// Create and initialize GUI related objects
Expand Down
7 changes: 4 additions & 3 deletions examples/ar-advanced/rs-ar-advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ std::vector<uint8_t> bytes_from_raw_file(const std::string& filename);

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_POSE);
std::string serial;
device_with_streams(RS2_STREAM_POSE, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with POSE sensor";
return EXIT_SUCCESS;;
std::cerr << "Connect T26X and rerun the demo";
return EXIT_SUCCESS;
}
std::string out_map_filepath, in_map_filepath, default_filepath = "map.raw";
for (int c = 1; c < argc; ++c) {
Expand Down
5 changes: 2 additions & 3 deletions examples/example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void register_glfw_callbacks(window& app, glfw_state& app_state)
}

// Find devices with specified streams
std::string depth_with_stream_type_present(rs2_stream type)
void device_with_streams(rs2_stream type, std::string& out_serial)
{
rs2::context ctx;
for (auto dev : ctx.query_devices(RS2_PRODUCT_LINE_DEPTH))
Expand All @@ -1082,9 +1082,8 @@ std::string depth_with_stream_type_present(rs2_stream type)
for (auto profile : sensor.get_stream_profiles())
{
if (profile.stream_type() == type)
return dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
out_serial = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
}
}
}
return "";
}
5 changes: 3 additions & 2 deletions examples/measure/rs-measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ void render_simple_distance(const rs2::depth_frame& depth,

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_COLOR);
std::string serial;
device_with_streams(RS2_STREAM_COLOR, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with RGB sensor";
return EXIT_SUCCESS;;
return EXIT_SUCCESS;
}

// OpenGL textures for the color and depth frames
Expand Down
7 changes: 4 additions & 3 deletions examples/pose-and-image/rs-pose-and-image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_POSE);
std::string serial;
device_with_streams(RS2_STREAM_POSE, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with POSE sensor";
return EXIT_SUCCESS;;
std::cerr << "Connect T26X and rerun the demo";
return EXIT_SUCCESS;
}
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
Expand Down
7 changes: 4 additions & 3 deletions examples/pose-predict/rs-pose-predict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ rs2_pose predict_pose(rs2_pose & pose, float dt_s)

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_POSE);
std::string serial;
device_with_streams(RS2_STREAM_POSE, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with POSE sensor";
return EXIT_SUCCESS;;
std::cerr << "Connect T26X and rerun the demo";
return EXIT_SUCCESS;
}

// Declare RealSense pipeline, encapsulating the actual device and sensors
Expand Down
7 changes: 4 additions & 3 deletions examples/pose/rs-pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_POSE);
std::string serial;
device_with_streams(RS2_STREAM_POSE, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with POSE sensor";
return EXIT_SUCCESS;;
std::cerr << "Connect T26X and rerun the demo";
return EXIT_SUCCESS;
}

// Declare RealSense pipeline, encapsulating the actual device and sensors
Expand Down
7 changes: 4 additions & 3 deletions examples/trajectory/rs-trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ class split_screen_renderer
// In this example, we show how to track the camera's motion using a T265 device
int main(int argc, char * argv[]) try
{
auto serial = depth_with_stream_type_present(RS2_STREAM_POSE);
std::string serial;
device_with_streams(RS2_STREAM_POSE, serial);
if (serial.empty())
{
std::cerr << "The demo requires Realsense Depth camera with POSE sensor";
return EXIT_SUCCESS;;
std::cerr << "Connect T26X and rerun the demo";
return EXIT_SUCCESS;
}

// Initialize window for rendering
Expand Down
9 changes: 7 additions & 2 deletions wrappers/python/examples/align-depth2color.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Import OpenCV for easy image rendering
import cv2

context = rs.context()
# Create a pipeline
pipeline = rs.pipeline()

Expand All @@ -25,8 +26,12 @@
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_line = str(device.get_info(rs.camera_info.product_line))
device_product_id = str(device.get_info(rs.camera_info.product_id))
if device_product_id == "0AA3":
deviceList = context.query_devices()
dev = deviceList.front()
sensorsList = dev.query_sensors()
try:
next(s for s in sensorsList if s.get_info(rs.camera_info.name) == 'RGB Camera')
except Exception as e:
print("The connected device does not support RGB stream")
exit(0)

Expand Down
11 changes: 7 additions & 4 deletions wrappers/python/examples/opencv_pointcloud_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import cv2
import numpy as np
import pyrealsense2 as rs

context = rs.context()

class AppState:

Expand Down Expand Up @@ -71,11 +71,14 @@ def pivot(self):
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_id = str(device.get_info(rs.camera_info.product_id))
if device_product_id == "0AA3":
deviceList = context.query_devices()
dev = deviceList.front()
sensorsList = dev.query_sensors()
try:
next(s for s in sensorsList if s.get_info(rs.camera_info.name) == 'RGB Camera')
except Exception as e:
print("The connected device does not support RGB stream")
exit(0)

config.enable_stream(rs.stream.depth, rs.format.z16, 30)
config.enable_stream(rs.stream.color, rs.format.bgr8, 30)

Expand Down
10 changes: 7 additions & 3 deletions wrappers/python/examples/opencv_viewer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
context = rs.context()

# Get device product line for setting a supporting resolution
# And product id to skip SR306
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_line = str(device.get_info(rs.camera_info.product_line))
device_product_id = str(device.get_info(rs.camera_info.product_id))
if device_product_id == "0AA3":
deviceList = context.query_devices()
dev = deviceList.front()
sensorsList = dev.query_sensors()
try:
next(s for s in sensorsList if s.get_info(rs.camera_info.name) == 'RGB Camera')
except Exception as e:
print("The connected device does not support RGB stream")
exit(0)

Expand Down

0 comments on commit bc82331

Please sign in to comment.