前文介绍了使用X86 PC交叉编译OpenCV的过程,因为交叉编译后的imgShow GTK2.0 Error始终无法得到解决,故现在使用本地OpenCV编译方式。留作记录,方便以后复现。
开发环境:ARM开发板 ToyBrick RK3399PRO_X, Debain10, OpenCV 3.4
*可选前置步骤,更换国内源
修改/etc/apt/sources.list 文件,笔者选择的是阿里源
# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
第一步:更新系统
sudo apt-get update && sudo apt-get upgrade
第二步:安装依赖项
依赖项,视情况而定。事实上,OpenCV的依赖项很多,缺少某些依赖项会影响OpenCV部分功能。OpenCV会在make阶段检测依赖项是否会安装,并自我调整功能。
$ sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install libjpeg-dev libpng-dev libtiff5-dev libjasper-dev libdc1394-22-dev libeigen3-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev sphinx-common libtbb-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libopenexr-dev libgstreamer-plugins-base1.0-dev libavutil-dev libavfilter-dev libavresample-dev
某依赖项安装有问题时,请自行搜索解决。如依赖包,libjasper-dev
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
重复之前的操作,即可运行。
第三步:下载OpenCV
在github官网选择对应版本下载即可。
第四步:编译和安装OpenCV
进入第三步下载的或者解压的opencv文件夹,利用cmake生成makefile,当然有很多的选择项设置,具体可以查看cmakelist文件中的帮助信息,对于我们来说这些就足够了,其实默认也可以,即直接使用如下选择项。
/opt$ cd opencv
/opt/opencv$ mkdir build
/opt/opencv$ cd build
/opt/opencv/build$ cmake -D BUILD_TIFF=ON -D WITH_CUDA=OFF -D ENABLE_AVX=OFF -D WITH_OPENGL=OFF -D WITH_OPENCL=OFF -D WITH_IPP=OFF -D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_EIGEN=OFF -D WITH_V4L=OFF -D WITH_VTK=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK=ON -D WITH_GTK2.0=ON -D CMAKE_INSTALL_PREFIX=/usr/local/opencvlocal/ OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib/modules /opt/opencv/ ..
/opt/opencv/build$ make -j4 # multi task
/opt/opencv/build$ make install
/opt/opencv/build$ ldconfig
/opt/opencv/build$ exit # exit root
/opt/opencv/build$ cd ~
如果ldconfig提示没有此指令,则直接去目录运行:
/sbin/ldconfig
如果不修改CMakeLists文件,则Opencv默认的安装位置:
/usr/local/include/opencv2/ #新版Opencv核心头文件
/usr/local/include/opencv/ #旧Opencv核心头文件
/usr/local/share/OpenCV/ #一些Opencv其他安装信息
/usr/local/lib/ #Opencv中的动态链接库存放位置
第五步:检测安装
pkg-config --modversion opencv
3.4.0
第六步:测试
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(){
VideoCapture capture(0);
while(true){
Mat frame;
capture >> frame;
imshow("Read Camera", frame);
waitKey(30);
}
return 0;
}
编译运行:
g++ camera.cpp -o output `pkg-config --cflags --libs opencv`
./output
参考:
Ubuntu 18.04 LTS 安装OpenCV (C/C++)
https://blog.csdn.net/weixin_44278406/article/details/103619191
bash: ldconfig: command not found
https://blog.csdn.net/weixin_43570089/article/details/98733129
【opencv】64位ARM提示:errorE: unable to locate libjasper-dev
https://blog.csdn.net/u011622208/article/details/105252720
解决GPG error: The following signatures couldn’t be verified because the public key is not available
https://blog.csdn.net/zhuiqiuzhuoyue583/article/details/90597499
文章评论