install opencv with linux

本文档详细介绍了如何在Ubuntu 10.04及其它发行版上从源码编译安装OpenCV的过程。包括所需依赖包的安装、获取OpenCV源码、使用CMake配置与构建OpenCV等步骤。

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

The following steps have been tested for Ubuntu 10.04 but should work with other distros as well.

Required Packages

  • GCC 4.4.x or later
  • CMake 2.8.7 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
  • [optional] CUDA Toolkit 6.5 or higher

The packages can be installed using a terminal and the following commands or by using Synaptic Manager:

[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Getting OpenCV Source Code

You can use the latest stable OpenCV version or you can grab the latest snapshot from our Git repository.

Getting the Latest Stable OpenCV Version

Getting the Cutting-edge OpenCV from the Git Repository

Launch Git client and clone OpenCV repository. If you need modules from OpenCV contrib repository then clone it as well.

For example

cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

Building OpenCV from Source Using CMake

  1. Create a temporary directory, which we denote as <cmake_build_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.

    For example

    cd ~/opencv
    mkdir build
    cd build
  2. Configuring. Run cmake [<some optional parameters>] <path to the OpenCV source directory>

    For example

    cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

    or cmake-gui

    • set full path to OpenCV source code, e.g. /home/user/opencv
    • set full path to <cmake_build_dir>, e.g. /home/user/opencv/build
    • set optional parameters
    • run: “Configure”
    • run: “Generate”
    Note
    Use  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. , without spaces after -D if the above example doesn't work.
  3. Description of some parameters
    • build type: CMAKE_BUILD_TYPE=Release\Debug
    • to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to <path to opencv_contrib/modules/>
    • set BUILD_DOCS for building documents
    • set BUILD_EXAMPLES to build all examples
  4. [optional] Building python. Set the following python parameters:
    • PYTHON2(3)_EXECUTABLE = <path to python>
    • PYTHON_INCLUDE_DIR = /usr/include/python<version>
    • PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python<version>
    • PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython<version>.so
    • PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python<version>/dist-packages/numpy/core/include/
  5. [optional] Building java.
    • Unset parameter: BUILD_SHARED_LIBS
    • It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all will be statically linked with OpenCV and can take a lot of memory.
  6. Build. From build directory execute make, it is recommended to do this in several threads

    For example

    make -j7 # runs 7 jobs in parallel
  7. [optional] Building documents. Enter <cmake_build_dir/doc/> and run make with target "html_docs"

    For example

    cd ~/opencv/build/doc/
    make -j7 html_docs
  8. To install libraries, execute the following command from build directory
    sudo make install
  9. [optional] Running tests

    For example

    git clone https://github.com/opencv/opencv_extra.git
    • set OPENCV_TEST_DATA_PATH environment variable to <path to opencv_extra/testdata>.
    • execute tests from build directory.

    For example

    <cmake_build_dir>/bin/opencv_test_core
Note
If the size of the created library is a critical issue (like in case of an Android build) you can use the install/strip command to get the smallest size possible. The  stripped version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter.
<think>好的,用户想在RK3588平台上通过pip3安装OpenCV库。首先,我需要确认RK3588的架构和操作系统。RK3588是ARM架构的处理器,通常运行Linux系统,比如Ubuntu或Debian。 接下来,用户想用pip3安装,但OpenCV的官方Python包叫opencv-python,不过这个包主要是为x86架构预编译的,可能不支持ARM架构。直接安装可能会遇到兼容性问题或者找不到合适的版本。 我需要检查是否有适用于ARM的预编译版本。opencv-python-headless可能是一个选项,但同样可能不支持ARM。用户可能需要从源代码编译,但编译OpenCV在ARM设备上可能比较耗时,且需要安装依赖库。 另一个可能性是使用conda或其他包管理器,但用户明确要求用pip3。可能需要参考之前提到的自定义安装OpenCV的方法,比如在CMake中指定路径,但用户这里的问题是通过pip安装,可能需要其他解决方案。 另外,用户之前提到过在CMakeLists中添加自定义OpenCV库,所以如果pip安装失败,可能需要手动编译安装,然后确保Python能找到这个库。或者,是否存在第三方提供的预编译ARM版本的opencv-python包,比如通过piwheels或者其他ARM优化的仓库。 可能需要建议用户尝试安装opencv-python-headless,如果失败的话,再考虑从源码编译,或者寻找社区提供的适用于RK3588的wheel文件。此外,安装必要的依赖库如libopencv-dev可能也是必须的步骤。 总结步骤:1. 尝试pip安装opencv-python-headless;2. 如果失败,手动编译安装;3. 确保系统依赖已安装;4. 验证安装。同时提醒用户注意ARM架构的兼容性问题。</think>在RK3588(基于ARM架构)平台上通过pip3安装OpenCV的步骤如下: ### 一、基础安装尝试 1. **直接安装预编译包** 尝试安装轻量版: ```bash pip3 install opencv-python-headless ``` *注意:官方预编译包主要面向x86架构,ARM架构可能提示兼容性问题*[^1] ### 二、ARM架构适配方案 2. **使用ARM优化版本** 针对RK3588的ARMv8架构,可尝试社区维护的兼容版本: ```bash pip3 install opencv-python-headless --pre --extra-index-url https://snapshots.linaro.org/ldcg/python/opencv/ ``` 3. **手动编译安装**(推荐可靠方案) ```bash # 安装编译依赖 sudo apt-get update && sudo apt-get install -y \ cmake build-essential python3-dev \ libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev # 下载源码 git clone --depth 1 --branch 4.9.0 https://github.com/opencv/opencv.git cd opencv && mkdir build && cd build # 配置编译参数 cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_GTK=ON \ -D BUILD_opencv_python3=ON \ .. # 编译安装(RK3588建议使用-j4加速) make -j4 && sudo make install ``` ### 三、验证安装 ```python import cv2 print(cv2.__version__) # 应输出4.9.0等版本号 ``` ### 四、常见问题处理 - **ImportError: libGL.so.1** 安装缺失依赖: ```bash sudo apt install libgl1-mesa-glx ``` - **CUDA加速支持** 需先安装NVIDIA JetPack SDK(需确认RK3588具体开发板支持情况)[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值