-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MATLAB file from SDK2.0/matlab/+realsense #9773
Comments
Hi @nchu-cha Thanks very much for your questions. 1 and 2. The files that you mention are part of the MATLAB wrapper's operating files and are not meant to be run as example programs. The scripts in the wrapper's file list that are examples that can be tried have the word example in their name. https://github.com/IntelRealSense/librealsense/tree/master/wrappers/matlab These include: advanced_mode_example.m If you wish to perform alignment in the MATLAB wrapper, the script created by a RealSense user in #3735 provides an example of doing so. 3 and 4. #3735 also demonstrates defining custom stream configurations with cfg instructions and obtaining intrinsics when alignment is being used. |
thanks for your apply, I had tried the measure in #3735, but I got some questions.
thank you |
2 and 3. The L515 does not support 1280x720 depth (the reference script was designed for a RealSense 400 Series camera). L515 supports a maximum 1024x768 resolution for depth. RGB supports 1920x1080 though.
|
A .raw file would not work with the rosbag_example program. It is expecting a bag format file, which is like a video recording of camera data instead of a static image. In the Viewer you can create a bag file by enabling streams in the RealSense Viewer and then left-clicking on the circular Record option beneath the camera's name in the Viewer's options side-panel. The Viewer will then record into the bag all streams that were enabled at the time that the Record option was activated. Clicking on the Record option again should stop the recording and you will then have a bag file that you can load into programs such as rosbag_example. You can also obtain pre-made sample bag files from the link below. https://github.com/IntelRealSense/librealsense/blob/master/doc/sample-data.md |
Can I used MATALB code to save a bag file? Because I want to do all the stuff on the MATLAB |
#6057 discusses creating a script in the MATLAB wrapper to record a bag file. |
I used the method in #6057 like the below to have a bag file Then I want to read the information in the bag file, but it can't open the file, can anyone help me to solve the problem? this is my MATLAB code: clc; clear all; close all; filepath = fullfile('D:\matlab_code\bag_file','testrecord.bag'); % Make Pipeline object to manage streaming |
Reading a bag file in the MATLAB wrapper involves a different process to recording one with enable_record_to_file. It is done with cfg.enable_device_from_file, as demonstrated in the rosbag_example.m script. After stopping the pipeline with pipe.stop(), you should be able to change to a different cfg configuration than the cfg.enable_record_to_file one that the script started with (i.e set the cfg.enable_device_from_file instruction instead). |
|
Yes, use cfg.enable_record_to_file() to create the bag and cfg.enable_device_from_file() to play it back. To obtain a complete, readable bag, the pipeline needs to be stopped so that the bag is indexed upon closure of the recording process. The SDK's C++ reference about record and playback recommends updating the device after closing recording to signify that a new pipeline is being used where playback will take place instead of record.
In regard to getting the distance, #6612 (comment) provides references for doing this in the MATLAB wrapper using depth.get_distance |
I had looked the #6057, but I still don't know how to solve the problem? this is my code: filepath = fullfile('D:\matlab_code\bag_file','20120919_test3.bag'); % Make Pipeline object to manage streaming
% Select depth frame
|
My MATLAB wrapper programming knowledge is limited though, so I do not know what the wrapper equivalent of
There was a recent discussion that talked about doing simultaneous streaming and recording using multithreading. I pointed the RealSense user in that case to the C++ multithreading script at #6865 Multithreading is not a simple subject though and I do not have knowledge about how it could be used in a MATLAB wrapper script. |
The information I currently needed are : 1. RGB image, 2. Depth image, 3. Depth distance (in Viewer is a RAW file), I need these three information when I capture the photo from theL515 camera. I need A bag file is because the RGB and DEPTH image can't align together, and the methods I found all said that the parameters in the bag file are required, so I tried to get a bag file and read the parameters in it. Now I can capture the depth image and get the bag file, so I start to capture the RGB image want to see the RGB image and the depth image. Is there an example for capture the RGB image? |
All stream types that have been defined with cfg instructions should be captured in the bag file if they are enabled at the time that recording begins. I researched your situation further and found a MATLAB script contributed by a RealSense user in #6763 (comment) that aligns depth and color in real-time and then generates a point cloud. Adapting this script may avoid the need to record a bag file if you only needed a bag for the purpose of performing alignment. |
What happens if you remove the % part of the line? depth_dis = depth_frame.get_distance(x,y); |
If you cannot make get_distance work, the real-world distance in meters can alternatively be achieved by multiplying the 16-bit uint16_t raw depth pixel value by the depth unit scale of the RealSense camera model being used (which is 0.001 meters by default on 400 Series cameras and 0.000250 on L515). If the SDK's Align processing block (align_to) is used then the SDK automatically adjusts the aligned image if depth and RGB are different resolutions. |
Sorry for I can't clearly describe my problem.
Can MATLAB directly generate the RAW file?
thank you |
#1485 discusses in detail how to write depth data in binary format, including how to approach the problem of doing so in the RealSense MATLAB wrapper. For example, one RealSense user in that discussion in #1485 (comment) wrote a script for saving the data as a .txt file that MATLAB could read. If you want to go even more directly than the MATLAB wrapper, the function imwrite in MATLAB itself offers the possibility of saving data in binary raw format, though it may not be the same as the .raw files that the RealSense SDK generates. https://uk.mathworks.com/help/matlab/ref/imwrite.html In regard to the script with a point cloud player, aside from having to change the stream resolutions to be compatible with L515 I cannot see a reason why the script would not work on an L515. |
Sincerely thank you for answering me patiently.
|
Thanks so much for sharing your MATLAB wrapper script with the RealSense community, @nchu-cha :) |
Can I have a view before I capture the frame? Because I want to make sure that the image which I capture is I want. I'm thinking that can I us the capture_example revise to the capture function? thank you |
You could have the program wait for a keypress before initiating capture, like in the C++ script at #8007 (comment) |
In the #8007 (comment) can it had a screen to see the instance frame? I need to build dataset for a market, in the dataset I hope that when I'm capturing the frame there will not had people in the frame, so I think if I had a viewer to see the instance frame will be more convenient. I'm looking the code in capture_example, and I don't understand the meaning of the function description inside. Is there a more detailed explanation?
thank you |
RsPipeLine would be the definition for the pipeline, and RsColorizer would refer to the use of a colorizer component to color-shade the depth data based on the depth values.
I do not know what 'r' represents though on the gyro and accel displays in the capture-example.m program though. It is probably equivalent to 'n' in the gyro and accel readout in the Viewer.
|
A function is a list of instructions that is jumped to when the function name is called from elsewhere in the script and then the instructions are carried out in the order that they are listed in the function. For example, if you created a Start button and set that start button to jump to a function named Start() that contained the start-up code, then that code would be run when the start button is clicked on. Have you defined the new Capture button in the properties (Access = public) list? Have you also defined a list of settings for CaptureButton like the ones for the Start and Stop buttons in the link below? |
yes, I had defined the capture button and also defined a list of setting for capture button.
Is the function mean when I click the capture button than the tmr.runnung == 'on' then the tmr will stop and the pipeline will also stop too? |
That is what your onCaptureButton() function looks like to me. If the button is pressed then the onCaptureButton is jumped to and the stop code currently within that function should cause the pipeline to be stopped. But because of the If logic statement that the stop code is within, the stop will only activate if the If condition's terms are met. In other words, the stop would only activate if the state app.tmr.Running is currently On. If it is Off then the If condition is not met and the stop code nested inside it would not be able to be triggered. So nothing would happen when the onCaptureButton button is pressed. |
I change the onCaptureButton() function to the below:
And change my CaptureUpFunc(app) function too, but it can't save the frame that I want.
I had found that if I write the |
Perhaps you could define a bool condition such as 'pause' that can be true or false, and set it to false by default in your script's start function. Then you could enclose wait_for_frames within an 'If pause = false' condition, so that new frames can only arrive if pause = false. When the capture button is pressed, the onCaptureButton() function's code could set pause to 'true'. As soon as it is set to true, wait_for_frames should no longer be able to deliver new frames. The capture could then be saved and pause set to 'false' again immediately afterwards so that wait_for_frames can resume streaming frames. |
I have heard of this behaviour once before, with Depth first and RGB second working but not the other way around. I do not have an explanation for it though. |
Thank you for your patient reply, I will close the issue |
Thanks very much @nchu-cha for the update and for your patience too! |
Before opening a new issue, we wanted to provide you with some useful suggestions (Click "Preview" above for a better view):
All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven't followed any of the suggestions above :)
Issue Description
hello,
I'm trying to understand all the MATALB function. I had tried
align,m
andcamera_info.m
, them I get some errorIn the
align.m
, comes an error that showsnot enough input arguments
in line 6narginchk(1,1);
. Should I revise the(1,1)
range?function this = align(align_to)
narginchk(1, 1);
validateattributes(align_to, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', int64(realsense.stream.count)});
out = realsense.librealsense_mex('rs2::align', 'new', int64(align_to));
this = [email protected](out);
end
In
canera_info.m
, I get an error aboutCannot call the constructor of 'realsense.camera_info' outside of its enumeration block.
I want to let my depth resolution up to 1024768, and let my RGB resolution up to 19201080, hoe can I change the resolution from using MATLAB function?
I have seen other people get the intrinsic and extrinsic parameters before aligning the images, can anyone teach me how to get these parameters?
Does anyone know hoe to solve it?
Thank you
The text was updated successfully, but these errors were encountered: