旭日X3派编译opencv4.2

1 安装依赖库
sudo apt-get install build-essential git cmake pkg-config -y

sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libgtk2.0-dev libatlas-base-dev -y

2 下载opencv4.2 和contrib 扩展模块。

或者

下载opencv4.2 和opencv_contrib-4.2.0

链接:https://pan.baidu.com/s/1O9hAts_s635esRt8nSHDdg 
提取码:yrhx

链接:https://pan.baidu.com/s/1SRNBXMKU3GDesQWjdiEuZg 
提取码:7g25

3

生成makefile
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/sunrise/Downloads/opencv_contrib-4.2.0/modules -D BUILD_EXAMPLES=ON -D OPENCV_ENABLE_NONFREE=YES -D WITH_LIBV4L=ON ..


OPENCV_ENABLE_NONFREE 是使用专利相关的算法

4 make -j4 编译
编译过程中内存出现溢出
增加swap 交换内存2G,重启后需要重新设置。
cd /var 
sunrise@ubuntu:/var$ sudo dd if=/dev/zero of=swap bs=2M count=1024

1024+0 records in
1024+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 52.3633 s, 41.0 MB/s
sunrise@ubuntu:/var$ sudo mkswap /var/swap
mkswap: /var/swap: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=32c5dc15-2283-48e0-9c7a-43f8ab1776bc
sunrise@ubuntu:/var$ 
sunrise@ubuntu:/var$ sudo swapon /var/swap
/var/swap
sunrise@ubuntu:/var$ sudo swapon /var/swap
swapon: /var/swap: insecure permissions 0644, 0600 suggested.
sunrise@ubuntu:/var$ free 
              total        used        free      shared  buff/cache   available
Mem:        2029888      628928       13556        9568     1387404     1370680
Swap:       2097148           0     2097148
sunrise@ubuntu:/var$ 
[ 57%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/affine_feature2d.cpp.o [ 57%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o /home/sunrise/Downloads/opencv_contrib-4.2.0/modules/xfeatures2d/src/boostdesc.cpp:654:20: fatal error: boostdesc_bgm.i: No such file or directory 654 | #include "boostdesc_bgm.i" | ^~~~~~~~~~~~~~~~~ compilation terminated.

解决方法:将/home/pi/Downloads/opencv-4.2.0/modules/features2d/test文件下的
test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp
这5个文件复制粘贴到opencv_contrib-4.2.0/modules/xfeatures2d/test这个目录下,不要多拷贝。

sitemap