Skip to content
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

realsense L515 frame rate start getting slower and slower #10287

Closed
Billccx opened this issue Mar 4, 2022 · 9 comments
Closed

realsense L515 frame rate start getting slower and slower #10287

Billccx opened this issue Mar 4, 2022 · 9 comments

Comments

@Billccx
Copy link

Billccx commented Mar 4, 2022


Required Info
Camera Model L515
Operating System & Version ubunru20.04
Platform PC
Language C++

Issue Description

Dear researchers:
I use two realsense L515 to get RGB and depth frames. However, I found that the frame rate start getting slower after running for a while, rather than keeping a constant fps. Why is was so? Here is my code:

#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <chrono>
#include <time.h>

static cv::Mat frame_to_mat(const rs2::frame& f){
    using namespace cv;
    using namespace rs2;

    auto vf = f.as<video_frame>();
    const int w = vf.get_width();
    const int h = vf.get_height();

    if (f.get_profile().format() == RS2_FORMAT_BGR8){
        return Mat(Size(w, h), CV_8UC3, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_RGB8){
        auto r_rgb = Mat(Size(w, h), CV_8UC3, (void*)f.get_data(), Mat::AUTO_STEP);
        Mat r_bgr;
        cvtColor(r_rgb, r_bgr, COLOR_RGB2BGR);
        return r_bgr;
    }
    else if (f.get_profile().format() == RS2_FORMAT_Z16){
        return Mat(Size(w, h), CV_16UC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_Y8){
        return Mat(Size(w, h), CV_8UC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_DISPARITY32){
        return Mat(Size(w, h), CV_32FC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }

    throw std::runtime_error("Frame format is not supported yet!");
}


void printIntrinsics(rs2_intrinsics intrin){
    std::cout<<"\ncolor intrinsics: ";
    std::cout<<intrin.width<<"  "<<intrin.height<<"  ";
    std::cout<<intrin.ppx<<"  "<<intrin.ppy<<"  ";
    std::cout<<intrin.fx<<"  "<<intrin.fy<<std::endl;
    std::cout<<"coeffs: ";
    for(auto value : intrin.coeffs)
    std::cout<<value<<"  ";
    std::cout<<std::endl;
    std::cout<<"distortion model: "<<(int)intrin.model<<std::endl;
}

int main(){
    rs2::align align_to_color(RS2_STREAM_COLOR);
    rs2::context ctx;
    std::vector<rs2::pipeline> pipelines;
    std::map<std::string, rs2::colorizer> colorizers;
    std::vector<std::string> serials; //相机id

    auto list = ctx.query_devices(); // Get a snapshot of currently connected devices
    if (list.size() == 0) {
        throw std::runtime_error("No device detected. Is it plugged in?");
    }
    else{
        std::cout<<list.size()<<std::endl;
    }

    for(auto&& item : list){
        std::string serial=item.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
        std::cout<<serial<<std::endl;
        serials.push_back(serial);
    } 

    for (auto&& serial : serials){
        rs2::pipeline pipe(ctx);
        rs2::config cfg;
        cfg.enable_device(serial);
        cfg.enable_stream(rs2_stream::RS2_STREAM_DEPTH, 640, 480, rs2_format::RS2_FORMAT_Z16); 
        cfg.enable_stream(rs2_stream::RS2_STREAM_COLOR, 640, 480, rs2_format::RS2_FORMAT_RGB8); 
        pipe.start(cfg);
        pipelines.emplace_back(pipe);
        // Map from each device's serial number to a different colorizer
        colorizers[serial] = rs2::colorizer();
    }

    int cnt=0;
    int validcnt=0;

    std::cout<<"ready to fetch"<<std::endl;

    rs2::frameset prefs0,prefs1;
    prefs0=pipelines[0].wait_for_frames();
    prefs1=pipelines[1].wait_for_frames();
    rs2::video_frame precolor0=prefs0.get_color_frame();
    rs2::depth_frame predepth0=prefs0.get_depth_frame();
    rs2::video_frame precolor1=prefs1.get_color_frame();
    rs2::depth_frame predepth1=prefs1.get_depth_frame();

    rs2::stream_profile dprofile0 =  predepth0.get_profile();
    rs2::stream_profile cprofile0 =  precolor0.get_profile();
    rs2::stream_profile dprofile1 =  predepth1.get_profile();
    rs2::stream_profile cprofile1 =  precolor1.get_profile();

    rs2::video_stream_profile cvsprofile0(cprofile0);
    rs2_intrinsics color_intrin0 =  cvsprofile0.get_intrinsics();
    std::cout<<"for this first camera:"<<std::endl;
    printIntrinsics(color_intrin0);

    std::cout<<"for this second camera:"<<std::endl;
    rs2::video_stream_profile cvsprofile1(cprofile1);
    rs2_intrinsics color_intrin1 =  cvsprofile1.get_intrinsics();
    printIntrinsics(color_intrin1);

    std::chrono::_V2::steady_clock::time_point start,now;

    while (cnt<10000){
        start=now;
        rs2::frameset fs0,fs1;
        fs0=pipelines[0].wait_for_frames();
        fs1=pipelines[1].wait_for_frames();
        rs2::frameset aligned_frames0 = align_to_color.process(fs0);
        rs2::frameset aligned_frames1 = align_to_color.process(fs1);

        rs2::video_frame color0=aligned_frames0.get_color_frame();
        rs2::depth_frame depth0=aligned_frames0.get_depth_frame();

        rs2::video_frame color1=aligned_frames1.get_color_frame();
        rs2::depth_frame depth1=aligned_frames1.get_depth_frame();

        cv::Mat color0_mat=frame_to_mat(color0);
        cv::Mat color1_mat=frame_to_mat(color1);

        cv::Mat depth0_mat=frame_to_mat(depth0);
        cv::Mat depth1_mat=frame_to_mat(depth1);

        now=std::chrono::steady_clock::now();
        std::cout<<cnt<< "--fps:"<<
        1000000/(double)(std::chrono::duration_cast<std::chrono::microseconds>(now - start).count()) 
        << std::endl;
        cnt++;
    }
}

the output of my program is as follows:

2
f1231209
f1230584
ready to fetch
for this first camera:

color intrinsics: 640  480  331.948  248.697  600.764  600.986
coeffs: 0.171335  -0.528704  -0.00208366  2.20354e-05  0.495262  
distortion model: 4
for this second camera:

color intrinsics: 640  480  333.593  244.954  601.325  601.453
coeffs: 0.157447  -0.49804  -0.00211366  -0.00051181  0.47009  
distortion model: 4
0--fps:2.59976e-05
1--fps:21.2902
2--fps:21.5736
3--fps:21.4197
4--fps:17.5349
5--fps:22.6234
6--fps:21.0788
7--fps:21.3456
8--fps:22.4396
9--fps:22.412
10--fps:23.2872
11--fps:23.0378
12--fps:22.3174
13--fps:22.5591
14--fps:17.359
15--fps:22.0965
16--fps:20.9947
17--fps:21.4712
18--fps:15.6191
19--fps:22.6685
20--fps:22.0741
21--fps:21.4601
22--fps:21.8938
23--fps:22.7386
24--fps:21.9804
25--fps:22.8076
26--fps:22.0488
27--fps:22.302
28--fps:22.2881
29--fps:22.2198
30--fps:21.4078
31--fps:20.0856
32--fps:19.2704
33--fps:19.9263
34--fps:22.8352
35--fps:21.9346
36--fps:23.1278
37--fps:18.3311
38--fps:18.405
39--fps:16.9883
40--fps:24.1891
41--fps:22.1754
42--fps:21.9669
43--fps:22.1582
44--fps:22.1897
45--fps:21.6605
46--fps:22.7412
47--fps:23.5283
48--fps:22.1161
49--fps:21.3566
50--fps:22.0868
51--fps:21.3707
52--fps:23.2326
53--fps:22.0697
54--fps:18.1274
55--fps:18.9036
56--fps:18.6296
57--fps:18.4305
58--fps:17.6168
59--fps:18.4635
60--fps:21.5003
61--fps:22.3759
62--fps:21.126
63--fps:22.4926
64--fps:19.2186
65--fps:18.7846
66--fps:22.2846
67--fps:21.9558
68--fps:21.5633
69--fps:21.2875
70--fps:20.1649
71--fps:22.5739
72--fps:21.9433
73--fps:19.0157
74--fps:21.2409
75--fps:20.3331
76--fps:17.7321
77--fps:22.7273
78--fps:21.5517
79--fps:21.8551
80--fps:22.3829
81--fps:22.7485
82--fps:21.6492
83--fps:23.7001
84--fps:19.3904
85--fps:23.7756
86--fps:23.7001
87--fps:22.6608
88--fps:22.7739
89--fps:22.877
90--fps:22.5388
91--fps:21.8188
92--fps:22.3214
93--fps:22.4341
94--fps:23.8095
95--fps:22.5276
96--fps:22.9806
97--fps:22.8802
98--fps:21.3908
99--fps:22.6984
100--fps:21.4261
101--fps:18.8879
102--fps:21.0447
103--fps:23.1166
104--fps:23.0622
105--fps:21.6029
106--fps:23.6485
107--fps:21.9829
108--fps:21.4459
109--fps:21.3456
110--fps:22.9463
111--fps:22.9379
112--fps:23.8203
113--fps:23.0256
114--fps:22.5703
115--fps:16.6606
116--fps:19.2864
117--fps:16.1559
118--fps:16.9477
119--fps:22.6311
120--fps:22.3279
121--fps:21.0633
122--fps:22.7796
123--fps:22.5114
124--fps:22.8269
125--fps:22.409
126--fps:21.2269
127--fps:15.9962
128--fps:21.0766
129--fps:22.5601
130--fps:22.4457
131--fps:21.8522
132--fps:23.1551
133--fps:22.0522
134--fps:21.4105
135--fps:21.2825
136--fps:20.993
137--fps:19.145
138--fps:23.5134
139--fps:22.2163
140--fps:20.5326
141--fps:19.9824
142--fps:19.4609
143--fps:18.9118
144--fps:16.2514
145--fps:15.2607
146--fps:14.5582
147--fps:10.228
148--fps:9.47742
149--fps:13.9016
150--fps:14.1195
151--fps:13.428
152--fps:13.277
153--fps:12.6441
154--fps:9.75467
155--fps:11.5219
156--fps:10.3882
157--fps:10.2305
158--fps:10.5971
159--fps:10.3123
160--fps:10.2783
161--fps:9.28859
162--fps:9.70601
163--fps:7.84406
164--fps:10.4988
165--fps:7.80427
166--fps:7.41955
167--fps:12.2525
168--fps:10.1352
169--fps:10.3779
170--fps:10.0048
171--fps:10.4815
172--fps:6.40381
173--fps:9.93581
174--fps:10.0043
175--fps:9.81354
176--fps:10.0147
177--fps:9.26999
178--fps:10.8329
179--fps:10.5704
180--fps:10.0458
181--fps:9.64757
182--fps:9.69265
183--fps:10.0742
184--fps:10.5025
185--fps:10.0832
186--fps:9.11046
187--fps:10.9327
188--fps:10.1116
189--fps:9.0867
190--fps:9.74592
191--fps:8.61015
192--fps:8.09697
193--fps:8.16287
194--fps:8.46339
195--fps:11.2726
196--fps:12.0825
197--fps:12.9809
198--fps:13.4353
199--fps:12.6891
200--fps:13.6175
201--fps:13.5439
202--fps:11.8837
203--fps:9.36198
204--fps:8.57677
205--fps:8.89047
206--fps:12.2791
207--fps:11.1547
208--fps:10.9517
209--fps:10.3089
210--fps:7.78804
211--fps:7.40565
212--fps:7.83994
213--fps:8.73286
214--fps:11.6545
215--fps:10.7823
216--fps:10.0424
217--fps:10.6197
218--fps:9.42943
219--fps:10.1925
220--fps:10.0284
221--fps:9.88572
222--fps:9.90275
223--fps:8.79995
224--fps:8.50138
225--fps:8.86226
226--fps:9.33001
227--fps:9.1894
228--fps:10.0591
229--fps:10.1393
230--fps:9.53598
231--fps:9.64506
232--fps:7.2794
233--fps:9.19599
234--fps:9.40389
235--fps:7.18716
236--fps:8.28343
237--fps:10.4581
238--fps:9.81017
239--fps:10.3384
240--fps:9.14294
241--fps:8.6143
242--fps:11.2463
243--fps:9.51095
244--fps:10.3261
245--fps:10.4814
246--fps:9.86855
247--fps:9.49677
248--fps:9.83429
249--fps:10.1949
250--fps:8.98545
251--fps:9.52653
252--fps:8.64185
253--fps:9.07211
254--fps:7.97505
255--fps:7.05413
256--fps:6.87129
257--fps:6.89337
258--fps:9.55776
259--fps:12.2407
260--fps:11.6816
261--fps:11.1926
262--fps:9.79231
263--fps:9.5011
264--fps:8.78588
265--fps:9.55941
266--fps:9.5142
267--fps:8.52791
268--fps:9.72091
269--fps:9.70855
270--fps:9.85824
271--fps:10.2905
272--fps:10.3101
273--fps:6.99232
274--fps:8.18049
275--fps:9.20683
276--fps:10.3038
277--fps:9.37981
278--fps:8.83384
279--fps:11.1151
280--fps:10.4648
281--fps:10.1724
282--fps:8.58922
283--fps:10.9966
284--fps:11.0684
285--fps:11.1914
286--fps:10.4979
287--fps:8.86886
288--fps:7.33832
289--fps:9.2377
290--fps:10.7698
291--fps:10.9545
292--fps:10.259
293--fps:9.98652
294--fps:9.00471
295--fps:10.174
296--fps:11.1593
297--fps:9.96582
298--fps:10.6744
299--fps:7.03507
300--fps:9.48452
301--fps:11.2987
302--fps:11.5274
303--fps:10.2836
304--fps:10.0254
305--fps:9.945
306--fps:9.57176

As you can see, the fps slow down from 20 to 10. Besides that, I noticed that realsenseL515 get ‘fever’ after running for a while. Is fps slowing down caused by overheating?

I am really looking forward to you reply and thanks in advance!

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 4, 2022

Hi @Billccx If performance is slowing down over time then there may be a memory leak, where the memory of the computer is progressively consumed over time and causes the program's performance to degrade and even freeze / crash. In Ubuntu you can use a system monitoring tool such as htop to monitor memory usage whilst your program is running to see whether there is a leak.

If you are using the RealSense Viewer tool then memory leaks can occur for a small number of RealSense users if the GLSL options are enabled. You can disable GLSL in the Viewer's settings interface using instructions at #8110 (comment) to see whether it improves the reliability of performance.

In regard to the L515's temperature, if the casing is hot to the touch only a few minutes after streaming begins then this can indicate that there is an overheating problem related to USB (either a glitch on the USB port or a bad USB cable). The camera's temperatures can be monitored in real-time in the RealSense Viewer under the 'Controls' category of the L500 Depth Sensor options.

image

You can also unplug the micro-sized end of the USB cable from the base of the L515 camera, turn the connector around the opposite way and re-insert it into the base of the camera (as USB-C cables are two-way insertion at the micro-sized end) to see whether performance improves.

@Billccx
Copy link
Author

Billccx commented Mar 4, 2022

@MartyG-RealSense
Thanks a lot for such a quick reply!
I tried htop to monitor the memory. However it seems that I failed to find the sign of memory leak?
Here is the htop output when I started to run, the fps (not precise) is around 30-40.

1

After running for a while, the htop output is as follow, the fps is around 10-15.

2

Could you please tell me why it was so?
I'd be grateful if you would have a look at my source code.
Thanks!

@MartyG-RealSense
Copy link
Collaborator

Thanks very much for testimg memory usage and for your images. Next, please try going to the RGB section of the Viewer's options and disabling an option called Auto-Exposure Priority (whilst keeping Auto-Exposure enabled). If Auto-Exposure is enabled and Auto-Exposure Priority is disabled then the RealSense SDK should try to enforce a constant FPS rate instead of permitting the FPS to vary.

image

Also, did you find that the camera casing was hot to the touch only a few minutes after streaming began, and did you try reversing the connector?

@Billccx
Copy link
Author

Billccx commented Mar 4, 2022

@MartyG-RealSense
Thanks for your advice!
I haved disabled the "Auto-Exposure Priority" while keeping "Auto-Exposure" enabled. The fps in realsense-viewer is very stable. (Hardware fps 30/ viewer fps 17-22)
3

Unfortunately, when I try to run my source code, the problem still exist! Even though I have already set Auto-Exposure Priority off in my code:

for (auto&& serial : serials){
    rs2::pipeline pipe(ctx);
    rs2::config cfg;
    cfg.enable_device(serial);
    cfg.enable_stream(rs2_stream::RS2_STREAM_DEPTH, 640, 480, rs2_format::RS2_FORMAT_Z16); 
    cfg.enable_stream(rs2_stream::RS2_STREAM_COLOR, 640, 480, rs2_format::RS2_FORMAT_RGB8); 
    auto prof=pipe.start(cfg);
    auto sensors = prof.get_device().query_sensors();
    for(auto item:sensors) std::cout<<item.get_info(RS2_CAMERA_INFO_NAME)<<std::endl;

    auto rgb=prof.get_device().first<rs2::color_sensor>();
    rgb.set_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, 1);
    rgb.set_option(RS2_OPTION_AUTO_EXPOSURE_PRIORITY,0);

    pipelines.emplace_back(pipe);
    // Map from each device's serial number to a different colorizer
    colorizers[serial] = rs2::colorizer();
}

the output of my code are as follows:

~/code/C++/librealsense-2.50.0/examples/rs_bazel$ ./bazel-bin/src4/fps

2
f1231209
f1230584
L500 Depth Sensor
RGB Camera
Motion Module
L500 Depth Sensor
RGB Camera
Motion Module
ready to fetch
for this first camera:

color intrinsics: 640  480  331.948  248.697  600.764  600.986
coeffs: 0.171335  -0.528704  -0.00208366  2.20354e-05  0.495262  
distortion model: 4
for this second camera:

color intrinsics: 640  480  333.593  244.954  601.325  601.453
coeffs: 0.157447  -0.49804  -0.00211366  -0.00051181  0.47009  
distortion model: 4
0--fps:8.02835e-05
1--fps:18.9283
2--fps:18.8002
3--fps:21.9819
4--fps:21.8269
5--fps:18.7547
6--fps:21.034
7--fps:23.6206
8--fps:18.766
9--fps:22.0264
10--fps:23.0489
11--fps:23.5322
12--fps:21.4321
13--fps:21.1721
14--fps:23.3046
15--fps:21.901
16--fps:23.1353
17--fps:23.1455
18--fps:22.9505
19--fps:22.2207
20--fps:22.9437
21--fps:23.561
22--fps:23.1107
23--fps:24.024
24--fps:21.2734
25--fps:17.1942
26--fps:20.1191
27--fps:16.4614
28--fps:18.2202
29--fps:17.2622
30--fps:17.5908
31--fps:17.1057
32--fps:16.7434
33--fps:14.8524
34--fps:11.5517
35--fps:9.47445
36--fps:12.2414
37--fps:10.8074
38--fps:11.5182
39--fps:10.3991
40--fps:10.3449
41--fps:10.4062
42--fps:10.1002
43--fps:9.39761
44--fps:9.38958
45--fps:8.18438
46--fps:8.65816
47--fps:8.57442
48--fps:6.21616
49--fps:6.79297
50--fps:5.96805
51--fps:6.06502
52--fps:7.82473
53--fps:6.97623
54--fps:6.53053
55--fps:6.8645
56--fps:7.46977
57--fps:8.45866
58--fps:7.77454
59--fps:7.35532
60--fps:7.48963
61--fps:6.2007
62--fps:4.05313
63--fps:4.96662
64--fps:5.38497
65--fps:6.30601
66--fps:5.48195
67--fps:6.3937
68--fps:6.50656
69--fps:7.01331
70--fps:6.61892
71--fps:7.2247
72--fps:5.65032
73--fps:5.43877
74--fps:4.93813
75--fps:5.49843
76--fps:5.37285
77--fps:5.71122
78--fps:5.41243
79--fps:6.11247
80--fps:7.28959
81--fps:7.54023
82--fps:7.0368
83--fps:5.5513
84--fps:7.64175
85--fps:7.96324
86--fps:7.00687
87--fps:6.20952
88--fps:5.11949

The fps slow down quickly, from 20 to 5~10, only within 80 iterations.
I think the most likely explanation is there is something wrong with my source code. Unfortunately, I do not know how to correct it. :(
Sorry to have troubled you so much and I am looking forward to your reply.

Here is my source code:

#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <chrono>
#include <time.h>

static cv::Mat frame_to_mat(const rs2::frame& f){
    using namespace cv;
    using namespace rs2;

    auto vf = f.as<video_frame>();
    const int w = vf.get_width();
    const int h = vf.get_height();

    if (f.get_profile().format() == RS2_FORMAT_BGR8){
        return Mat(Size(w, h), CV_8UC3, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_RGB8){
        auto r_rgb = Mat(Size(w, h), CV_8UC3, (void*)f.get_data(), Mat::AUTO_STEP);
        Mat r_bgr;
        cvtColor(r_rgb, r_bgr, COLOR_RGB2BGR);
        return r_bgr;
    }
    else if (f.get_profile().format() == RS2_FORMAT_Z16){
        return Mat(Size(w, h), CV_16UC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_Y8){
        return Mat(Size(w, h), CV_8UC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }
    else if (f.get_profile().format() == RS2_FORMAT_DISPARITY32){
        return Mat(Size(w, h), CV_32FC1, (void*)f.get_data(), Mat::AUTO_STEP);
    }

    throw std::runtime_error("Frame format is not supported yet!");
}


void printIntrinsics(rs2_intrinsics intrin){
    std::cout<<"\ncolor intrinsics: ";
    std::cout<<intrin.width<<"  "<<intrin.height<<"  ";
    std::cout<<intrin.ppx<<"  "<<intrin.ppy<<"  ";
    std::cout<<intrin.fx<<"  "<<intrin.fy<<std::endl;
    std::cout<<"coeffs: ";
    for(auto value : intrin.coeffs)
    std::cout<<value<<"  ";
    std::cout<<std::endl;
    std::cout<<"distortion model: "<<(int)intrin.model<<std::endl;
}

int main(){
    rs2::align align_to_color(RS2_STREAM_COLOR);
    rs2::context ctx;
    std::vector<rs2::pipeline> pipelines;
    std::map<std::string, rs2::colorizer> colorizers;
    std::vector<std::string> serials;

    auto list = ctx.query_devices(); // Get a snapshot of currently connected devices
    if (list.size() == 0) {
        throw std::runtime_error("No device detected. Is it plugged in?");
    }
    else{
        std::cout<<list.size()<<std::endl;
    }

    for(auto&& item : list){
        std::string serial=item.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
        std::cout<<serial<<std::endl;
        serials.push_back(serial);
    } 

    for (auto&& serial : serials){
        rs2::pipeline pipe(ctx);
        rs2::config cfg;
        cfg.enable_device(serial);
        cfg.enable_stream(rs2_stream::RS2_STREAM_DEPTH, 640, 480, rs2_format::RS2_FORMAT_Z16); 
        cfg.enable_stream(rs2_stream::RS2_STREAM_COLOR, 640, 480, rs2_format::RS2_FORMAT_RGB8); 
        auto prof=pipe.start(cfg);
        auto sensors = prof.get_device().query_sensors();
        for(auto item:sensors) std::cout<<item.get_info(RS2_CAMERA_INFO_NAME)<<std::endl;

        auto rgb=prof.get_device().first<rs2::color_sensor>();
        rgb.set_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, 1);
        rgb.set_option(RS2_OPTION_AUTO_EXPOSURE_PRIORITY,0);

        pipelines.emplace_back(pipe);
        // Map from each device's serial number to a different colorizer
        colorizers[serial] = rs2::colorizer();
    }

    int cnt=0;
    int validcnt=0;
    
    std::cout<<"ready to fetch"<<std::endl;

    rs2::frameset prefs0,prefs1;
    prefs0=pipelines[0].wait_for_frames();
    prefs1=pipelines[1].wait_for_frames();
    rs2::video_frame precolor0=prefs0.get_color_frame();
    rs2::depth_frame predepth0=prefs0.get_depth_frame();
    rs2::video_frame precolor1=prefs1.get_color_frame();
    rs2::depth_frame predepth1=prefs1.get_depth_frame();

    rs2::stream_profile dprofile0 =  predepth0.get_profile();
    rs2::stream_profile cprofile0 =  precolor0.get_profile();
    rs2::stream_profile dprofile1 =  predepth1.get_profile();
    rs2::stream_profile cprofile1 =  precolor1.get_profile();

    rs2::video_stream_profile cvsprofile0(cprofile0);
    rs2_intrinsics color_intrin0 =  cvsprofile0.get_intrinsics();
    std::cout<<"for this first camera:"<<std::endl;
    printIntrinsics(color_intrin0);

    std::cout<<"for this second camera:"<<std::endl;
    rs2::video_stream_profile cvsprofile1(cprofile1);
    rs2_intrinsics color_intrin1 =  cvsprofile1.get_intrinsics();
    printIntrinsics(color_intrin1);

    std::chrono::_V2::steady_clock::time_point start,now;

    while (cnt<10000){
        start=now;
        rs2::frameset fs0,fs1;
        fs0=pipelines[0].wait_for_frames();
        fs1=pipelines[1].wait_for_frames();
        rs2::frameset aligned_frames0 = align_to_color.process(fs0);
        rs2::frameset aligned_frames1 = align_to_color.process(fs1);

        rs2::video_frame color0=aligned_frames0.get_color_frame();
        rs2::depth_frame depth0=aligned_frames0.get_depth_frame();

        rs2::video_frame color1=aligned_frames1.get_color_frame();
        rs2::depth_frame depth1=aligned_frames1.get_depth_frame();

        cv::Mat color0_mat=frame_to_mat(color0);
        cv::Mat color1_mat=frame_to_mat(color1);

        cv::Mat depth0_mat=frame_to_mat(depth0);
        cv::Mat depth1_mat=frame_to_mat(depth1);

        now=std::chrono::steady_clock::now();

        std::cout<<cnt<< "--fps:"<<
        1000000/(double)(std::chrono::duration_cast<std::chrono::microseconds>(now - start).count()) 
        << std::endl;
        cnt++;
    }

    return 0;
}

@MartyG-RealSense
Copy link
Collaborator

I see that you are using multicam code in your project to access two L515 cameras. It is recommended though to use poll_for_frames() instead of wait_for_frames() for an application that is accessing multiple cameras, like the SDK's rs-multicam example program does.

@Billccx
Copy link
Author

Billccx commented Mar 5, 2022

@MartyG-RealSense
Thanks for your advice!
I think I have already found what leads to program slowing down. It is rs2::align.
It seems that after hundreds of iterations, the time cost on RGB and depth alignment grow larger and larger.
here is my code:

#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <chrono>
#include <time.h>

int main(){
    rs2::align align_to_color(RS2_STREAM_COLOR);
    rs2::context ctx;
    std::vector<rs2::pipeline> pipelines;
    std::map<std::string, rs2::colorizer> colorizers;
    std::vector<std::string> serials;

    auto list = ctx.query_devices(); // Get a snapshot of currently connected devices
    if (list.size() == 0) {
        throw std::runtime_error("No device detected. Is it plugged in?");
    }
    else{
        std::cout<<list.size()<<std::endl;
    }

    for(auto&& item : list){
        std::string serial=item.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
        std::cout<<serial<<std::endl;
        serials.push_back(serial);
    } 

    for (auto&& serial : serials){
        rs2::pipeline pipe(ctx);
        rs2::config cfg;
        cfg.enable_device(serial);
        cfg.enable_stream(rs2_stream::RS2_STREAM_DEPTH, 640, 480, rs2_format::RS2_FORMAT_Z16); 
        cfg.enable_stream(rs2_stream::RS2_STREAM_COLOR, 640, 480, rs2_format::RS2_FORMAT_RGB8); 
        auto prof=pipe.start(cfg);
        auto sensors = prof.get_device().query_sensors();
        for(auto item:sensors) std::cout<<item.get_info(RS2_CAMERA_INFO_NAME)<<std::endl;

        auto rgb=prof.get_device().first<rs2::color_sensor>();
        rgb.set_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE, 1);
        rgb.set_option(RS2_OPTION_AUTO_EXPOSURE_PRIORITY,0);

        pipelines.emplace_back(pipe);
        // Map from each device's serial number to a different colorizer
        colorizers[serial] = rs2::colorizer();
    }

    int cnt=0;   
    std::cout<<"ready to fetch"<<std::endl;

    std::chrono::_V2::steady_clock::time_point start,now;
    std::chrono::_V2::steady_clock::time_point r,l;

    while (cnt<10000){
        start=now;
        rs2::frameset fs0,fs1;
        fs0=pipelines[0].wait_for_frames();
        fs1=pipelines[1].wait_for_frames();


        l=std::chrono::steady_clock::now();

        rs2::frameset aligned_frames0 = align_to_color.process(fs0);
        rs2::frameset aligned_frames1 = align_to_color.process(fs1);


        r=std::chrono::steady_clock::now();

        std::cout<<cnt<< "-RGB depth alignment time cost: "<<
        (double)(std::chrono::duration_cast<std::chrono::duration<double>>(r - l).count()) 
        <<" seconds       ";

        rs2::video_frame color0=fs0.get_color_frame();
        rs2::depth_frame depth0=fs0.get_depth_frame();

        rs2::video_frame color1=fs1.get_color_frame();
        rs2::depth_frame depth1=fs1.get_depth_frame();

        now=std::chrono::steady_clock::now();

        std::cout<<cnt<< "--fps:"<<
        1000000/(double)(std::chrono::duration_cast<std::chrono::microseconds>(now - start).count()) 
        << std::endl;
        cnt++;
    }

    return 0;
}

the output of the program is as follow:

2
f1231209
f1230584
L500 Depth Sensor
RGB Camera
Motion Module
L500 Depth Sensor
RGB Camera
Motion Module
ready to fetch
0-RGB depth alignment time cost: 0.229177 seconds       0--fps:4.24504e-05
1-RGB depth alignment time cost: 0.038753 seconds       1--fps:25.6984
2-RGB depth alignment time cost: 0.0390417 seconds       2--fps:25.5323
3-RGB depth alignment time cost: 0.0389218 seconds       3--fps:25.6174
4-RGB depth alignment time cost: 0.03765 seconds       4--fps:26.4823
5-RGB depth alignment time cost: 0.0386433 seconds       5--fps:25.7951
6-RGB depth alignment time cost: 0.0388555 seconds       6--fps:25.5598
7-RGB depth alignment time cost: 0.0375068 seconds       7--fps:26.5936
8-RGB depth alignment time cost: 0.0374081 seconds       8--fps:26.6574
9-RGB depth alignment time cost: 0.0379117 seconds       9--fps:26.2992
10-RGB depth alignment time cost: 0.0387661 seconds       10--fps:25.7215
11-RGB depth alignment time cost: 0.0379902 seconds       11--fps:26.2502
12-RGB depth alignment time cost: 0.0387106 seconds       12--fps:25.7639
13-RGB depth alignment time cost: 0.0375177 seconds       13--fps:26.5315
14-RGB depth alignment time cost: 0.0367369 seconds       14--fps:27.1518
15-RGB depth alignment time cost: 0.0364953 seconds       15--fps:27.3299
16-RGB depth alignment time cost: 0.0366364 seconds       16--fps:27.2227
17-RGB depth alignment time cost: 0.0366454 seconds       17--fps:27.2057
18-RGB depth alignment time cost: 0.0361884 seconds       18--fps:27.5452
19-RGB depth alignment time cost: 0.0360009 seconds       19--fps:27.6909
20-RGB depth alignment time cost: 0.03593 seconds       20--fps:27.7493
21-RGB depth alignment time cost: 0.0369931 seconds       21--fps:26.9564
22-RGB depth alignment time cost: 0.0400367 seconds       22--fps:24.8558
23-RGB depth alignment time cost: 0.0371478 seconds       23--fps:26.8492
24-RGB depth alignment time cost: 0.036921 seconds       24--fps:27.0161
25-RGB depth alignment time cost: 0.0365378 seconds       25--fps:27.2881
26-RGB depth alignment time cost: 0.0356602 seconds       26--fps:27.9345
27-RGB depth alignment time cost: 0.036634 seconds       27--fps:27.2146
28-RGB depth alignment time cost: 0.0369219 seconds       28--fps:26.9942
29-RGB depth alignment time cost: 0.0367923 seconds       29--fps:27.0981
30-RGB depth alignment time cost: 0.0382679 seconds       30--fps:26.0559
31-RGB depth alignment time cost: 0.0371203 seconds       31--fps:26.8075
32-RGB depth alignment time cost: 0.0370518 seconds       32--fps:26.9193
33-RGB depth alignment time cost: 0.036352 seconds       33--fps:27.4363
34-RGB depth alignment time cost: 0.0364952 seconds       34--fps:27.3246
35-RGB depth alignment time cost: 0.037499 seconds       35--fps:26.5774
36-RGB depth alignment time cost: 0.0364835 seconds       36--fps:27.3276
37-RGB depth alignment time cost: 0.0360367 seconds       37--fps:27.6732
38-RGB depth alignment time cost: 0.035875 seconds       38--fps:27.7708
39-RGB depth alignment time cost: 0.0354098 seconds       39--fps:28.1468
40-RGB depth alignment time cost: 0.0383673 seconds       40--fps:25.9632
41-RGB depth alignment time cost: 0.0373736 seconds       41--fps:26.6596
42-RGB depth alignment time cost: 0.0357121 seconds       42--fps:27.922
43-RGB depth alignment time cost: 0.0347376 seconds       43--fps:28.7043
44-RGB depth alignment time cost: 0.0344683 seconds       44--fps:28.9243
45-RGB depth alignment time cost: 0.0348688 seconds       45--fps:28.5976
46-RGB depth alignment time cost: 0.0375928 seconds       46--fps:26.5189
47-RGB depth alignment time cost: 0.0383193 seconds       47--fps:26.0125
48-RGB depth alignment time cost: 0.0370604 seconds       48--fps:26.8861
49-RGB depth alignment time cost: 0.037458 seconds       49--fps:26.6219
50-RGB depth alignment time cost: 0.0379696 seconds       50--fps:26.2619
51-RGB depth alignment time cost: 0.0374925 seconds       51--fps:26.5632
52-RGB depth alignment time cost: 0.0366939 seconds       52--fps:27.1769
53-RGB depth alignment time cost: 0.0401451 seconds       53--fps:24.8429
54-RGB depth alignment time cost: 0.0458157 seconds       54--fps:21.7467
55-RGB depth alignment time cost: 0.0378522 seconds       55--fps:26.3442
56-RGB depth alignment time cost: 0.0364481 seconds       56--fps:27.3388
57-RGB depth alignment time cost: 0.0362236 seconds       57--fps:27.527
58-RGB depth alignment time cost: 0.0355616 seconds       58--fps:28.0458
59-RGB depth alignment time cost: 0.0349894 seconds       59--fps:28.4835
60-RGB depth alignment time cost: 0.0345176 seconds       60--fps:28.8942
61-RGB depth alignment time cost: 0.0353968 seconds       61--fps:28.1738
62-RGB depth alignment time cost: 0.0364978 seconds       62--fps:27.3082
63-RGB depth alignment time cost: 0.0355464 seconds       63--fps:28.0426
64-RGB depth alignment time cost: 0.0357885 seconds       64--fps:27.8489
65-RGB depth alignment time cost: 0.0439528 seconds       65--fps:22.6896
66-RGB depth alignment time cost: 0.0461307 seconds       66--fps:21.6146
67-RGB depth alignment time cost: 0.0462508 seconds       67--fps:21.5773
68-RGB depth alignment time cost: 0.0474853 seconds       68--fps:21.0133
69-RGB depth alignment time cost: 0.0452652 seconds       69--fps:22.0313
70-RGB depth alignment time cost: 0.0450759 seconds       70--fps:22.1107
71-RGB depth alignment time cost: 0.0475847 seconds       71--fps:20.8459
72-RGB depth alignment time cost: 0.0470258 seconds       72--fps:21.2197
73-RGB depth alignment time cost: 0.0427415 seconds       73--fps:23.334
74-RGB depth alignment time cost: 0.0439944 seconds       74--fps:22.6511
75-RGB depth alignment time cost: 0.0439473 seconds       75--fps:22.6727
76-RGB depth alignment time cost: 0.0460091 seconds       76--fps:21.6109
77-RGB depth alignment time cost: 0.0428149 seconds       77--fps:23.2975
78-RGB depth alignment time cost: 0.041497 seconds       78--fps:24.0327
79-RGB depth alignment time cost: 0.039585 seconds       79--fps:25.156
80-RGB depth alignment time cost: 0.0430873 seconds       80--fps:23.1444
81-RGB depth alignment time cost: 0.0524004 seconds       81--fps:19.0161
82-RGB depth alignment time cost: 0.0352922 seconds       82--fps:28.2382
83-RGB depth alignment time cost: 0.0384508 seconds       83--fps:25.9336
84-RGB depth alignment time cost: 0.0400018 seconds       84--fps:24.854
85-RGB depth alignment time cost: 0.0376006 seconds       85--fps:26.5238
86-RGB depth alignment time cost: 0.0382437 seconds       86--fps:26.0824
87-RGB depth alignment time cost: 0.0374226 seconds       87--fps:26.6283
88-RGB depth alignment time cost: 0.0370726 seconds       88--fps:26.894
89-RGB depth alignment time cost: 0.0376059 seconds       89--fps:26.5196
90-RGB depth alignment time cost: 0.0365395 seconds       90--fps:27.2866
91-RGB depth alignment time cost: 0.049035 seconds       91--fps:20.2996
92-RGB depth alignment time cost: 0.0449439 seconds       92--fps:22.202
93-RGB depth alignment time cost: 0.0346676 seconds       93--fps:28.7588
94-RGB depth alignment time cost: 0.0354643 seconds       94--fps:28.1136
95-RGB depth alignment time cost: 0.0351765 seconds       95--fps:28.3286
96-RGB depth alignment time cost: 0.0380442 seconds       96--fps:26.1897
97-RGB depth alignment time cost: 0.0356227 seconds       97--fps:27.9634
98-RGB depth alignment time cost: 0.0350188 seconds       98--fps:28.4819
99-RGB depth alignment time cost: 0.0354095 seconds       99--fps:28.1698
100-RGB depth alignment time cost: 0.0379055 seconds       100--fps:26.3137
101-RGB depth alignment time cost: 0.0376058 seconds       101--fps:26.5154
102-RGB depth alignment time cost: 0.0360134 seconds       102--fps:27.6909
103-RGB depth alignment time cost: 0.0358949 seconds       103--fps:27.7847
104-RGB depth alignment time cost: 0.0340729 seconds       104--fps:29.2646
105-RGB depth alignment time cost: 0.0341763 seconds       105--fps:29.1783
106-RGB depth alignment time cost: 0.034211 seconds       106--fps:29.1426
107-RGB depth alignment time cost: 0.0353568 seconds       107--fps:28.1833
108-RGB depth alignment time cost: 0.0360751 seconds       108--fps:27.6373
109-RGB depth alignment time cost: 0.0362327 seconds       109--fps:27.4937
110-RGB depth alignment time cost: 0.0371576 seconds       110--fps:26.8276
111-RGB depth alignment time cost: 0.0361254 seconds       111--fps:27.6144
112-RGB depth alignment time cost: 0.0359273 seconds       112--fps:27.7639
113-RGB depth alignment time cost: 0.0359461 seconds       113--fps:27.7454
114-RGB depth alignment time cost: 0.0368952 seconds       114--fps:27.0285
115-RGB depth alignment time cost: 0.035713 seconds       115--fps:27.9174
116-RGB depth alignment time cost: 0.0361523 seconds       116--fps:27.5786
117-RGB depth alignment time cost: 0.0363171 seconds       117--fps:27.4589
118-RGB depth alignment time cost: 0.035671 seconds       118--fps:27.9501
119-RGB depth alignment time cost: 0.0361547 seconds       119--fps:27.5748
120-RGB depth alignment time cost: 0.0402642 seconds       120--fps:24.7476
121-RGB depth alignment time cost: 0.0370244 seconds       121--fps:26.9411
122-RGB depth alignment time cost: 0.036121 seconds       122--fps:27.6159
123-RGB depth alignment time cost: 0.0357106 seconds       123--fps:27.9322
124-RGB depth alignment time cost: 0.0371894 seconds       124--fps:26.7989
125-RGB depth alignment time cost: 0.0335211 seconds       125--fps:29.7292
126-RGB depth alignment time cost: 0.0338834 seconds       126--fps:29.4178
127-RGB depth alignment time cost: 0.0341402 seconds       127--fps:29.1877
128-RGB depth alignment time cost: 0.0337455 seconds       128--fps:29.5377
129-RGB depth alignment time cost: 0.034029 seconds       129--fps:29.2997
130-RGB depth alignment time cost: 0.0342637 seconds       130--fps:29.1036
131-RGB depth alignment time cost: 0.0345705 seconds       131--fps:28.845
132-RGB depth alignment time cost: 0.0343628 seconds       132--fps:29.0217
133-RGB depth alignment time cost: 0.0349068 seconds       133--fps:28.5665
134-RGB depth alignment time cost: 0.0349418 seconds       134--fps:28.5356
135-RGB depth alignment time cost: 0.035893 seconds       135--fps:27.7731
136-RGB depth alignment time cost: 0.037325 seconds       136--fps:26.7023
137-RGB depth alignment time cost: 0.0366887 seconds       137--fps:27.1621
138-RGB depth alignment time cost: 0.0356441 seconds       138--fps:27.9712
139-RGB depth alignment time cost: 0.0359116 seconds       139--fps:27.777
140-RGB depth alignment time cost: 0.0362882 seconds       140--fps:27.4839
141-RGB depth alignment time cost: 0.0365751 seconds       141--fps:27.2405
142-RGB depth alignment time cost: 0.0361893 seconds       142--fps:27.549
143-RGB depth alignment time cost: 0.0360251 seconds       143--fps:27.6771
144-RGB depth alignment time cost: 0.0347014 seconds       144--fps:28.7373
145-RGB depth alignment time cost: 0.0345373 seconds       145--fps:28.8717
146-RGB depth alignment time cost: 0.0351559 seconds       146--fps:28.3656
147-RGB depth alignment time cost: 0.0349089 seconds       147--fps:28.5551
148-RGB depth alignment time cost: 0.0356571 seconds       148--fps:27.9509
149-RGB depth alignment time cost: 0.0368198 seconds       149--fps:27.0504
150-RGB depth alignment time cost: 0.0364547 seconds       150--fps:27.3321
151-RGB depth alignment time cost: 0.0362116 seconds       151--fps:27.5399
152-RGB depth alignment time cost: 0.0360712 seconds       152--fps:27.6518
153-RGB depth alignment time cost: 0.0353502 seconds       153--fps:28.2095
154-RGB depth alignment time cost: 0.0351051 seconds       154--fps:28.3881
155-RGB depth alignment time cost: 0.0359895 seconds       155--fps:27.7001
156-RGB depth alignment time cost: 0.0356472 seconds       156--fps:27.9767
157-RGB depth alignment time cost: 0.035621 seconds       157--fps:28.0034
158-RGB depth alignment time cost: 0.0353614 seconds       158--fps:28.1976
159-RGB depth alignment time cost: 0.0355789 seconds       159--fps:28.0285
160-RGB depth alignment time cost: 0.0350453 seconds       160--fps:28.4544
161-RGB depth alignment time cost: 0.0355389 seconds       161--fps:28.0568
162-RGB depth alignment time cost: 0.0374026 seconds       162--fps:26.6581
163-RGB depth alignment time cost: 0.035893 seconds       163--fps:27.7616
164-RGB depth alignment time cost: 0.0364089 seconds       164--fps:27.3928
165-RGB depth alignment time cost: 0.0353866 seconds       165--fps:28.1889
166-RGB depth alignment time cost: 0.0353572 seconds       166--fps:28.2111
167-RGB depth alignment time cost: 0.0357489 seconds       167--fps:27.9002
168-RGB depth alignment time cost: 0.0364735 seconds       168--fps:27.3276
169-RGB depth alignment time cost: 0.0360188 seconds       169--fps:27.6801
170-RGB depth alignment time cost: 0.0359551 seconds       170--fps:27.7385
171-RGB depth alignment time cost: 0.0354704 seconds       171--fps:28.1152
172-RGB depth alignment time cost: 0.0360648 seconds       172--fps:27.6518
173-RGB depth alignment time cost: 0.0353631 seconds       173--fps:28.1984
174-RGB depth alignment time cost: 0.0359651 seconds       174--fps:27.7108
175-RGB depth alignment time cost: 0.0363636 seconds       175--fps:27.3943
176-RGB depth alignment time cost: 0.0361137 seconds       176--fps:27.5961
177-RGB depth alignment time cost: 0.03548 seconds       177--fps:28.1152
178-RGB depth alignment time cost: 0.0355816 seconds       178--fps:28.034
179-RGB depth alignment time cost: 0.0355926 seconds       179--fps:28.023
180-RGB depth alignment time cost: 0.035871 seconds       180--fps:27.7731
181-RGB depth alignment time cost: 0.0357328 seconds       181--fps:27.9018
182-RGB depth alignment time cost: 0.0358823 seconds       182--fps:27.7924
183-RGB depth alignment time cost: 0.0357085 seconds       183--fps:27.9267
184-RGB depth alignment time cost: 0.0357664 seconds       184--fps:26.4187
185-RGB depth alignment time cost: 0.0357718 seconds       185--fps:27.8761
186-RGB depth alignment time cost: 0.037065 seconds       186--fps:26.8991
187-RGB depth alignment time cost: 0.0368756 seconds       187--fps:27.0051
188-RGB depth alignment time cost: 0.0353386 seconds       188--fps:28.2271
189-RGB depth alignment time cost: 0.034645 seconds       189--fps:28.7869
190-RGB depth alignment time cost: 0.0374528 seconds       190--fps:26.6297
191-RGB depth alignment time cost: 0.0392348 seconds       191--fps:25.4026
192-RGB depth alignment time cost: 0.0361018 seconds       192--fps:27.6136
193-RGB depth alignment time cost: 0.0363525 seconds       193--fps:27.4273
194-RGB depth alignment time cost: 0.0358939 seconds       194--fps:27.7909
195-RGB depth alignment time cost: 0.0360104 seconds       195--fps:27.6932
196-RGB depth alignment time cost: 0.0384635 seconds       196--fps:25.9269
197-RGB depth alignment time cost: 0.0361913 seconds       197--fps:27.5346
198-RGB depth alignment time cost: 0.0362965 seconds       198--fps:27.4816
199-RGB depth alignment time cost: 0.035934 seconds       199--fps:27.7608
200-RGB depth alignment time cost: 0.0361629 seconds       200--fps:27.5824
201-RGB depth alignment time cost: 0.0361536 seconds       201--fps:27.5778
202-RGB depth alignment time cost: 0.0357427 seconds       202--fps:27.9018
203-RGB depth alignment time cost: 0.0359624 seconds       203--fps:27.7362
204-RGB depth alignment time cost: 0.0360876 seconds       204--fps:27.6388
205-RGB depth alignment time cost: 0.0361865 seconds       205--fps:27.5626
206-RGB depth alignment time cost: 0.0362339 seconds       206--fps:27.5247
207-RGB depth alignment time cost: 0.0370391 seconds       207--fps:26.9041
208-RGB depth alignment time cost: 0.0364076 seconds       208--fps:27.3471
209-RGB depth alignment time cost: 0.0359292 seconds       209--fps:27.7577
210-RGB depth alignment time cost: 0.0360615 seconds       210--fps:27.6625
211-RGB depth alignment time cost: 0.035988 seconds       211--fps:27.7177
212-RGB depth alignment time cost: 0.0360075 seconds       212--fps:27.6962
213-RGB depth alignment time cost: 0.0357431 seconds       213--fps:27.8901
214-RGB depth alignment time cost: 0.0357377 seconds       214--fps:27.8979
215-RGB depth alignment time cost: 0.0361632 seconds       215--fps:27.5824
216-RGB depth alignment time cost: 0.0362977 seconds       216--fps:27.4748
217-RGB depth alignment time cost: 0.0366142 seconds       217--fps:27.2383
218-RGB depth alignment time cost: 0.0398418 seconds       218--fps:25.0269
219-RGB depth alignment time cost: 0.0402586 seconds       219--fps:24.7727
220-RGB depth alignment time cost: 0.042275 seconds       220--fps:23.5983
221-RGB depth alignment time cost: 0.0433863 seconds       221--fps:22.9906
222-RGB depth alignment time cost: 0.0476642 seconds       222--fps:20.9266
223-RGB depth alignment time cost: 0.0476839 seconds       223--fps:20.9205
224-RGB depth alignment time cost: 0.0504138 seconds       224--fps:19.7902
225-RGB depth alignment time cost: 0.0496984 seconds       225--fps:20.0747
226-RGB depth alignment time cost: 0.0530068 seconds       226--fps:18.8179
227-RGB depth alignment time cost: 0.0534609 seconds       227--fps:18.6522
228-RGB depth alignment time cost: 0.0551169 seconds       228--fps:18.0819
229-RGB depth alignment time cost: 0.057613 seconds       229--fps:17.3139
230-RGB depth alignment time cost: 0.0573502 seconds       230--fps:17.3916
231-RGB depth alignment time cost: 0.0589014 seconds       231--fps:16.9222
232-RGB depth alignment time cost: 0.0599539 seconds       232--fps:16.6367
233-RGB depth alignment time cost: 0.0612367 seconds       233--fps:16.292
234-RGB depth alignment time cost: 0.0634953 seconds       234--fps:15.7099
235-RGB depth alignment time cost: 0.0631687 seconds       235--fps:15.7913
236-RGB depth alignment time cost: 0.0640505 seconds       236--fps:15.5771
237-RGB depth alignment time cost: 0.0691937 seconds       237--fps:14.4209
238-RGB depth alignment time cost: 0.0706561 seconds       238--fps:14.1161
239-RGB depth alignment time cost: 0.0694268 seconds       239--fps:14.3664
240-RGB depth alignment time cost: 0.0687614 seconds       240--fps:14.5062
241-RGB depth alignment time cost: 0.0687726 seconds       241--fps:14.5045
242-RGB depth alignment time cost: 0.0678698 seconds       242--fps:14.6964
243-RGB depth alignment time cost: 0.068217 seconds       243--fps:14.6239
244-RGB depth alignment time cost: 0.0701592 seconds       244--fps:14.2201
245-RGB depth alignment time cost: 0.0714898 seconds       245--fps:13.954
246-RGB depth alignment time cost: 0.0756127 seconds       246--fps:13.1808
247-RGB depth alignment time cost: 0.0744754 seconds       247--fps:13.3924
248-RGB depth alignment time cost: 0.0743576 seconds       248--fps:13.4162
249-RGB depth alignment time cost: 0.0761368 seconds       249--fps:13.101
250-RGB depth alignment time cost: 0.0754748 seconds       250--fps:13.2045
251-RGB depth alignment time cost: 0.0742685 seconds       251--fps:13.4277
252-RGB depth alignment time cost: 0.0736638 seconds       252--fps:13.5421
253-RGB depth alignment time cost: 0.0762429 seconds       253--fps:13.0822
254-RGB depth alignment time cost: 0.0752997 seconds       254--fps:13.2382
255-RGB depth alignment time cost: 0.0741932 seconds       255--fps:13.4443
256-RGB depth alignment time cost: 0.0742841 seconds       256--fps:13.4291
257-RGB depth alignment time cost: 0.0760248 seconds       257--fps:13.1211
258-RGB depth alignment time cost: 0.0897253 seconds       258--fps:11.1144
259-RGB depth alignment time cost: 0.073125 seconds       259--fps:13.6394
260-RGB depth alignment time cost: 0.0736016 seconds       260--fps:13.552
261-RGB depth alignment time cost: 0.0744919 seconds       261--fps:13.3776
262-RGB depth alignment time cost: 0.0728621 seconds       262--fps:13.6906
263-RGB depth alignment time cost: 0.0725256 seconds       263--fps:13.7546
264-RGB depth alignment time cost: 0.0775168 seconds       264--fps:12.8682
265-RGB depth alignment time cost: 0.0793255 seconds       265--fps:12.5649
266-RGB depth alignment time cost: 0.076653 seconds       266--fps:13.012
267-RGB depth alignment time cost: 0.0795302 seconds       267--fps:12.5411
268-RGB depth alignment time cost: 0.0778435 seconds       268--fps:12.8162
269-RGB depth alignment time cost: 0.0737549 seconds       269--fps:13.523
270-RGB depth alignment time cost: 0.0748183 seconds       270--fps:13.3308
271-RGB depth alignment time cost: 0.0740825 seconds       271--fps:13.4568
272-RGB depth alignment time cost: 0.0748294 seconds       272--fps:13.3248
273-RGB depth alignment time cost: 0.0773406 seconds       273--fps:12.8984
274-RGB depth alignment time cost: 0.0818149 seconds       274--fps:12.1941
275-RGB depth alignment time cost: 0.0791071 seconds       275--fps:12.6127
276-RGB depth alignment time cost: 0.08064 seconds       276--fps:12.3706
277-RGB depth alignment time cost: 0.0738759 seconds       277--fps:13.4902
278-RGB depth alignment time cost: 0.0717763 seconds       278--fps:13.8953
279-RGB depth alignment time cost: 0.0730709 seconds       279--fps:13.6519
280-RGB depth alignment time cost: 0.072188 seconds       280--fps:13.819
281-RGB depth alignment time cost: 0.0746569 seconds       281--fps:13.3611
282-RGB depth alignment time cost: 0.0793603 seconds       282--fps:12.5606
283-RGB depth alignment time cost: 0.0772265 seconds       283--fps:12.9169
284-RGB depth alignment time cost: 0.0793632 seconds       284--fps:12.5694
285-RGB depth alignment time cost: 0.0768992 seconds       285--fps:12.9455
286-RGB depth alignment time cost: 0.0766701 seconds       286--fps:13.0115
287-RGB depth alignment time cost: 0.0751535 seconds       287--fps:13.2709
288-RGB depth alignment time cost: 0.0745802 seconds       288--fps:13.3656
289-RGB depth alignment time cost: 0.0743019 seconds       289--fps:13.4277
290-RGB depth alignment time cost: 0.09542 seconds       290--fps:10.4529
291-RGB depth alignment time cost: 0.0776479 seconds       291--fps:12.8327
292-RGB depth alignment time cost: 0.073763 seconds       292--fps:13.5216
293-RGB depth alignment time cost: 0.0710003 seconds       293--fps:14.0463
294-RGB depth alignment time cost: 0.0762975 seconds       294--fps:13.0727
295-RGB depth alignment time cost: 0.0769347 seconds       295--fps:12.9685
296-RGB depth alignment time cost: 0.0745512 seconds       296--fps:13.3783
297-RGB depth alignment time cost: 0.0786076 seconds       297--fps:12.6904
298-RGB depth alignment time cost: 0.0734689 seconds       298--fps:13.5788
299-RGB depth alignment time cost: 0.0718114 seconds       299--fps:13.8906
300-RGB depth alignment time cost: 0.0722875 seconds       300--fps:13.7988
301-RGB depth alignment time cost: 0.0743864 seconds       301--fps:13.3774
302-RGB depth alignment time cost: 0.0746394 seconds       302--fps:13.3515
303-RGB depth alignment time cost: 0.0737597 seconds       303--fps:13.5241
304-RGB depth alignment time cost: 0.0699076 seconds       304--fps:14.2694

The time cost of the code below grow from 0.03 seconds to 0.07 seconds

rs2::frameset aligned_frames0 = align_to_color.process(fs0);
rs2::frameset aligned_frames1 = align_to_color.process(fs1);

Besides that, I have also noticed that my CPU usage is quite heavy after running for a while.
4

What should I do? I do not understand why 'RGB-depth alignment' operation takes more and more time.

I am looking forward to your reply. Thanks a lot!

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 5, 2022

I have not seen your particular approach in your script before. It looks as though it could be very costly in terms of processing burden.

A RealSense team member provides a C++ multicam script that uses pipelines at #2219 (comment) that you could compare to your own approach.

@MartyG-RealSense
Copy link
Collaborator

Hi @Billccx Do you require further assistance with this case, please? Thanks!

@MartyG-RealSense
Copy link
Collaborator

Case closed due to no further comments received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants