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

add MONO16 / GRAY16_LE support #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ This can be run as both a node and a nodelet.
* `~frame_id`: The [TF](http://www.ros.org/wiki/tf) frame ID.
* `~reopen_on_eof`: Re-open the stream if it ends (EOF).
* `~sync_sink`: Synchronize the app sink (sometimes setting this to `false` can resolve problems with sub-par framerates).
* `~image_encoding`: Encoding of the stream. Can be {`rgb8`,`mono8`,`mono16`}. Defaults to `rgb8`.

C++ API (unstable)
------------------
Expand Down
36 changes: 28 additions & 8 deletions src/gscam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace gscam {
nh_private_.param("image_encoding", image_encoding_, sensor_msgs::image_encodings::RGB8);
if (image_encoding_ != sensor_msgs::image_encodings::RGB8 &&
image_encoding_ != sensor_msgs::image_encodings::MONO8 &&
image_encoding_ != sensor_msgs::image_encodings::MONO16 &&
image_encoding_ != "jpeg") {
ROS_FATAL_STREAM("Unsupported image encoding: " + image_encoding_);
}
Expand Down Expand Up @@ -139,6 +140,10 @@ namespace gscam {
caps = gst_caps_new_simple( "video/x-raw",
"format", G_TYPE_STRING, "GRAY8",
NULL);
} else if (image_encoding_ == sensor_msgs::image_encodings::MONO16) {
caps = gst_caps_new_simple( "video/x-raw",
"format", G_TYPE_STRING, "GRAY16_LE",
NULL);
} else if (image_encoding_ == "jpeg") {
caps = gst_caps_new_simple("image/jpeg", NULL, NULL);
}
Expand All @@ -147,6 +152,11 @@ namespace gscam {
caps = gst_caps_new_simple( "video/x-raw-rgb", NULL,NULL);
} else if (image_encoding_ == sensor_msgs::image_encodings::MONO8) {
caps = gst_caps_new_simple("video/x-raw-gray", NULL, NULL);
} else if (image_encoding_ == sensor_msgs::image_encodings::MONO16) {
Copy link
Author

@julled julled Dec 23, 2020

Choose a reason for hiding this comment

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

this stuff related to gst 0.1 is untested

caps = gst_caps_new_simple("video/x-raw-gray",
"bpp", G_TYPE_INT,16,
"depth", G_TYPE_INT,16,
"endianness", G_TYPE_INT,1234, NULL);
} else if (image_encoding_ == "jpeg") {
caps = gst_caps_new_simple("image/jpeg", NULL, NULL);
}
Expand Down Expand Up @@ -346,10 +356,16 @@ namespace gscam {
cinfo_pub_.publish(cinfo);
} else {
// Complain if the returned buffer is smaller than we expect
const unsigned int expected_frame_size =
image_encoding_ == sensor_msgs::image_encodings::RGB8
? width_ * height_ * 3
: width_ * height_;
unsigned int expected_frame_size;
if(image_encoding_ == sensor_msgs::image_encodings::RGB8){
expected_frame_size = width_ * height_ * 3;
}
else if ( image_encoding_ == sensor_msgs::image_encodings::MONO8) {
expected_frame_size = width_ * height_;
}
else if ( image_encoding_ == sensor_msgs::image_encodings::MONO16) {
expected_frame_size = width_ * height_ * 2;
}

if (buf_size < expected_frame_size) {
ROS_WARN_STREAM( "GStreamer image buffer underflow: Expected frame to be "
Expand All @@ -372,10 +388,14 @@ namespace gscam {
// Copy only the data we received
// Since we're publishing shared pointers, we need to copy the image so
// we can free the buffer allocated by gstreamer
if (image_encoding_ == sensor_msgs::image_encodings::RGB8) {
img->step = width_ * 3;
} else {
img->step = width_;
if(image_encoding_ == sensor_msgs::image_encodings::RGB8){
img->step = width_ * 3;
}
else if ( image_encoding_ == sensor_msgs::image_encodings::MONO8) {
img->step = width_;
}
else if ( image_encoding_ == sensor_msgs::image_encodings::MONO16) {
img->step = width_ * 2;
}
std::copy(
buf_data,
Expand Down