Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv: Build Python bindings #9369

Merged
merged 1 commit into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions packages/opencv/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ TERMUX_PKG_HOMEPAGE=https://opencv.org/
TERMUX_PKG_DESCRIPTION="Open Source Computer Vision Library"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=4.5.5
TERMUX_PKG_SRCURL=https://github.com/opencv/opencv/archive/${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=a1cfdcf6619387ca9e232687504da996aaa9f7b5689986b8331ec02cb61d28ad
TERMUX_PKG_VERSION=(4.5.5)
TERMUX_PKG_VERSION+=(1.22.3) # NumPy version
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=(https://github.com/opencv/opencv/archive/${TERMUX_PKG_VERSION}.tar.gz
https://github.com/numpy/numpy/archive/refs/tags/v${TERMUX_PKG_VERSION[1]}.tar.gz)
TERMUX_PKG_SHA256=(a1cfdcf6619387ca9e232687504da996aaa9f7b5689986b8331ec02cb61d28ad
c8f3ec591e3f17b939220f2b9eabb4c5e2db330f8af62c0a3aeee8a4d1a6c0db)
TERMUX_PKG_DEPENDS="libc++, libjpeg-turbo, libpng, libprotobuf, libtiff, libwebp, openjpeg, openjpeg-tools, zlib"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DANDROID_NO_TERMUX=OFF
Expand All @@ -13,6 +17,10 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DPROTOBUF_UPDATE_FILES=ON
"

termux_step_post_get_source() {
mv numpy-${TERMUX_PKG_VERSION[1]} numpy
}

termux_step_pre_configure() {
termux_setup_protobuf

Expand All @@ -35,6 +43,27 @@ termux_step_pre_configure() {
_NEED_DUMMY_LIBRT_A=true
echo '!<arch>' > $_LIBRT_A
fi

# For Python bindings
_PYTHON_VERSION=$(. $TERMUX_SCRIPTDIR/packages/python/build.sh; echo $_MAJOR_VERSION)
termux_setup_python_crossenv
pushd $TERMUX_PYTHON_CROSSENV_SRCDIR
_CROSSENV_PREFIX=$TERMUX_PKG_BUILDDIR/python-crossenv-prefix
python${_PYTHON_VERSION} -m crossenv \
$TERMUX_PREFIX/bin/python${_PYTHON_VERSION} \
${_CROSSENV_PREFIX}
popd
. ${_CROSSENV_PREFIX}/bin/activate
LDFLAGS+=" -lpython${_PYTHON_VERSION}"
export NPY_DISABLE_SVML=1
pushd $TERMUX_PKG_SRCDIR/numpy
pip install .
popd
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+="
-DPYTHON_DEFAULT_EXECUTABLE=python
-DPYTHON3_INCLUDE_PATH=$TERMUX_PREFIX/include/python${_PYTHON_VERSION}
-DPYTHON3_NUMPY_INCLUDE_DIRS=${_CROSSENV_PREFIX}/cross/lib/python${_PYTHON_VERSION}/site-packages/numpy/core/include
"
}

termux_step_post_make_install() {
Expand Down
8 changes: 8 additions & 0 deletions packages/opencv/opencv-python.subpackage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TERMUX_SUBPKG_INCLUDE="lib/python*"
TERMUX_SUBPKG_DESCRIPTION="Python bindings for OpenCV"
TERMUX_SUBPKG_DEPENDS="python"

termux_step_create_subpkg_debscripts() {
echo "#!$TERMUX_PREFIX/bin/sh" > postinst
echo "pip3 install numpy" >> postinst
}