Items with no label
3338 討論

why realsense should code like this? auto&& frame : pipe.wait_for_frames()

FritzY
初學者
1,900 檢視

i saw the code example of IntelRealSense/librealsense/examples/save-to-disk/rs-save-to-disk.cpp from github.

link is https://github.com/IntelRealSense/librealsense/blob/master/examples/save-to-disk/rs-save-to-disk.cpp#L34

 line 34  for (auto&& frame : pipe.wait_for_frames())

​why code like this rather "auto frame = pipe.wait_for_frames()"

 

and line 37 if (auto vf = frame.as<rs2::video_frame>())

rather "auto vf = frame.get_depth_frame()"

 

is any better to code this way?

0 積分
5 回應
FritzY
初學者
1,670 檢視

is it in order to minimize the memory cost?

MartyG
榮譽貢獻者 III
1,670 檢視

The link below explains why wait_for_frames is used and the alternatives to it.

https://github.com/IntelRealSense/librealsense/issues/2422#issuecomment-423254709

Using 'video' frame is an appropriate choice when only saving data as a simple PNG, and not a file format with embedded depth matrix information such as .raw. or .bin

FritzY
初學者
1,670 檢視

Thanks for reply, it 's really helpful.

But what really disturb me is why it use A reference " auto &&" to define frame, is it a better(tidy) wrriting than using " = " to define an argument(the way we usually do)?and why?

then using "as" methond to change the class of frame. on the contrary, I may use "get_depth_frame" function straightly if my purpose is to get a depth image.

Perhaps it belongs to a c++ question boundary, but i would appriciate it if you give me some suggestions.

 

MartyG
榮譽貢獻者 III
1,670 檢視

My understanding is that "auto &&" makes it a 'universal reference' that can be bound to anything.

 

When programming Librealsense, my advice is to use example programs as a base reference and then adjust the code to your own style if you believe that your own method of structuring code is more suitable. Librealsense is open-source exactly so users can mold it to their needs and preferences.

FritzY
初學者
1,670 檢視

My opinion is maybe it's a memory saving way to code like this. Anyway, thanks you very much.

回覆