Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Losing alpha channel when passing from Unity to OpenCV?

$
0
0
Hello, I'm trying to develop an educational application using Unity3d and OpenCV (c++ Dll). My problem is that when I pass an image from unity encoded in PNG (in BGRA32 textureFromat) to OpenCV, if i save the image through OpenCV it looks like alpha channel is removed. Alpha channel is critical in some 'heavy' OpenCV-side operations for my application and this removal is disastrous. This is what i get by saving the image from Unity (there is a transparent border) before sending it to OpenCV dll ![image description](http://i67.tinypic.com/2myrww1.png) This is what i get by saving the image from OpenCV ![image description](http://i67.tinypic.com/55md1w.png) Here is the relative portion of the c++ code public void saveIncomingImageArray(uchar * imMedium, int imMediumLength) { std::vector vectordataImMedium(imMedium, imMedium + imMediumLength); cv::Mat data_mat_medium(vectordataImMedium, true); mediumImage = cv::imdecode(data_mat_medium, CV_LOAD_IMAGE_UNCHANGED); cv::imwrite("From Opencv1_medium.png", mediumImage, compression_params); } compression_params are defined just before the saveIncomingImageArray function and here is the c# code respectful //Create a texture2D to pass data from rendertexture with BGRA32 format Texture2D textMedium = new Texture2D(rtMedium.width, rtMedium.height, TextureFormat.BGRA32, false); textMedium.alphaIsTransparency = true; textMedium.Apply(); //fill texture2D with data from rendertexture - function defined in my code elsewhere RenderTextureToTexture2D(ref rtMedium, ref textMedium); //create the array to pass to OpenCV byte[] imageMedium = textMedium.EncodeToPNG(); I think I need some help or some guidance, Thank you.

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>