diff --git a/pythonforandroid/recipes/opencv/__init__.py b/pythonforandroid/recipes/opencv/__init__.py index a57089920f..a90ddda925 100644 --- 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 index 0000000000..c63d8da55b --- /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()