我这里是下载最新版本4.7.0
1、把下载的源码包上传到开发板,解压后在opencv下面新建一个build文件压,并进行入build文件夹。
2、执行:
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
3、然后执行编译:
sudo make -j8
4、然而到最后是编译通不过的:
make[1]: *** Waiting for unfinished jobs....
[ 92%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_imgproc_tests_fluid.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_perf_gapi.dir/build.make:128: modules/gapi/CMakeFiles/opencv_perf_gapi.dir/perf/cpu/gapi_core_perf_tests_fluid.cpp.o] Error 1
[ 92%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_ocv_stateful_kernel_tests.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_perf_gapi.dir/build.make:63: modules/gapi/CMakeFiles/opencv_perf_gapi.dir/perf/common/gapi_core_perf_tests.cpp.o] Error 1
[ 92%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_operators_tests_cpu.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_test_gapi.dir/build.make:76: modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/common/gapi_core_tests.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_perf_gapi.dir/build.make:141: modules/gapi/CMakeFiles/opencv_perf_gapi.dir/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp.o] Error 1
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_test_gapi.dir/build.make:180: modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_imgproc_tests_cpu.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:3611: modules/gapi/CMakeFiles/opencv_perf_gapi.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:3653: modules/gapi/CMakeFiles/opencv_test_gapi.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
所以后面还是退回了4.5.4才能安装好。
mak 好后,执行sudo make install
1.添加路径
(1)打开文件:
sudo vim /etc/ld.so.conf.d/opencv.conf
在文件后面添加如下内容:
/usr/loacal/lib
2.修改etc/bash.bashrc
我们之前安装的时候 OPENCV_GENERATE_PKGCONFIG=ON
所以在/usr/local/lib/pkgconfig下生成了opencv4.pc文件,里面记录了OpenCV头文件、库文件的路經。需要进行如下配置:
`sudo vim /etc/bash.bashrc
`
加截:
sudo ldconfig
#文件末尾添加以下内容 并保存
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
然后的要安装 sudo apt install mlocate
要不会报错sudo: updatedb: command not found
#更新
sudo updatedb
source /etc/bash.bashrc
#终端输入以下两命令,显示正常则安装成功
pkg-config --modversion opencv4 #查看版本号
pkg-config --libs opencv4 #查看libs库
然后报错:
forlinx@ok3588:~/opencv-4.5.4/build$ pkg-config opencv --modversion
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
经过网上详细查询资料后,是缺失了opencv.pc这个配置信息文件,故解决方法就是添加这个文件然后将其导入到环境变量中,具体操作如下:
首先创建opencv.pc文件,这里要注意它的路径信息:
cd /usr/local/lib
sudo mkdir pkgconfig
cd pkgconfig
sudo touch opencv.pc
然后在opencv.pc中添加以下信息,注意这些信息需要与自己安装opencv时的库路径对应:
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version:4.5.4
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
保存后再执行版本查看OK了:
forlinx@ok3588:/usr/local/lib/pkgconfig$ pkg-config opencv --modversion
4.5.4
进入opencv/samples/cpp/example_cmake目录下,终端打开,依次输入:
forlinx@ok3588:~/opencv-4.5.4/samples/cpp/example_cmake$ cmake .
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "4.5.4")
-- OpenCV library status:
-- config: /usr/local/lib/cmake/opencv4
-- version: 4.5.4
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio
-- include path: /usr/local/include/opencv4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/forlinx/opencv-4.5.4/samples/cpp/example_cmake
forlinx@ok3588:~/opencv-4.5.4/samples/cpp/example_cmake$ make
Scanning dependencies of target opencv_example
[ 50%] Building CXX object CMakeFiles/opencv_example.dir/example.cpp.o
[100%] Linking CXX executable opencv_example
[100%] Built target opencv_example
forlinx@ok3588:~/opencv-4.5.4/samples/cpp/example_cmake$
然后在桌面打开 ./example
./opencv_example
然后就可以生成opencv图像
1、3688有8核,编译时前面可以开8核编译,但到93%会报错:
fatal error: Killed signal terminated program cc++: fatal error: Killed signal terminated program cc1plus
经查资料,是交换空间太小导致的,我重复编了好多编,最后解决方法是只开2个线程编译,才通过。
2、opencv版本太新,可能会出现不兼容的情况。
更多回帖