pythonjavaopencvgradlechaquopy

How to import opencv in Chaquopy python in android studio


In the build.grade(:app) I added numpy and it worked, But when I tried adding opencv (commented lines) the app didn't build.

        python {

            pip {
                install("numpy")
//                install("opencv-python==4.7.0.72")
//                install("opencv-python")
//                install("opencv-python-headless")

            }
        }

The error I got:

ERROR: Failed to install opencv-python-headless from https://files.pythonhosted.org/packages/2f/7e/d20f68a5f1487adf19d74378d349932a386b1ece3be9be9915e5986db468/opencv-python-headless-4.10.0.84.tar.gz#sha256=f2017c6101d7c2ef8d7bc3b414c37ff7f54d64413a1847d89970b6b7069b4e1a.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

-- Configuring incomplete, errors occurred!

...

-- Trying 'Ninja' generator - failure

...

-- Trying 'Unix Makefiles' generator

...

Chaquopy: Exit status 1

I run on Mac with M1.
I have:
cmake 3.30.1 already installed
xcode-select version 2403.

In the java code I also use opencv:

implementation 'com.quickbirdstudios:opencv-contrib:4.5.3.0'

Thank you


Solution

  • As you can see from the repository, Chaquopy only supports specific versions of OpenCV, and currently only on Python 3.8. See here for how to change the Python version of your app.