loading opencv::mat images with alpha channel in opengl texture -


i want load opencv::mat images alpha channel opengl texture.

with of following posts manage load rgb images opengl texture opencv::mat.

https://stackoverflow.com/questions/16809833/opencv-image-loading-for-opengl-texture

https://stackoverflow.com/questions/9097756/converting-data-from-glreadpixels-to-opencvmat/9098883#9098883

but when try load image alpha channel, there problem.

here how glteximage2d function called.

glteximage2d(gl_texture_2d,     // type of texture                         0,                 // pyramid level (for mip-mapping) -                          gl_rgba,            // internal colour format convert                         image.cols,          // image width                           image.rows,          // image height                          0,                 // border width in pixels (can either 1 or 0)                         gl_bgra_integer, // input image format                          gl_unsigned_byte,  // image data type                         image.ptr());        // actual image data 

also, before rendering, enable blending using glenable(gl_blend);

if specifyinput image format , internal color format both gl_rgba / gl_bgra, segmentation fault, if set either of them or both of them gl_rgba_integer, @ least can see window, blank.

i can change transparency , accordingly window become more or less transparent, there no image in it. there image in cv::mat can see using cv::imshow, somehow there seems problem passing opengl texture.

could 1 suggest might missing. in advance.

p.s : new opengl, appreciate if explained smallest detail.. :p

i got working on computer, able load , display png texture.

the code in question adapted last answer in following link.

opencv image loading opengl texture

i post working code (also adapted code in aforementioned link) below

gluint texture;  cv::mat image = cv::imread("textures/trashbin.png", -1);  cv::flip(image, image, 0); glgentextures(1, &texture); glbindtexture(gl_texture_2d, texture);  gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_nearest); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear);  // set texture clamping method gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp);   glteximage2d(gl_texture_2d,     // type of texture     0,                 // pyramid level (for mip-mapping) - 0 top level     gl_rgba,            // internal colour format convert     image.cols,          // image width  i.e. 640 kinect in standard mode     image.rows,          // image height i.e. 480 kinect in standard mode     0,                 // border width in pixels (can either 1 or 0)     gl_bgra, // input image format (i.e. gl_rgb, gl_rgba, gl_bgr etc.)     gl_unsigned_byte,  // image data type     image.ptr()); 

pay attention 3 points:

  • the -1 in imread call @ second line. tells opencv load alpha channel. believe questioner had problem.
  • the gl_rgba , gl_bgra in last function call.
  • cv::flip(image, image, 0); not necesssary me, had commented out in project. reason might got uv coordinates flipped in first place.

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -