[1]参考http://www.cnblogs.com/woshijpf/p/3840530.html
Table of Contents
1.使用g++命令行 pkg-config参数方法
1.2pkg-config 官网与说明
2.OpenCV推荐的CMake工具
3.使用IDE:Qt Creator新建工程来使用opencv库
4.了解
新建一个cpp文件:main.cpp,功能是输入一幅图像文件的路径并显示该图像:
#include
#include
#include
using namespace std;
using namespace cv;//下面的所有cv相关类型不用加上前缀了
int main(int argc,char** argv)
{
string filename;
cout<<"please input the image file path:"<>filename;
Mat img =imread(filename);//声明Mat变量,并读取图片,imread中需要传入图片的绝对路径
if(img.data==NULL)
{
cout<<"image is not exit"<
然后使用g++ 带pkg参数命令编译 Opencv 的C++文件:
sudo g++ main.cpp -o main `pkg-config --cflags --libs opencv`
然后成可执行的main文件。
注意1:权限问题:不加sudo 编译报错:
/usr/local/lib/libopencv_imgcodecs.so:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用
参考:https://blog.csdn.net/cfyzcc/article/details/52981467
得以解决
注意2:`与' 的区别 英文状态下数字1左边的键盘是~和`,不要误用成单引号'了。
注意3:这实质是g++编译命令中 -I与-L参数打使用。
然后在当前路径下运行mian文件:
$ ./main
./main: /home/yang/anaconda2/lib/libtiff.so.5: no version information available (required by /usr/local/lib/libopencv_imgcodecs.so.3.4)
please input the image file path:
dog.jpeg
https://www.freedesktop.org/wiki/Software/pkg-config/
pkg-config介绍:
pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use gcc -o test test.c `pkg-config --libs --cflags glib-2.0`
for instance, rather than hard-coding values on where to find glib (or other libraries). It is language-agnostic, so it can be used for defining the location of documentation tools, for instance.
pkg-config是编译应用程序和库时使用的辅助工具。 它可以帮助您在命令行中插入正确的编译器选项,以便应用程序可以使用gcc -o test test.c`pkg-config --libs --cflags glib-2.0`,而不是硬编码值在哪里找到glib(或其他库)。 它与语言无关,因此可用于定义文档工具的位置。
pkg-config 使用示例:
gcc Test.c -o Test `pkg-config --cflags --libs opencv`
./Test baboon.jpg
在上面的编译命令中我们其实用到了一个工具“pkg-config”,它主要有以下几个功能:
所有有了这个工具之后我们的编译就很方便了(不过在此之前你要确保你安装的OpenCV的安装链接库文件的目录下有一个pkgconfig文件夹,在该文件夹里面有个opencv.pc的文件,其实这就是pkg-config下OpenCV的配置文件)。
使用pkg-config时,选项--cflags 它是用来指定程序在编译时所需要头文件所在的目录,选项 --libs则是指定程序在链接时所需要的动态链接库的目录,如下是我的PC上安装的Opencv的include和lib目录:
$ pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include
$ pkg-config --libs opencv
-L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
step1:新建一个目录用于存放我们的代码和程序中要处理的相关图片
step2:添加cmake工具编译时所需的文件CMakeLists.txt
注:这个文件你可以到你的OpenCV源代码解压出来的文件夹下的/samples/c/example_cmake/文件夹下拷过来,然后再做修改
为修改文件如下:
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
# 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
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 " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})
根据你的项目名称和该项目里包含的源码文件 修改如下:
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
#这是对CMake工具最低版本要求,这里我们要检查下我们的CMake工具的版本信息,我们可以使用命令“cmake --version”查看
# Define project name
project(opencv_example)
#//这是建立一个工程项目(类似于我们VS中建立C++项目一样),括号里面时工程名,工程名我们可以任意给,最后程序编译出来的可执行文件就是这个名字
# 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
find_package(OpenCV REQUIRED) #这是cmake用来查找opencv包用的,
# 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 " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(opencv_example main.cpp) #这里括号里面的两个参数分别是工程项目名和我们要编译文件名的意思,记住中间一空格键隔开
# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS}) #这是我们链接到OpenCV库的环节,我们只要更改前面第一个参数为我们的工程项目名即可
然后我们就将终端的工作目录切换到我们建立工程文件的这个目录
Step3:让后我们输入命令"cmake ."对当前的工程进行编译。
$ cmake .
cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by cmake)
-- OpenCV library status:
-- version: 3.4.3
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab
-- include path: /usr/local/include;/usr/local/include/opencv
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yang/桌面/learningOPencv/编译opencv_cpp文件的方法2CMake/opencv_sourceCode
Step4: make
$ make
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[100%] Built target opencv_example
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
运行可执行文件:
$ ./opencv_example
./opencv_example: /home/yang/anaconda2/lib/libtiff.so.5: no version information available (required by /usr/local/lib/libopencv_imgcodecs.so.3.4)
please input the image file path:
dog.jpeg
1.新建一个Qt Console Application工程:hello_opencv
2.关键在工程的.pro文件中加入下面的语句:配置opencv的include路径和lib库打路径:
INCLUDEPATH+=/home/yang/opencv-3.4.3/include\
/home/yang/opencv-3.4.3/include\opencv\
/home/yang/opencv-3.4.3/include\opencv2
LIBS+=-L/home/yang/opencv-3.4.3/build/lib\
-lopencv_core\
-lopencv_imgcodecs\
-lopencv_highgui\
-lopencv_imgproc
整个.pro文件和mian.cpp文件如下:
QT += core
QT -= gui
CONFIG += c++11
TARGET = hello_opencv
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH+=/home/yang/opencv-3.4.3/include\
/home/yang/opencv-3.4.3/include\opencv\
/home/yang/opencv-3.4.3/include\opencv2
LIBS+=-L/home/yang/opencv-3.4.3/build/lib\
-lopencv_core\
-lopencv_imgcodecs\
-lopencv_highgui\
-lopencv_imgproc
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
mian.cpp文件如下:
#include
#include
#include
#include
//#include"imgproc.hpp"
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout<<"please input a image file path:"<>imagePath;
String filePath=imagePath;
cout<<"The input is "<
3.直接编译运行该工程:
please input a image file path:
/home/yang/Desktop/dog.jpeg
The input is /home/yang/Desktop/dog.jpeg
Press to close this window...
1.想了解Liunx下c++的一些常用开发工具
2.任务驱动,但现在暂时没找到Linux下开发所需要学习的方向
3.在计算机视觉学习方面,实验室现在的开发与学习环境是 这样打:
3.1Windows下做客户端Qt+Opencv+附加的神经网络模型(使用Caffe深度学习框架训练出来用于目标检测的)
3.2Linux下使用 Caffe+CUDA+cuDNN在训练神经网络模型(需要带显卡的服务器),普通PC带nvidia显卡打做学习和写代码
3.3在一些嵌入式领域:
3.3.1图像处理嵌入式:FPGA做板卡,完成一些诸如图像压缩/解压缩的任务。
3.3.2北京的一些做安防监控与自动驾驶的公司 :将剪枝压缩的神经网络模型以C的开发方式在Xilinx的FGPA板卡上实现,用于车辆识别与检测。
深瞐mò科技 http://www.seemmo.com/#page4
实验室的师兄前辈:https://www.iyiou.com/p/71694
王建辉,深瞐科技CTO,华中科技大学博士,多年来从事FPGA芯片设计和机器学习方向的研究,专注于神经网络加速芯片设计和算法优化,是该领域集硬件设计、算法研发、整体优化能力于一体的全面性专家。
王建辉博士在此前接受亿欧专访时曾表示:“手机成为AI芯片的新引擎,安防市场终将面临价格战。”总结AI芯片如此火热的根源,王建辉认为有四大因素:
第一,国家政策在扶持。2017年7月,国务院发布了《新一代人工智能发展规划》,对人工智能产业的发展做出详细的规划和明确的政策支持。规划中表明,人工智能产业要达到发展规划中的产业规模,政府给予资源配置以及保障措施等政策帮助。去年以来,一级市场对人工智能的景气度高,从芯片、技术平台的基础层到语音识别、计算机视觉的应用层的融资现象都非常火热。
第二,深度学习是一个非常新的技术,底层计算结构比较简单,国内AI芯片公司跟国外的巨头处于同一起跑线,也成为AI红利的收益者。
第三,融资需求。公司做到一定程度之后,需要新的增长点来“讲故事”,其实做芯片非常费钱,而且需要时间,芯片行业如果能做起来也是非常有潜力领域,想象空间大,更容易拿到钱。
第四,手机端对芯片的巨大需求,苹果、小米、华为等厂商纷纷发布AI手机,而手机一年的出货量比安防市场摄像头历年存量还要大。
“安防对图像处理是刚需。未来3-5年中国所有的摄像头会换一遍,海康、大华也这么想。安防行业现在还处于相对浑浊的时期,但成熟之后就是拼价格。”王建辉说。
3.3.3 NVIDIA Jetson 是业内领先的 AI 计算平台,它面向移动嵌入式系统市场中的 GPU 加速并行处理。在深度学习和计算机视觉方面的高性能、低能耗计算,使得 Jetson 成为计算密集型嵌入式项目的理想平台。
nvidia的GPU+ARM的CPU,可以安装Linux操作系统,就是一台嵌入式的小型电脑,可以实现一些视觉,深度学习,的开发任务。
https://www.nvidia.com/zh-cn/autonomous-machines/embedded-systems/