package/opencv: add python support
authorSamuel Martin <s.martin49@gmail.com>
Thu, 25 Jun 2015 19:59:49 +0000 (21:59 +0200)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Fri, 26 Jun 2015 18:44:29 +0000 (20:44 +0200)
opencv_python module needs python-numpy because it uses some numpy
headers in this wrapper.

>From its 2.4 release, OpenCV offers python bindings, but they required
most of the OpenCV modules to be enabled.

Since OpenCV-3.0.0, python bindings have been reworked:
- it now supports both python2 and python3
- only built modules supporting wrapped in python will be included in
  the bindings.

Signed-off-by: Samuel Martin <s.martin49@gmail.com>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
package/opencv/Config.in
package/opencv/opencv.mk

index 877ddda9122ab64510ec99eb5f2704325d260914..576f66787a67e47a967241975f1e1bcdbfc9f731 100644 (file)
@@ -85,7 +85,17 @@ config BR2_PACKAGE_OPENCV_LIB_PHOTO
          Include opencv_photo (computational photography) module into the OpenCV
          build.
 
-comment "opencv_python module requires numpy which is not yet available."
+config BR2_PACKAGE_OPENCV_LIB_PYTHON
+       bool "python"
+       depends on BR2_PACKAGE_PYTHON || BR2_PACKAGE_PYTHON3
+       depends on BR2_aarch64 || BR2_arm || BR2_armeb || BR2_i386 \
+               || BR2_mips || BR2_mipsel || BR2_powerpc || BR2_powerpc64 \
+               || BR2_sh || BR2_x86_64 # python-numpy
+       depends on !BR2_TOOLCHAIN_USES_UCLIBC || BR2_i386 || BR2_x86_64 # python-numpy
+       select BR2_PACKAGE_PYTHON_NUMPY
+       help
+         Include opencv_python module into the OpenCV build.
+         No python example is installed.
 
 config BR2_PACKAGE_OPENCV_LIB_SHAPE
        bool "shape"
index 7211c1845a45e0836d025b10940b30f87682e209..a43de0c6217f5a63a8e348d3e017324563ab52df 100644 (file)
@@ -78,8 +78,6 @@ OPENCV_CONF_OPTS += \
        -DBUILD_opencv_ml=$(if $(BR2_PACKAGE_OPENCV_LIB_ML),ON,OFF) \
        -DBUILD_opencv_objdetect=$(if $(BR2_PACKAGE_OPENCV_LIB_OBJDETECT),ON,OFF) \
        -DBUILD_opencv_photo=$(if $(BR2_PACKAGE_OPENCV_LIB_PHOTO),ON,OFF) \
-       -DBUILD_opencv_python2=OFF \
-       -DBUILD_opencv_python3=OFF \
        -DBUILD_opencv_shape=$(if $(BR2_PACKAGE_OPENCV_LIB_SHAPE),ON,OFF) \
        -DBUILD_opencv_stitching=$(if $(BR2_PACKAGE_OPENCV_LIB_STITCHING),ON,OFF) \
        -DBUILD_opencv_superres=$(if $(BR2_PACKAGE_OPENCV_LIB_SUPERRES),ON,OFF) \
@@ -282,6 +280,37 @@ else
 OPENCV_CONF_OPTS += -DWITH_V4L=OFF -DWITH_LIBV4L=OFF
 endif
 
+ifeq ($(BR2_PACKAGE_OPENCV_LIB_PYTHON),y)
+ifeq ($(BR2_PACKAGE_PYTHON),y)
+OPENCV_CONF_OPTS += \
+       -DBUILD_opencv_python2=ON \
+       -DBUILD_opencv_python3=OFF \
+       -DPYTHON2_EXECUTABLE=$(HOST_DIR)/usr/bin/python2 \
+       -DPYTHON2_INCLUDE_PATH=$(STAGING_DIR)/usr/include/python$(PYTHON_VERSION_MAJOR) \
+       -DPYTHON2_LIBRARIES=$(STAGING_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR).so \
+       -DPYTHON2_NUMPY_INCLUDE_DIRS=$(STAGING_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/numpy/core/include \
+       -DPYTHON2_PACKAGES_PATH=/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages \
+       -DPYTHON2_NUMPY_VERSION=$(PYTHON_NUMPY_VERSION)
+OPENCV_DEPENDENCIES += python
+else
+OPENCV_CONF_OPTS += \
+       -DBUILD_opencv_python2=OFF \
+       -DBUILD_opencv_python3=ON \
+       -DPYTHON3_EXECUTABLE=$(HOST_DIR)/usr/bin/python3 \
+       -DPYTHON3_INCLUDE_PATH=$(STAGING_DIR)/usr/include/python$(PYTHON3_VERSION_MAJOR)m \
+       -DPYTHON3_LIBRARIES=$(STAGING_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)m.so \
+       -DPYTHON3_NUMPY_INCLUDE_DIRS=$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages/numpy/core/include \
+       -DPYTHON3_PACKAGES_PATH=/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages \
+       -DPYTHON3_NUMPY_VERSION=$(PYTHON_NUMPY_VERSION)
+OPENCV_DEPENDENCIES += python3
+endif
+OPENCV_DEPENDENCIES += python-numpy
+else
+OPENCV_CONF_OPTS += \
+       -DBUILD_opencv_python2=OFF \
+       -DBUILD_opencv_python3=OFF
+endif
+
 # Installation hooks:
 define OPENCV_CLEAN_INSTALL_DOC
        $(RM) -fr $(TARGET_DIR)/usr/share/OpenCV/doc