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

CompressedImageMsg and alpha channels #169

Closed
laxnpander opened this issue May 29, 2017 · 5 comments
Closed

CompressedImageMsg and alpha channels #169

laxnpander opened this issue May 29, 2017 · 5 comments

Comments

@laxnpander
Copy link

Hey there,

after some tests I found out that the compressed image message does not support an alpha channel. At least it is cutting them off and sets everything to 255 when decoding. Is this on purpose?

Best regards,

Alex

@vrabaud
Copy link
Contributor

vrabaud commented Jun 5, 2017

what are you referring to here ? ImageTransport ? JPEG does not support alpha, PNG does.

@laxnpander
Copy link
Author

laxnpander commented Jun 8, 2017

I have this code snippet as example:

// Converting input image "pImg" to ros msg
sensor_msgs::ImagePtr imgMsg = cv_bridge::CvImage(header, "bgra8",
pImg).toCompressedImageMsg(cv_bridge::PNG);
// Converting ros msg back to cv::Mat
cv_bridge::CvImagePtr imgPtr = cv_bridge::toCvCopy(imgMsg, "bgra8");
cv::Mat img = imgPtr->image;
std::cout << "Value pimg: " << pImg.atcv::Vec4b(0, 0) << std::endl; // Outputs alpha 0
std::cout << "Value img: " << img.atcv::Vec4b(0, 0) << std::endl; // Outputs alpha 255

My pImg is the input 4 channel cv::Mat that is converted to a bgra8 image message. Afterwards it is getting reconverted into a cv::Mat. Value at point (0, 0) is then shown for both input and reconverted mat. Alpha channel is lost and set to 255. The same code works for "toImageMsg()".
Am I missing something?

@vrabaud vrabaud closed this as completed in 8c659ac Jun 8, 2017
@vrabaud
Copy link
Contributor

vrabaud commented Jun 8, 2017

Thx for reporting, please confirm that master works for you

vrabaud added a commit that referenced this issue Jun 8, 2017
@laxnpander
Copy link
Author

laxnpander commented Jun 9, 2017

Confirmed.

And thanks!

Edit: Ah, btw do you plan an update for ros indigo too?

@vrabaud
Copy link
Contributor

vrabaud commented Jun 13, 2017

Cool ! Yes, it got cherry-picked in Indigo: 87b9bba
I will make a release very soon: I am waiting for OpenCV 3.2.1 to be out this week and I'll release all of that together.

amiller27 pushed a commit to Pitt-RAS/vision_opencv that referenced this issue Dec 30, 2017
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

No branches or pull requests

2 participants