最简洁的基础版 opencv-3.4.x Linux 下安装教程 | 第一个C++ opencv程序运行
【摘要】
最简洁的基础版 opencv-3.4.x Linux 下安装教程
准备工作:需要 Linux 安装好 Gcc、G++、cmake; gcc、g++ 通常默认有安装,可能会需要升级版本,本文...
最简洁的基础版 opencv-3.4.x Linux 下安装教程
准备工作:需要 Linux 安装好 Gcc、G++、cmake;
gcc、g++ 通常默认有安装,可能会需要升级版本,本文不再赘述;
下载特定版本的源码包
- copy到服务器,Linux 环境下一路执行如下命令即可命令
tar -zxvf opencv-3.4.13.tar.gz
cd opencv-3.4.13
ll
mkdir build
cd build/
# root 用户直接运行,会默认编译安装到/usr/local 目录下
cmake ..
make -j16
make install
# 普通用户,没有 /usr/local 写入权限,需要 指定安装路径
make install DESTDIR=/home/Moli/usr/local
# 记录编译路径( CMakeLists.txt 编写是需要指定该路径 ):
/build/ownOppenCV/opencv-3.4.13/build
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
参考博文Ubuntu下多个版本OpenCV管理(Multiple Opencv version)
第一个C++ opencv程序运行
- lap.cpp 只是一个普通的 openCV 示例程序:
- 重要的是 CMakeLists.txt 文件的编写
vim CMakeLists.txt
需要修改的是 设定 OpenCV_DIR的路径:
set(OpenCV_DIR /build/ownOppenCV/opencv-3.4.13/build)
指定运行主程序:
add_executable(opencv_example lap.cpp)
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
#set(OpenCV_DIR /home/moli/usr/local)
set(OpenCV_DIR /build/ownOppenCV/opencv-3.4.13/build)
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(opencv_example lap.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
编译运行,命令如下
mkdir build
cd build/
cmake ..
make
./opencv_example
- 1
- 2
- 3
- 4
- 5
- 6
- 7
干饭,干饭
博主维新:bravePatch
欢迎各位 初学 OpenCV 的小伙伴添加上方维新,加入 OpenCV 讨论组,添加时备注 【OpenCV入组】 即可,这样好友通过后,我会第一时间直接带您入圈哈;
声明:码字不易,如果本博文对您有用,请多多点赞,点赞虽然不能当饭吃,但是会让打工人开心呀!
文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。
原文链接:positive.blog.csdn.net/article/details/116135490
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)