OpenCV(开源计算机视觉库)是一个开源计算机视觉和机器学习软件库。
OpenCV 广泛应用于计算机视觉、机器人、智能交通、医学成像、安全等领域。
Forlinx RK3588 EVK 是一款高性能嵌入式计算机,结合 OpenCV,可进行高效的图像和视频处理以支持应用程序。
如何在 Forlinx RK3588 EVK 上安装OpenCV ?
下载:
https://opencv.org/releases/
下载最新版本4.7.0
编译源代码
编译流程:
将OpenCV源码包上传到EVK→解压→在OpenCV源码包根目录下新建build文件夹→进入build文件夹→通过CMake命令生成Makefile文件→使用make命令编译并安装OpenCV库。
执行:
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译:
sudo make -j8
不合格项目:
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
OpenCV 4.5.4 最终安装成功。
使用make命令编译OpenCV库后,用户可以通过执行sudo make install命令将编译好的OpenCV库安装到系统的默认路径中。
配置环境
添加路径
(1) 打开文件:
sudo vim /etc/ld.so.conf.d/opencv.conf
在文件后添加以下内容:
/usr/loacal/lib
修改 etc/bash.bashrc
在安装OpenCV时,我们设置OPENCV_GENERATE_PKGCONFIG=ON来生成opencv4.pc文件,该文件记录了OpenCV头文件和库文件的路径信息。
为了在编译时自动找到这些文件,我们需要将路径信息添加到系统环境变量中。可以通过编辑sudo vim /etc/bash.bashrc
文件来实现。
sudo ldconfig
#Add the follows after the file:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Then install sudo apt install mlocate
sudo updatedb
source /etc/bash.bashrc
Or an error will be reported sudo: updatedb: command not found#update
sudo updatedb
source /etc/bash.bashrc
检查安装状态:
#Input the following two commands in the terminal, and normal display indicates successful installation.
pkg-config --modversion opencv4 #check version
pkg-config --libs opencv4 #check 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 pkgconfigcd 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
保存并执行上述命令后,我们可以确认OpenCV 4.5.4的安装状态。
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图像了:
欲了解更多信息,请访问 OK3588-C 单板计算机:https://www.forlinx.net/product/135.html
最初发布于 www.forlinx.net(https://www.forlinx.net/article_view_471.html)
☆ END ☆
如果看到这里,说明你喜欢这篇文章,请转发、点赞。微信搜索「uncle_pn」,欢迎添加小编微信「 woshicver」,每日朋友圈更新一篇高质量博文。
↓扫描二维码添加小编↓