因为网络原因, 在国内编译Opencv非常的艰难
openfans 提供了opencv-4.5.1-org.pifan_20210116-1_arm64.deb, 可以直接下载, 百度盘路径在: /树莓派爱好者基地64位系统2.0正式版/Debian-Pi-Aarch64-2.0-Release/Extra/OpenCV/

准备工作

mkdir /root/opencv/
cd /root/opencv/

下载并解压

下载源代码

wget https://github.com/opencv/opencv/archive/refs/tags/4.5.2.zip -O opencv-4.5.2.zip
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.zip -O opencv_contrib-4.5.2.zip

unzip opencv-4.5.2.zip
unzip opencv_contrib-4.5.2.zip

下载必要文件

因为这地址无法访问, 会卡在下载环节

face_landmark_model.dat

wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat -O face_landmark_model.dat

vim opencv_contrib-4.5.2/modules/face/CMakeLists.txt

https://raw.githubusercontent.com/opencv/opencv_3rdparty/${__commit_hash}/改为file:///root/opencv/

ippicv_2020_lnx_intel64_20191018_general.tgz

这个树莓派无需下载/安装
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz -O ippicv_2020_lnx_intel64_20191018_general.tgz

vim opencv-4.5.2/3rdparty/ippicv/ippicv.cmake

"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"改为file:///root/opencv/

安装依赖

apt -y remove x264 libx264-dev

## Install dependencies
apt -y install build-essential checkinstall cmake pkg-config yasm
apt -y install libjpeg8-dev libjasper-dev libpng12-dev

apt -y install libtiff5-dev

apt -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
apt -y install libxine2-dev libv4l-dev
cd /usr/include/linux
ln -s -f ../libv4l1-videodev.h videodev.h
cd $cwd

apt -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
apt -y install libgtk+-3.0-dev libgtk2.0-dev libtbb-dev
apt -y install libatlas-base-dev
apt -y install libmp3lame-dev libtheora-dev
apt -y install libvorbis-dev libxvidcore-dev libx264-dev
apt -y install libopencore-amrnb-dev libopencore-amrwb-dev
apt -y install libavresample-dev
apt -y install x264 v4l-utils

# Optional dependencies
apt -y install libprotobuf-dev protobuf-compiler
apt -y install libgoogle-glog-dev libgflags-dev
apt -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

创建编译目录

mkdir -p /root/opencv/opencv-4.5.2/build/
cd /root/opencv/opencv-4.5.2/build/

配置

cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/ \
-D BUILD_SHARED_LIBS=ON \
-D OPENCV_EXTRA_MODULES_PATH=/root/opencv/opencv_contrib-4.5.2/modules \
-D BUILD_DOCS=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_opencv_java=NO \
-D BUILD_opencv_python=NO \
-D BUILD_opencv_python2=NO \
-D BUILD_opencv_python3=NO \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=OFF \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D WITH_JASPER=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS='-latomic' \
-D OPENCV_GENERATE_PKGCONFIG=ON ..

编译&安装

make -j$(nproc)
make install

member
6.2k 声望158 粉丝

擅长计算机开关机、Windows系统的安装。