Hello, I'm trying to develop an educational application using Unity3d and OpenCV (c++ Dll). My problem is that if 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)
This is what i get by saving the image from OpenCV
Here is the relative portion of the c++ code
public void (uchar imMedium, int imMediumLength) {
std::vector<uchar> 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);
} 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
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.