Install opencv in termux

本文详细介绍了在Termux环境中安装Python和OpenCV的具体步骤,包括安装必要的开发工具和库,从Git克隆OpenCV,配置和构建OpenCV,以及在Python中测试OpenCV是否成功安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Refer to https://wiki.termux.com/wiki/Instructions_for_installing_python_packages#opencv
1. Install python3 and dev
     pkg install python python-dev
2. Install tools and libs
     pkg install libjpeg-turbo-dev libpng-dev cmake pkg-config
3. Clone opencv from git
    git clone https://github.com/opencv/opencv && cd opencv
4. Create build directory
     mkdir build && cd build
5. Configure
LDFLAGS=" -llog -lpython3" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DWITH_QT=OFF -DWITH_GTK=OFF ..
Don't missing the double dot at the end of command, It means start from the parent folder. After success, execute the following command:
     make
     make install
Please be noted that make will take a long time.
6. After installed, test it in python
     python
     >>> import cv2
     >>>cv2.__version__
    If no error it will print the version

Note: don'tt install python2, cmake will confuse with it and when import cv will face error.

Report issues at https://termux.dev/issues ~ $ # 安装核心依赖 pkg install python cmake make clang libjpeg-turbo libpng openblas -y pip install numpy # 获取 OpenCV 源码 git clone https://github.com/opencv/opencv git clone https://github.com/opencv/opencv_contrib # 配置编译参数 cd opencv && mkdir build && cd build cmake \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DBUILD_opencv_python3=ON \ -DPYTHON3_INCLUDE_DIR=$(python -c "import sysconfig;print(sysconfig.get_path('include'))") \ -DPYTHON3_LIBRARY=$(find $PREFIX/lib -name 'libpython3.*.so') \ -DPYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "import numpy;print(numpy.get_include())") \ -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \ -DWITH_OPENBLAS=ON \ FIX/lib/python3.*/site-packages/e-packages/cv2/*.so $PRE Checking availability of current mirror: [*] https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main: ok Reading package lists... Done Building dependency tree... Done Reading state information... Done E: Unable to locate package openblas Requirement already satisfied: numpy in /data/data/com.termux/files/usr/lib/python3.12/site-packages (2.2.5) fatal: destination path 'opencv' already exists and is not an empty directory. fatal: destination path 'opencv_contrib' already exists and is not an empty directory. mkdir: cannot create directory ‘build’: File exists CMake Warning: Ignoring extra path from command line: ".." CMake Error: The source directory "/data/data/com.termux/files/home" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. make: *** No targets specified and no makefile found. Stop. make: *** No rule to make target 'install'. Stop. ~/opencv
最新发布
07-01
~ $ pkg install python python-dev pkg install libjpeg-turbo-dev libpng-dev cmake pkg-config git clone https://github.com/opencv/opencv && cd opencv mkdir build && cd build # 安装proot pkg install proot # 进入管理员环境,用exit退出 termux-chroot LDFLAGS=" -llog -lpython3" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$PREFIX/local -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DOPENCV_EXTRA_MODULES=../modules -DPYTHON3_LIBRARIES=$PREFIX/lib/libpython3.so -DWITH_QT=OFF -DWITH_GTK=OFF .. make -j4 make install exit Checking availability of current mirror: [*] https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main: ok Reading package lists... Done Building dependency tree... Done Reading state information... Done Package python-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: python E: Package 'python-dev' has no installation candidate Checking availability of current mirror: [*] https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main: ok Reading package lists... Done Building dependency tree... Done Reading state information... Done Package libjpeg-turbo-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: libjpeg-turbo Package libpng-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: libpng E: Package 'libjpeg-turbo-dev' has no installation candidate E: Package 'libpng-dev' has no installation candidate The program git is not installed. Install it by executing: pkg install git Checking availability of current mirror: [*] https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main: ok Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libtalloc Suggested packages: proot-distro The following NEW packages will be installed: libtalloc proot 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 118 kB of archives. After this operation, 471 kB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable/main aarch64 libtalloc aarch64 2.4.2 [33.1 kB] Get:2 https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable/main aarch64 proot aarch64 5.1.107-65 [84.9 kB] Fetched 118 kB in 1s (126 kB/s) Selecting previously unselected package libtalloc. (Reading database ... 17171 files and directories currently installed.) Preparing to unpack .../libtalloc_2.4.2_aarch64.deb ... Unpacking libtalloc (2.4.2) ... Selecting previously unselected package proot. Preparing to unpack .../proot_5.1.107-65_aarch64.deb ... Unpacking proot (5.1.107-65) ... Setting up libtalloc (2.4.2) ... Setting up proot (5.1.107-65) ... ~ $
07-01
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值