Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Enable to publish JPEG images without image decompression on the host #77

Merged
merged 5 commits into from
Oct 8, 2019

Conversation

shuntaraw
Copy link
Contributor

@shuntaraw shuntaraw commented Sep 18, 2019

Enable to publish JPEG image at rgb/image_raw/compressed so that clients can subscribe to the compressed image at rgb/image_raw via compressed_image_transport. This feature is useful when the images are received/consumed by remote clients and the local host is not powerful enough to decompress the JPEG images.

Fixes #20

Description of the changes:

This PR implements the technique described in the following site. http://wiki.ros.org/compressed_image_transport#Publishing_compressed_images_directly

  • Add color_format ROS param to enable publishing JPEG images without image decompression on the host computer.
  • If color_format is jpeg,
    • JPEG images are published at /rgb/image_raw/compressed
    • /rgb/image_raw is not advertised (to avoid confusion).
    • /rgb_to_depth/image_raw does not publish.
    • rgb_point_cloud ROS param must be false.

Before submitting a Pull Request:

I tested changes on:

  • Windows
  • Linux

manual/ad-hoc testing

@shuntaraw shuntaraw changed the title Enable to publish JPEG image via compressed image transport without d… Enable to publish JPEG images via compressed image transport Sep 18, 2019
@shuntaraw shuntaraw changed the title Enable to publish JPEG images via compressed image transport Enable to publish JPEG images without image decompression on the host Sep 18, 2019
@RoseFlunder
Copy link
Contributor

RoseFlunder commented Sep 18, 2019

I don't have a device here at the moment, but did you check if everything works with jpeg color format and rgb point cloud?
Because on the first glance I see a potential problem at the rgb point cloud there:

const size_t point_count = k4a_bgra_frame.get_size() / sizeof(BgraPixel);

This check will fail with color format jpeg I think.
Later on at the point cloud generation you need distinct values for Red, Green, Blue.
Thats difficult with jpeg color format I guess. Because of that I turned on conversion to BGRA when using recording files.

@shuntaraw
Copy link
Contributor Author

shuntaraw commented Sep 19, 2019

@RoseFlunder Nice catch! Please take a look at the updated PR. I confirmed that the following topics work as expected with color_format=jpeg. The default setting color_format=bgra does not change the behavior.

/depth/camera_info
/depth/image_raw
/depth_to_rgb/camera_info
/depth_to_rgb/image_raw
/imu
/ir/camera_info
/ir/image_raw
/joint_states
/points2
/rgb/camera_info
/rgb/image_raw/compressed

Copy link
Contributor

@RoseFlunder RoseFlunder left a comment

Choose a reason for hiding this comment

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

Another questions is how to handle the parameter when opening a recording file?
Whats the expected behaviour?
At the moment we always enable conversion to bgra.

We could use this setting to decide wether to enable color conversion to bgra or not.
If set to bgra we enable color conversion.
If set to jpeg and the recordings color Format is jpeg, we do not enable color conversion.

This is the logic that needs to be changed:
https://github.com/shuntaraw/Azure_Kinect_ROS_Driver/blob/f7f1cf98adb4c1168615b6c1a4ea02742fd487ba/src/k4a_ros_device.cpp

@shuntaraw
Copy link
Contributor Author

shuntaraw commented Sep 19, 2019

@RoseFlunder Thanks for pointing this out. I will address this issue shortly.

@shuntaraw
Copy link
Contributor Author

shuntaraw commented Sep 19, 2019

Apparently, the color format in a recorded file is either MJPG, NV12, or YUV2. Since the SDK does not support the conversion to MJPG, the logic implemented here is as follows:

  • when JPEG is requested
    • if recorded image is JPEG, it is published.
    • otherwise the image is converted to BGRA and a warning is printed.
  • when BGRA is requested
    • the image is converted to BGRA and then published.

I've tested this PR with the files recorded in MJPG, NV12, and YUV2.

@RoseFlunder
Copy link
Contributor

Looks fine to me.
I more question:
Whats about the rectified color image when using jpeg?
I see that there is a rectified version for the bgra option in the code but not for the jpeg version.
Is it not possible?

@shuntaraw
Copy link
Contributor Author

shuntaraw commented Sep 20, 2019

@RoseFlunder As mentioned in the "description of the changes", /rgb_to_depth/image_raw is advertised but does not publish anything. I believe it is impossible to rectify the image without having an RGB pixel array.

src/k4a_ros_device.cpp Outdated Show resolved Hide resolved
src/k4a_ros_device.cpp Show resolved Hide resolved
@shuntaraw
Copy link
Contributor Author

@skalldri will you merge this?

@ooeygui
Copy link
Member

ooeygui commented Oct 8, 2019

@shuntaraw I'm doing a quick local validation and will merge.

@ooeygui
Copy link
Member

ooeygui commented Oct 8, 2019

Confirmed on Windows

@ooeygui ooeygui merged commit 8a2e8cd into microsoft:melodic Oct 8, 2019
@shuntaraw shuntaraw deleted the jpeg branch October 8, 2019 20:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish JPEG images instead of BGRA
4 participants