1.环境
-
OS: Ubuntu18.04 / Debian 10
-
OpenCV version: 3.4.15
-
Board: RK3399
2.编译和安装
-
搭建python3.7虚拟环境
# 依次安装gcc和cmake等编译环境 # 安装python3.7-tk 和 python3.7-dev # 安装virtualenv虚拟环境 sudo apt install gcc cmake git build-essential \ python3-tk python3.7-dev \ virtualenv
-
创建python3.7虚拟环境
virtualenv -p /usr/bin/python3.7m /home/firefly/venv # 使用虚拟环境,如果想退出可以在终端输入 deactivate source /home/firefly/venv/bin/activate
-
安装Opencv所需的环境包
# 安装编译环境、gtk包和相关编解码库 sudo apt install cmake build-essential libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libjasper-dev # 注意!如果安装了rknn_toolkit(or lite)则不需要再安装Python-numpy,否则会导致rknn_toolkit(or lite)无法使用 sudo apt install python-numpy
-
下载Opencv
# 创建文件夹 mkdir opencv cd opencv # 下载 opencv-3.4.15.zip wget https://github.com/opencv/opencv/archive/refs/tags/3.4.15.zip unzip opencv-3.4.15.zip
-
配置
mkdir build cd build # 让 OpenCV 和 Python3 之间建立联系 cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D PYTHON_DEFAULT_EXECUTABLE=$(python -c "import sys; print(sys.executable)")\ -D PYTHON3_EXECUTABLE=$(python -c "import sys; print(sys.executable)") \ -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "import numpy; print (numpy.get_include())") \ -D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ ../opencv-3.4.15
-
如需支持Gstreamer API,则进行以下配置操作否则跳过
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev cmake -D WITH_GSTREAMER=ON ../opencv-3.4.15
-
编译安装# 如果板子内存不超过2G,建议不超过-j4
make -j6 # 安装的过程需要sudo权限 sudo make install