realsense viewer output into fullscreen of modify example code to have set depth map
using realsense 435 and raspberry pi 4b - output to hdmi screen
i really hope somebody can help ... ive got a requirement to just have the output of the depth cam (435) to a fullscreen for interpretation by humans .. no ai or pointcloud required as yet ...
i can modify the examples so that they open up in 1920x1080 windows (as close to a 'fullscreen' as i can manage for the time being (although if you could help with that id be grateful) ...
BUT
the examples out put what seem to be a sort of realtime variable depth map ... meaning .. that the colour gradient seems to change with regard to what is closest to the camera at the time rather than to any specific set depth ... sorry if that makes no sense .. let me explain further.
in the realsense-viewer i get a set depth map .. so if some thing is close its red and then it slowly gets blue as the distance gets futher .. and this is constant ... but as the realsense-viewer cant be opened in fullscreen without its GUI im using the examples ... but none of them have a 'fixed' depth graduation .. and they seem to adjust what is 'closest' according to what the camera is seeing ... i.e if looking at a living room then maybe the walls are blue and the chair near me is red .. BUT if i point the camera at a person and they 'fill' the view then the center of them will be red but their arms and edges will be blue ... as these are further from the centre of the lens..
to simplify the question ... how do i make a .cpp build example on the raspebrry pi that outputs the results i have set in the realsense-viewer ??
steve
-
Hi Steve You can toggle fullscreen view in the Viewer by pressing the F8 key on the keyboard instead of going to the Settings interface to do so. Once the change is made, it persists and remains active when the Viewer is next launched until toggled back to a windowed screen.
If you need to program your own fullscreen .cpp application though, I could not find an equivalent method for implementing a fullscreen mode with scripting. There may be scope for modifying the default fullscreen status of the Viewer program via the model-views.cpp file.
https://github.com/IntelRealSense/librealsense/blob/master/common/model-views.cpp#L2720
-
hi - thanks for the reply - - actually the fulscreen part is the least of my worries -
and when i say fulscreen - i mean without the controls/gui ... so just a window with the depth stream in it.
i can manage this so far by going into the .cpp of a particular example and changing the basic window setting .. then i can go into the 'build' folder and 'make' again . and it re-builds the examples - with my new settings ..
so thats great ..
what i CANT manage to do is find a way of getting the output that i have from the realsense-viewer to show up as a standalone window.
so im trying to modify one of the c++ examples (on the rasp pi 4) to work as i want
let me explain
the examples all have their own settings .. none of which i want - i want particular settings that i set in the realsense viewer ..
i can, in theory, save these as a .json file ... which is great ... but cant do anything with that file as far as using it to control the stream settings in an existing example ...
i managed to guess that their were numbered colourizer presets so i could change the colour sets ... by changing numbers in the examples and re-'making' them .. .but there must be a block of code i can use to just open a window up of a set size and have it display the stream based on the /json file in question ? ..
-
How I interpret your description above is that you would like to create a C++ program that is a standalone window that has no selectable options like the Viewer does (something more like rs-capture) but you would like to apply your own default settings taken from the Viewer to your program by using a json file exported from the Viewer.
If the above description is correct then it should be relatively straightforward to do so. You can load a custom json file into your own application to apply the settings in the file to it. Links to some examples of json file loading scripting for C++ can be found in the link below.
https://github.com/IntelRealSense/librealsense/issues/7322
You should be able to test this scripting by modifying an existing C++ example program.
-
hi - -thanks so much for getting back to me ..
im kinda melting down
ive been plugging away with realsense cam 435 on raspberry pi 4 .. and having followed MANY paths ive ALMOST achieved what i need to do ... but not quite ...
i have limited programming experience - - and started off using c# to do what i needed as it was a case of taking the examples and modifying them .. it took me a while to work out how to 'build' them again .. and i just got lucky if im honest .i then hit a wall and needed to follow examples which were in python ...
but i couldnt get the python examples to run .. which was a shame as i figured they would be easier to modify.
eventually i cracked it - realizing that the build process had put certain files into the wrong folder - so a copy and paste later and hey presto.
but i feel my luck is running out .. there's only so much searching the internet for bits of code and then blindly hacking them into the programs i can do.
i dont fully understand the structure -- and i am learning .. but not fast enough
ideally i just want a display from the camera in a set colour pallet within specified min and max depth ..
ive tried all i can to import and use a json file (created in realsense-viewer) but i just cant seem to leverage it .. not knowing exactly where to shoehorn the bits of code i find
so i then tried to see if there was maybe a way of just calling the functions i want ..
i decided id just put up with the set pallet presets (it would have been nice to apply a filter of my own but i have no idea how - id also like to apply the prost processing hole flter .. but that too is eluding me) and so i found a thing called clamping .. and then that led me to the realsense docs whch lists code snippets .. but because they are out of context i never seem to manage to get them in the right place or whatnot.
would you mind looking at my code (its a short program) and telling me what on earth im doing wrong ? .... totally understand if you dont accept .. but it would make a desperate and tired sole very happy ... i am in your hands - kind regards
the following does MOST of what i want .. it just starts up a window - streams the depth image and then resizes it to fill the window .. cool
so then i can only colourise it with presets - - ok .. not bad .. but ideally i want the colours the other way round so when something is close its red and when its far away its blue .. with the colours graduated between that min and max (kind of the reverse of JET
i need to be able to set the min and max distance for the depths .. i cant seem to do anything with the json file as there are too many lines of code in each example i see which means i cant just get a simple command and insert it somewhere obvious .. there's way more to it than that ... so i tracked down
__init__(self: pyrealsense2.threshold_filter, min_dist: float=0.15000000596046448, max_dist: float=4.0) → None
but i have no idea where to put that .. and when i try it throws up all manner of errors .. as there are clearly syntax issues in it but i am a beginner and i cant work out which bits to put where - for example - - im pretty sure that arrow symbol before 'none' is wrong .. but why is included in the page:
and why on earth cant it be shown in ANY example anywhere that i can find ..
really hope you can help .
losing my mind
steve
## 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
import datetimeimport json
data = json.load(open('Custom1.json', 'r'))
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
###config.enable_stream(rs.stream.depth, 848, 480, rs.format.z16, 60)
###config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)# Start streaming
cfg = pipeline.start(config)
dev = cfg.get_device()
depth_sensor = dev.first_depth_sensor()
depth_sensor.set_option(rs.option.visual_preset, 4)
iteration = 0;
preset = 1;
preset_name = '';try:
while True:# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
iteration = iteration + 0
if iteration > 100:
preset = preset + 0
iteration = 0
range = depth_sensor.get_option_range(rs.option.visual_preset)
preset = preset % range.max
depth_sensor.set_option(rs.option.visual_preset, preset)
preset_name = depth_sensor.get_option_value_description(rs.option.visual_preset, preset)
# Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())# Apply colormap on depth image (image must be converted to 8-bit per pixel first)
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, None, 0.5, 0), cv2.COLORMAP_RAINBOW)
# Stack both images horizontally - ive changed this to just the one image - - at some point id like to merge the colour image with it .. but not now
images = depth_colormap
###images = depth_image
#font = cv2.FONT_HERSHEY_SIMPLEX# Show images
cv2.namedWindow('RealSense', cv2.WINDOW_NORMAL)
cv2.resizeWindow('RealSense', 1920,1080)
cv2.imshow('RealSense', images)
key = cv2.waitKey(1)
# Press esc or 'q' to close the image window
if key & 0xFF == ord('q') or key == 27:
cv2.destroyAllWindows()
breakfinally:
# Stop streaming
pipeline.stop() -
as an aside - her's a classic example of what i keep finding - - for a start its old .. but also the last comments are ALMOST helpful .. but then leave me with sooo many questions ...
this modified example has the potential to use a json file if the last comments are to be believed - - but its indicative at best ... :S
## 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() config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) # Start streaming cfg = pipeline.start(config) dev = cfg.get_device() depth_sensor = dev.first_depth_sensor() depth_sensor.set_option(rs.option.visual_preset, 4) iteration = 0; preset = 0; preset_name = ''; try: while True: # Wait for a coherent pair of frames: depth and color frames = pipeline.wait_for_frames() depth_frame = frames.get_depth_frame() color_frame = frames.get_color_frame() iteration = iteration + 1 if iteration > 100: preset = preset + 1 iteration = 0 range = depth_sensor.get_option_range(rs.option.visual_preset) preset = preset % range.max depth_sensor.set_option(rs.option.visual_preset, preset) preset_name = depth_sensor.get_option_value_description(rs.option.visual_preset, preset) # Convert images to numpy arrays depth_image = np.asanyarray(depth_frame.get_data()) color_image = np.asanyarray(color_frame.get_data()) # Apply colormap on depth image (image must be converted to 8-bit per pixel first) depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, None, 0.5, 0), cv2.COLORMAP_JET) # Stack both images horizontally images = np.hstack((color_image, depth_colormap)) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(images, preset_name,(60,80), font, 4,(255,255,255),2,cv2.LINE_AA) # Show images cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE) cv2.imshow('RealSense', images) cv2.waitKey(1) finally: # Stop streaming pipeline.stop()
In addition,
load_jsonshould also work. After reviewing your code, I had two ideas:- Instead of using
find_device_that_supports_advanced_mode, get the device from pipeline configuration after start:
cfg = pipeline.start(config) dev = cfg.get_device()
- Perform
load_jsonafter you start streaming
- Instead of using
-
I am not aware of a means to grade depth from red to blue instead of blue to red, so if you are trying to reverse the color scheme with code and it is not working then it is not necessarily a problem with your code. Depth can though be represented in monochrome as dark in the short range and light in the far range using the Black to White color scheme.
A RealSense user created a C# implementation of the Threshold Filter in the link below that you can use as a reference.
-
thanks for getting back
i am not so focused on the color issue - i realise thats a lot to ask.
but the depth parameters ARE my focus and the example you provide is C# ... i am unable to translate this into any meaningful python
which is what i am now working with.
any other ideas ?
steve
-
If you are now using Python, some recently contributed example code for setting colorization options is here:
https://github.com/IntelRealSense/librealsense/issues/8299#issuecomment-773833234
In regard to setting the threshold filter with Python, there isn't a standalone script to refer to that I know of like there is for C++ and C#. The best references that I am aware of are in the links below.
https://github.com/IntelRealSense/librealsense/commit/84f78c9888a4e2ae48100e52df2e91c5ab82e683
Please sign in to leave a comment.
Comments
8 comments