Support python3-opencv 92/256892/2 accepted/tizen/unified/20210415.100509 submit/tizen/20210414.101645
authorTae-Young Chung <ty83.chung@samsung.com>
Wed, 14 Apr 2021 07:58:46 +0000 (16:58 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Wed, 14 Apr 2021 08:34:28 +0000 (17:34 +0900)
This patch enable python3 in opencv and
generates python3-opencv package.

To use python3-opencv, opencv should be installed together.

Change-Id: I1c2df0f9ee081aac04d355f113cc0608e6eda1ef
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
packaging/1001-TIZEN-OPENCV-PYTHON3-LIB64-PATH.patch [new file with mode: 0644]
packaging/opencv.spec

diff --git a/packaging/1001-TIZEN-OPENCV-PYTHON3-LIB64-PATH.patch b/packaging/1001-TIZEN-OPENCV-PYTHON3-LIB64-PATH.patch
new file mode 100644 (file)
index 0000000..dd963c5
--- /dev/null
@@ -0,0 +1,17 @@
+diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake
+index 4ff02a77d3..c27fe7d316 100644
+--- a/cmake/OpenCVDetectPython.cmake
++++ b/cmake/OpenCVDetectPython.cmake
+@@ -186,7 +186,11 @@ if(NOT ${found})
+         else() #debian based assumed, install to the dist-packages.
+           set(_packages_path "python${_version_major_minor}/dist-packages")
+         endif()
+-        set(_packages_path "lib/${_packages_path}")
++        if(EXISTS /usr/lib64)
++            set(_packages_path "lib64/${_packages_path}")
++        else()
++            set(_packages_path "lib/${_packages_path}")
++        endif()
+       elseif(CMAKE_HOST_WIN32)
+         get_filename_component(_path "${_executable}" PATH)
+         file(TO_CMAKE_PATH "${_path}" _path)
index 28a0618..2c0c875 100644 (file)
@@ -1,11 +1,17 @@
 Name: opencv
 Summary: OpenCV library
 Version: 4.5.0
-Release: 0
+Release: 1
 Group: Development/Libraries
 License: Apache-2.0 and BSD-3-Clause
 Source0: %{name}-%{version}.tar.gz
 Source100: opencv-contrib-4.5.0.tar.gz
+# In cmake/OpenCVDetectPython.cmake, python packages are installed
+# in lib/ regardless of i586, armv7l, x86_64, aarch64
+# So, this patch installs the python packages in:
+# lib64/ if x86_64 or aarch64
+# lib/ if i586 or armv7l
+Source1001: 1001-TIZEN-OPENCV-PYTHON3-LIB64-PATH.patch
 
 BuildRequires:  cmake
 BuildRequires:  pkg-config
@@ -19,7 +25,9 @@ BuildRequires:  libavutil-devel
 BuildRequires:  libavcodec-devel
 BuildRequires:  libavformat-devel
 BuildRequires:  libswscale-devel
-
+#support python3
+BuildRequires:  python3-devel
+BuildRequires:  python3-numpy-devel
 
 Requires(post):  /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
@@ -35,10 +43,21 @@ Requires:    %{name} = %{version}-%{release}
 %description devel
 The Open Computer Vision Library (Dev) includes various algorithms for computer vision problems.
 
+%package -n python3-opencv
+Summary:    OpenCV Python3 Library
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+
+%description -n python3-opencv
+The Open Computer Vision Library (Python3) includes various algorithms for computre vision problems.
+
 %prep
 %setup -q
 %setup -q -T -D -a 100
 
+cp %{SOURCE1001} .
+patch -p1 < %{SOURCE1001}
+
 %build
 %ifarch aarch64
 ARCH=aarch64
@@ -80,7 +99,7 @@ cmake .. -DCMAKE_INSTALL_PREFIX=/usr \
        -DBUILD_opencv_objdetect=ON \
        -DBUILD_opencv_photo=ON \
        -DBUILD_opencv_python2=OFF \
-       -DBUILD_opencv_python3=OFF \
+       -DBUILD_opencv_python3=ON \
        -DBUILD_opencv_shape=OFF \
        -DBUILD_opencv_stitching=OFF \
        -DBUILD_opencv_superres=OFF \
@@ -89,7 +108,6 @@ cmake .. -DCMAKE_INSTALL_PREFIX=/usr \
        -DBUILD_opencv_videoio=ON \
        -DBUILD_opencv_videostab=OFF \
        -DBUILD_opencv_world=OFF \
-       -DBUILD_opencv_python=OFF \
        -DBUILD_opencv_viz=OFF \
        -DOPENCV_EXTRA_MODULES_PATH=../opencv-contrib/modules \
        -DBUILD_opencv_aruco=OFF \
@@ -283,6 +301,10 @@ fi
 %exclude /usr/share/opencv4/lbpcascades/*silverware*
 %exclude /usr/share/opencv4/*.supp
 
+%files -n python3-opencv
+%{python3_sitearch}/cv2/*.py
+%{python3_sitearch}/cv2/*/*.so
+
 %files devel
 /usr/include/*
 %{_libdir}/pkgconfig/*.pc