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

[RSDK-7954] Add PCD support and organize encoding helpers #41

Merged
merged 7 commits into from
Jun 21, 2024
Merged

[RSDK-7954] Add PCD support and organize encoding helpers #41

merged 7 commits into from
Jun 21, 2024

Conversation

hexbabe
Copy link
Collaborator

@hexbabe hexbabe commented Jun 18, 2024

RSDK-7954

Before removing join_color_depth, we wanted to try out adding PCD support directly into the Realsense module since that was the main use case for join_color_depth anyways. After some trial and error, it looks like adding this logic into get_point_cloud is the right path forward. Since we do PCD computation using the latest depth frame and color frame on invocation, it doesn't slow down the logic of frame loop or get_image/images.

I implemented the above in this PR along with some re-organization of the encoding helpers into a separate file since the main file is getting quite large.

As for testing, I tested little_endian_depth set to true and the PCD came out fine. I tested getting color images and viewing point clouds on the App stream with 640x480 and 1280x720 with both sensors. I also verified that using only the depth sensor works for non-color PCDs.
Screenshot 2024-06-18 at 12 34 18 PM
Screenshot 2024-06-18 at 12 35 29 PM

@hexbabe
Copy link
Collaborator Author

hexbabe commented Jun 18, 2024

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 14ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 14ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 24ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 24ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 10ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 10ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 33ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 33ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 10ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 10ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] wait for frames: 0ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] total: 680ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] frame alignment: 677ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 11ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 11ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_point_cloud] total: 694ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 14ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 14ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 31ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 31ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 11ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 11ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] wait for frames: 0ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] total: 639ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [frameLoop] frame alignment: 637ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 18ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 18ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 13ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [GetImage] JPEG color encode: 13ms

6/18/2024, 12:09:51 PM info robot_server.modmanager.process.irs-local-mod_/home/seanyu/viam-camera-realsense-latest-aarch64.AppImage.StdOut pexec/managed_process.go:282 \_ [get_image] total: 19ms

Since we put PCD processing in the get_point_clouds method instead of the frame loop. It shouldn't mess with the performance of get_image or the frame loop (outside of general CPU/memory bottlenecks), but just in case I checked some of the debug spans and it looks 👍

@hexbabe hexbabe marked this pull request as ready for review June 18, 2024 16:36
@hexbabe hexbabe requested review from randhid, bhaney and seanavery June 18, 2024 16:36
@hexbabe hexbabe changed the title Add PCD support and organize encoding helpers [RSDK-7954] Add PCD support and organize encoding helpers Jun 18, 2024
return response;
}

std::vector<unsigned char> rsPointsToPCDBytes(const rs2::points& points, const rs2::frame& colorFrame) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] Do you have any resources/examples or more info on how the pcd transformation is done here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Seems great to have pointclouds native to the module now!

  • Makes sense that the get_point_cloud calls would not affect the performance of background image loop thread.
    • Looks like cpp sdk grpc stuff uses CompletionQueue async interface (ref), so long response times here should not affect anything on the main thread either.
  • Any info you have to help me grok rsPointsToPCDBytes helper addition would be awesome (Not up to speed yet with librealsense/pc formatting).

Copy link
Collaborator

@bhaney bhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition - we'll want to make sure that the points created by the function are actually scaled to real-world distances. Also the 4MB grpc message limit is just a default, it is not a real limit, you don't want to destroy data with no way of recovering it. Potentially could create a new optional config for scaling down point clouds, or telling the user to use a smaller resolution of image

src/encoding.hpp Outdated Show resolved Hide resolved
src/encoding.hpp Show resolved Hide resolved
src/camera_realsense.cpp Show resolved Hide resolved
Copy link
Contributor

@randhid randhid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few minor nits but this looks good to me!

src/encoding.hpp Outdated Show resolved Hide resolved
src/encoding.hpp Outdated Show resolved Hide resolved
@hexbabe hexbabe requested review from seanavery and bhaney June 20, 2024 16:57
.gitignore Outdated Show resolved Hide resolved
Copy link
Collaborator

@bhaney bhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Co-authored-by: randhid <[email protected]>
@hexbabe hexbabe merged commit d8a42bd into viam-modules:main Jun 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants