• OS: Debian 11
• OpenCV version: 4.6.0
• Board: RK3588
1. 搭建python3.9虚拟环境***
#依次安装gcc和cmake等编译环境
#安装python3.9-tk 和 python3.9-dev
#安装virtualenv虚拟环境
sudo apt install gcc cmake git build-essential \
python3-tk python3.9-dev \
virtualenv
2. 创建python3.9虚拟环境
virtualenv -p /usr/bin/python3.7m /home/firefly/venv
#使用虚拟环境,如果想退出可以在终端输入 deactivate
source /home/firefly/venv/bin/activate
3.安装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
安装libjasper-dev会报错 找不到包 解决方案换源
直接编辑/etc/apt/sources.list文件(需要使用 sudo):
将原文件做备份
sudo cp /etc/apt/sources.list /etc/apt/sources_copy.list
sudo gedit /etc/apt/sources.list
将文件中的内容删除,将镜像源复制到里面。
sudo apt-get update
ARM架构的18.04 ,解决是靠全部更改为老版本的清华源 替换原有 /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
sudo apt update
apt install libjasper1 libjasper-dev
#注意!如果安装了rknn_toolkit(or lite)则不需要再安装Python-numpy,否则会导致rknn_toolkit(or lite)无法使用
sudo apt install python-numpy
安装python-numpy会报错用aptitude安装且改成python3
sudo aptitude install python3-numpy
opencv下载地址:Releases - OpenCV
opencv_contrib下载地址:GitHub - opencv/opencv_contrib: Repository for OpenCV’s extra modules
其中,opencv_contrib的版本要与opencv的版本一致。本文采用opencv4.6.0、opencv_contrib4.x
解压opencv-4.6.0和contrib 放入同一目录,解压完的文件为opencv-4.6.0 改为opencv
mv opencv-4.6.0 opencv
mkdir build
在opencv文件夹下,新建build文件夹
进入BUILD进行编译,主要是为了让生成的文件放到一个文件夹下方便管理
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules/ .. -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D WITH_CUDA=ON
如需支持Gstreamer API,则进行以下配置操作否则跳过
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
cmake -D WITH_GSTREAMER=ON …
#如果板子内存不超过2G,建议不超过-j4
make -j6
如果出现C++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
适当调小线程 make -j4 或j2 直至编译完成
#安装的过程需要sudo权限
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
//打开后可能是空文件,在文件内容最后添加
/usr/local/lib
sudo ldconfig
//在末尾添加以下两行
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
sudo -s
source /etc/bash.bashrc
//**配置然后更新database
sudo updatedb
https://blog.csdn.net/kangzhaofang/article/details/127647214
https://blog.csdn.net/u011622208/article/details/105252720
https://wiki.t-firefly.com/zh_CN/3399pro_npu/OpenCV_support.html