- Home /
OpenCVForUnity Core.Flip function not working in Unity Android Build
I've been having this problem for a while now and it doesn't seem to be answered in other similar questions.
I'm trying to use OpenCV to show a preview of an android phones front facing camera on a webcamtexture object. In Unity, the OpenCV code works fine. There are if statements in the code that will flip the camera accordingly so that it isn't mirrored or flipped in weird ways. However, on Android, the preview is flipped 90 degrees and my if statements to flip it to normal don't do anything. In order to fix what the webcam texture orientation shows you, I use Core.flip on Mat rgba object.
if (webCamDevice.isFrontFacing)
{
if (webCamTexture.videoRotationAngle == 0)
{
Core.flip(rgbaMat, rgbaMat, 1);
}
else if (webCamTexture.videoRotationAngle == 90)
{
Core.flip(rgbaMat, rgbaMat, 0);
}
else if (webCamTexture.videoRotationAngle == 270)
{
Core.flip(rgbaMat, rgbaMat, 1);
}
}
This Mat object has a variable called nativeObj which is of type intptr. In Unity, this pointer is a positive number, but in Android, it's negative which is what I believe is causing the error (I don't think it's pointing to anything. Does anyone know why this pointer could be negative in Android? Could it be because of how Unity compresses all the files into the .apk file when it builds? if so is there a way to give OpenCV access to the files it needs (although I'm not sure where it's actually storing everything (I'm still new to using OpenCV).
Thank you in advance.