mohammedari / opengl_ros

A simple implementation to utilize OpenGL shader (GLSL) code with a GPU-powered machine under ROS environment
MIT License
10 stars 2 forks source link

Transparency in Images #1

Closed DanielArnett closed 4 years ago

DanielArnett commented 4 years ago

Hello, I'd like to add transparency to the images I publish from this node. How can I make that change?

Thank you!

DanielArnett commented 4 years ago

It turns out I successfully added transparency earlier, but that the ROS image viewer ignores the alpha channel. I just had to change CV_8UC3 to CV_8UC4, and GL_BGR to GL_BGRA.

For some reason though now when I pass an image topic with transparency into the node, I believe OpenGL doesn't recognize the transparency channel.

mohammedari commented 4 years ago

Thank you for using my code!

I think your change would work for alpha channel, but my current shader code does not take in account alpha channel for now. https://github.com/DanielArnett/opengl_ros/blob/7f1bebe2f990af0070322c3f1a51c57c06afadbd/opengl_ros/shader/fs_color_extraction.glsl#L66

Have you tried to change this line? I am out now, but i think i can test the code when i am back.

DanielArnett commented 4 years ago

Yes, I have gotten the shader to publish transparent images, however when I finished experimenting I could not get it to read transparent inputs to the shader. I will create a simple test so I can show you.

And thank you for making such a wonderful node! It's so fast and easy to use!

DanielArnett commented 4 years ago

I got the transparency fully working. The last thing I need to do to complete my project is to upload a second texture to the shader. Do you know how I can do this?

You can see in the below image I am creating two image topics with transparency. The image on the right is where I'm trying to blend the two images. This is where I'm trying to upload a second texture in the code, but I'm clearly not doing it the right way.

Screenshot from 2019-12-05 16-33-40

If you want to try it you can check out the image_blending branch of my code and run roslaunch opengl_ros transparency_test.launch.

mohammedari commented 4 years ago

Thank you for providing the code! and its nice to hear that alpha channel successfuly goes through to the shader!

For handling a second texture in the shader, you may need to

Cheers!

DanielArnett commented 4 years ago

It's working! Thank you so much! I have a bug where it crashes every 2nd or 3rd time I run it, but I can debug that. Thank you for your help with OpenGL, this will really help me develop shaders for computer vision.

Screenshot from 2019-12-06 15-35-18

If anyone stumbles across this here is the commit with blending.