Repository: kivy/python-for-android

Issue:
My despair at trying to simply import the opencv face class (python-for-android) 
I've been trying this for weeks, I was told it would be straightforward and that if I wanted to import the face class I could simply "add that option to the recipe".  But this is somehow starting to seem more difficult than I first thought. Has anyone ever managed to compile any of the extra modules (contrib) through p4a by changing the opencv recipe? If this is indeed too difficult, could I use pyjnius, as only 10 lines of code in my entire app is dedicated to detecting facial landmarks.


Discussion:

Resolving patch:
diff --git a/pythonforandroid/recipes/opencv/__init__.py b/pythonforandroid/recipes/opencv/__init__.py
--- a/pythonforandroid/recipes/opencv/__init__.py
+++ b/pythonforandroid/recipes/opencv/__init__.py
@@ -31,7 +31,7 @@ class OpenCVRecipe(NDKRecipe):
         'libopencv_video.so',
         'libopencv_dnn.so',
         'libopencv_imgcodecs.so',
-        'libopencv_photo.so'
+        'libopencv_photo.so',
     ]
 
     def get_lib_dir(self, arch):
@@ -46,6 +46,16 @@ def get_recipe_env(self, arch):
     def build_arch(self, arch):
         build_dir = join(self.get_build_dir(arch.arch), 'build')
         shprint(sh.mkdir, '-p', build_dir)
+
+        opencv_extras = []
+        if 'opencv_extras' in self.ctx.recipe_build_order:
+            opencv_extras_dir = self.get_recipe(
+                'opencv_extras', self.ctx).get_build_dir(arch.arch)
+            opencv_extras = [
+                f'-DOPENCV_EXTRA_MODULES_PATH={opencv_extras_dir}/modules',
+                '-DBUILD_opencv_legacy=OFF',
+            ]
+
         with current_directory(build_dir):
             env = self.get_recipe_env(arch)
 
@@ -120,6 +130,8 @@ def build_arch(self, arch):
                     '-DPYTHON{major}_PACKAGES_PATH={site_packages}'.format(
                         major=python_major, site_packages=python_site_packages),
 
+                    *opencv_extras,
+
                     self.get_build_dir(arch.arch),
                     _env=env)
             shprint(sh.make, '-j' + str(cpu_count()), 'opencv_python' + python_major)
diff --git a/pythonforandroid/recipes/opencv_extras/__init__.py b/pythonforandroid/recipes/opencv_extras/__init__.py
new file mode 100644
--- /dev/null
+++ b/pythonforandroid/recipes/opencv_extras/__init__.py
@@ -0,0 +1,23 @@
+from pythonforandroid.recipe import Recipe
+
+
+class OpenCVExtrasRecipe(Recipe):
+    """
+    OpenCV extras recipe allows us to build extra modules from the
+    `opencv_contrib` repository. It depends on opencv recipe and all the build
+    of the modules will be performed inside opencv recipe build directory.
+
+    .. note:: the version of this recipe should be the same than opencv recipe.
+
+    .. warning:: Be aware that these modules are experimental, some of them
+        maybe included in opencv future releases and removed from extras.
+
+    .. seealso:: https://github.com/opencv/opencv_contrib
+
+    """
+    version = '4.0.1'
+    url = 'https://github.com/opencv/opencv_contrib/archive/{version}.zip'
+    depends = ['opencv']
+
+
+recipe = OpenCVExtrasRecipe()


Test patch: