I'm using the latest Android OpenCV prebuilt SDK (4.3) to create a cpp shared library (cross compiling using the NDK r21) to use from the Dart FFI on Flutter to process the camera bytes.
I'm using the COLOR_YUV2RGBA_NV21 color transformation and it works great until the .so is built with any of the O flags turned on. If code optimization is turned on, then the returned image has flickery artifacts at the bottom and at the right of the image and the B and R channels are swapped.
If I compile the shared library for linux with OpenCV 4.2 and I open a (dumped frame) of the Android camera from a Main linked with the library, it also has the same issues. I'm using CMake with -DCMAKE_BUILD_TYPE=Release. RelWithDebInfo fails as well.
This is the CMakeLists.txt file to build the shared library:
This is the output image, weird green stripe at the bottom and it is red instead of blue. This is just a captured frame, but with the Android camera, the green stripe is flickering every frame, is not static.
I'm actually clueless on what could be wrong here.
Is it OpenCV? (It works fine with Debug type on both Android and Linux)
or
Am I building the shared library wrong and the compiler is optimizing out things that it should not?
Any help to know what could be going on here would be very appreciated.
Thank you.
I'm using the latest Android OpenCV prebuilt SDK (4.3) to create a cpp shared library (cross compiling using the NDK r21) to use from the Dart FFI on Flutter to process the camera bytes.
I'm using the
COLOR_YUV2RGBA_NV21
color transformation and it works great until the .so is built with any of the O flags turned on. If code optimization is turned on, then the returned image has flickery artifacts at the bottom and at the right of the image and the B and R channels are swapped.If I compile the shared library for linux with OpenCV 4.2 and I open a (dumped frame) of the Android camera from a Main linked with the library, it also has the same issues. I'm using CMake with
-DCMAKE_BUILD_TYPE=Release
.RelWithDebInfo
fails as well.This is the CMakeLists.txt file to build the shared library:
This is the output image, weird green stripe at the bottom and it is red instead of blue. This is just a captured frame, but with the Android camera, the green stripe is flickering every frame, is not static.
I'm actually clueless on what could be wrong here.
Any help to know what could be going on here would be very appreciated. Thank you.