2 color frames to display different data?
I am trying to show the same color frame capture twice but have each window display different information. I am using np.hstack to line up the two color captures horizontally, and I've declared two different kinds of color_image variables, but it ends up showing the same thing twice when running the program.
coord_color_image = np.asarray(frame[rs.stream.color].get_data())
box_color_image = np.asarray(frame[rs.stream.color].get_data())
Any help would be immensely appreciated. Is it possible to even do this? Did anyone try to do this successfully?
-
Hi Edenclaire8 If I were creating a similar program myself then I would try to adapt the RealSense SDK's Python example program opencv_viewer_example.py which uses hstack to display the depth and color stream. I edited it in the script below to only use the color stream and store the color frame in two separate numpy arrays, like you did - coord_color_image and box_color_image.
However, it is still going to show identical color frames in both views because the data is coming from the same color stream. For them to look different, you would likely have to perform some kind of unique processing work on the data in each individual numpy array before the two arrays are arranged onscreen by hstack.
## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
###############################################
## Open CV and Numpy integration ##
###############################################
import pyrealsense2 as rs
import numpy as np
import cv2
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
# Get device product line for setting a supporting resolution
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))
found_rgb = False
for s in device.sensors:
if s.get_info(rs.camera_info.name) == 'RGB Camera':
found_rgb = True
break
if not found_rgb:
print("The demo requires Depth camera with Color sensor")
exit(0)
if device_product_line == 'L500':
config.enable_stream(rs.stream.color, 960, 540, rs.format.bgr8, 30)
else:
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
# Start streaming
pipeline.start(config)
try:
while True:
# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
if not color_frame:
continue
# Convert images to numpy arrays
coord_color_image = np.asanyarray(color_frame.get_data())
box_color_image = np.asanyarray(color_frame.get_data())
images = np.hstack((coord_color_image, box_color_image))
# Show images
cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
cv2.imshow('RealSense', images)
cv2.waitKey(1)
finally:
# Stop streaming
pipeline.stop() -
If you wanted to have identical color frames but overlay different text on each image then using OpenCV's cv2.putText function may achieve your goal.
https://www.tutorialspoint.com/display-text-on-an-opencv-window-by-using-the-function-puttext
-
Thank you for the advice.
1.) So I tried making two separate windows (using OpenCV's cv2.namedWindow) where one shows world coordinates and the other shows a bounding box around an object. (This idea was borrowed from Intel's box_dimensioner_multicam.py.) In the cases where lines are being drawn to make a box, I changed color_image to box_color_image, and I changed color_image to coord_color_image for the window that I only want to have show the world coordinates. (I changed these around Lines 190 - 200 on measurement_task.py.) Whether it's in two separate windows or one big window stacked horizontally, the same thing (the bounding box and measurements) shows up twice :/ Am I missing something?
2.) Also, in that same demo (and other Intel Python tutorials), when running the window, at the very bottom there is a display for the current X and Y locations for the mouse, as well as the RGB information on a specific pixel. Is that code coming from the Realsense SDK or OpenCV?
-
1. On line 200 of measurement_task.py that is responsible for displaying the text using putText, does changing 'color_image' to 'coord_color_image' cause the text to only appear on the coord_color_image panel?
cv2.putText(coord_color_image, box_info, (50,50), cv2.FONT_HERSHEY_PLAIN, 2, (0,255,0) )
2. If the coordinate display at the bottom of the screen appears on multiple Python example programs then it sounds like it is not the RealSense program that is generating it.
Please sign in to leave a comment.
Comments
4 comments