如何编译运行opencv的sample

本文档详细介绍了如何在已配置好OpenCV的Ubuntu 14.04环境中编译和运行C++样本代码。首先确保安装了cmake,然后将example_cmake的Makefile和CMakeLists.txt复制到cpp样本代码目录,修改CMakeLists.txt以包含所有样例,并删除原有的example条目。完成这些步骤后,通过cmake和make进行编译,最终能够成功运行样本代码。
摘要由CSDN通过智能技术生成

如何编译运行opencv的sample

前言:之前在树莓派上配置了opencv,但还不知道怎么使用,知道opencv有很多的sample,所以现在记录一下如何使用opencv的sample。

设备:华硕FX50V

环境:已经配置好opencv的ubuntu 14.04(如果还没配置opencv可以参照前面的博客,有讲怎么配置,看树莓派那篇也行)

进入到samples文件夹,这里有各种语言的,如果你配置好python与opencv的话,进入python那个文件夹直接 python 文件名.py就能运行opencv的python样例了。

但cpp文件的编译运行就有些不一样了。

首先,要有cmake:

sudo apt-get install cmake

然后,要用到example_cmake里面的  Makefile 和  CMakeLists.txt,官方的介绍是把需要编译的 样例.cpp 文件拷贝到这个文件夹下面,再到CMakeLists.txt修改相应的文件名然后编译即可,但我发现这样做源代码里面的路径被不正确了,就像人脸识别那个样例没办法载入文件,而且新建一个build文件夹来编译的方式也会造成路径不正确,所以为了使它们能够正常运行,我的做法是直接在cpp文件夹里面编译,运行,就不新建了。

具体做法如下:

把example_cmake里面的 Makefile 和 CMakeLists.txt 拷贝到cpp文件夹下(将原先的 CMakeLists.txt 拷贝到tutorial_code备份一下),打开 CMakeLists.txt,先把最下面那两行example的删掉:

# Declare the executable target built from your sources
add_executable(example example.cpp)

# Link your application with OpenCV libraries
target_link_libraries(example ${OpenCV_LIBS})

然后添加全部样例的信息:

add_executable(facedetect facedetect.cpp)
target_link_libraries(facedetect ${OpenCV_LIBS})

add_executable(facial_features facial_features.cpp)
target_link_libraries(facial_features ${OpenCV_LIBS})


add_executable(falsecolor falsecolor.cpp)
target_link_libraries(falsecolor ${OpenCV_LIBS})


add_executable(fback fback.cpp)
target_link_libraries(fback ${OpenCV_LIBS})

add_executable(ffilldemo ffilldemo.cpp)
target_link_libraries(ffilldemo ${OpenCV_LIBS})

add_executable(filestorage_base64 filestorage_base64.cpp)
target_link_libraries(filestorage_base64 ${OpenCV_LIBS})

add_executable(filestorage filestorage.cpp)
target_link_libraries(filestorage ${OpenCV_LIBS})

add_executable(fitellipse fitellipse.cpp)
target_link_libraries(fi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值