【安装相关软件和库】

  1.安装CMAKE:这里使用apt-get来安装; CMAKE 是一个跨平台编译工具,能够输出各种makefile,和project 文件,指导编译器编译,对CMAKE具体的可以自行搜索,这里推荐一个链接:

  http://www.cnblogs.com/lyq105/archive/2010/12/03/1895067.html

在联网下,在终端输入:

  sudo apt-get install cmake

【编译、安装OPENCV】

  1.从OPENCV官网下载OpenCV-3.2.0.zip

  2.建议把OpenCV-3.2.0.zip 移动到主目录下;

  mv [OpenCV-3.2.0.zip存放路径/opencv3.2.0.zip] ~/opencv_3.2.0.zip

  3.配置CMAKE相关信息,默认安装目录,编译类型(DEBUG/RELEASE),对相关语言、环境的支持(如QT,Python),

  在终端输入:

    cd ~

    unzip opencv_3.2.0.zip

    cd opencv-3.2.0

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

  -D WITH_QT=ON 这个选项表示支持QT,-D CMAKE_INSTALL_PREFIX=/usr/local 表示安装目录。

  网上许多教程,都是建议在OpenCV下新建议个编译结果的目录,但是我尝试了很多种方法,最后直接在解压后的OpenCV 目录下 cmake 才成功了。

  3.编译

  在终端输入:

    make -j($nproc)

  -j表示用几个线程来编译,这样可以加快编译速度,不过这个与makefile的质量有关,有的工程用了-j会编译出错

  4.安装

  在终端输入:

    sudo make install

  5.配置环境变量

    a.添加库路径:

      sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

    这里使用了标准输出重定向,/usr/local OpenCV安装目录,在lib下有我们的.so库 ,把这“/usr/local/lib” “打印”--echo到/etc/ld.so.conf.d/opencv.conf'

    b.更新库路径:

      sudo ldconfig

【新建OpenCV的HelloWorld】

一、利用Make 和pkgconfig ,g++ 编译

  1. pkgconfig 只是提供g++一些-I -L 选项

  在终端输入:

      pkg-config --cflags --libs opencv

  看到输出一些-I -L选项如下,即pkg-config 安装正确,OpenCV 安装正确。如未安装,请先安装;如果发现不正确,可以修改/usr/local/lib/pkgconfig/opencv.pc文件,这个文件就是opencv的目录配置。

  -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -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

  2.中间出现的错误和解决方法

g++ -o opencv_test opencv_test.cpp `pkg-config --cflags --libs opencv` -Wall 
/usr/bin/ld: warning: libicui18n.so.54, needed by //home/yyh/anaconda2/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.54, needed by //home/yyh/anaconda2/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicudata.so.54, needed by //home/yyh/anaconda2/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libpng16.so.16, needed by //home/yyh/anaconda2/lib/libQt5Gui.so.5, not found (try using -rpath or -rpath-link)
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_clone_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_interlace_handling@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_IHDR@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_io_ptr@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_image_width@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `u_strToLower_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_longjmp_fn@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_gray_to_rgb@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_setMillis_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_bgr@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_valid@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_fromUnicode_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_write_rows@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_getDefaultName_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_PLTE@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_sig_bytes@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_write_chunk@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_pHYs@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_destroy_read_struct@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_inDaylightTime_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_x_pixels_per_meter@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_read_row@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_tRNS@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_get_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_close_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_error_fn@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_openTimeZones_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_toUnicode_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `u_strToUpper_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_close_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_packing@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_read_end@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_getMaxCharSize_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_countAvailable_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_read_fn@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_write_end@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_invert_mono@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_write_fn@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_tRNS@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_create_write_struct@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_getDefaultTimeZone_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_error@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_destroy_write_struct@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_packswap@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_text@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_strip_16@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_create_read_struct@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_oFFs@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `uenum_next_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_getStandardName_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucol_setAttribute_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_PLTE@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_compression_level@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucol_strcoll_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_text@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_setSubstChars_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_filler@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_gAMA@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_getTimeZoneDisplayName_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_openCountryTimeZones_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_open_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucol_open_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_IHDR@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucol_close_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucol_getSortKey_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_expand@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_getAvailableName_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_write_info@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_getDSTSavings_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_openTimeZoneIDEnumeration_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucal_open_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `u_errorName_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `uenum_close_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_oFFs@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_create_info_struct@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_read_update_info@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_write_image@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_gamma@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_getAlias_54'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_y_pixels_per_meter@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_image_height@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_read_image@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_read_info@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_set_gAMA@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Gui.so.5: undefined reference to `png_get_channels@PNG16_0'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_compareNames_54'
//home/yyh/anaconda2/lib/libQt5Core.so.5: undefined reference to `ucnv_countAliases_54'

原因:QT安装在了用户目录下,当时没有配置环境变量,出现了链接错误:

解决方案:

  利用export 命令设置环境变量:[Qt安装目录下/version number /gcc_64/lib]

  在终端输入(或~/.bashrc):

  export LD_LIBRARY_PATH=/home/yyh/Qt5.7.1/5.7/gcc_64/lib/

查找Qt路径的方法:

qmake -v

执行 ./opencv_test 出现下面的error,但是直接双击可以执行

This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: minimal, offscreen, xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

解决方案:

关闭终端重新执行

4.opencv_test.cpp

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define PICTURE "./01.jpg"
int main(void)
{
IplImage* img = cvLoadImage(PICTURE, 0);
cvNamedWindow( "test", 0 );
cvShowImage("test", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "test" );
return 0;
}

5.Makefile(赋值的时候注意TAB键)

CXX       = g++
CFLAGS = -Wall
LDFLAGS = `pkg-config --cflags --libs opencv` SRCS = $(wildcard *.cpp)
TARGETS = $(patsubst %.cpp, %,$(SRCS)) all:$(TARGETS)
$(TARGETS):$(SRCS)
$(CXX) -o $@ $< $(LDFLAGS) $(CFLAGS)
clean:
-rm -rf $(TARGETS) *~ .*swp
.PHONY: clean all

二、在 QT 下使用OpenCV

  我尝试照着网上的教程试了一下,但是运行时出现下面的错误:(先不用到就先放着咯)

  Starting /home/yyh/workspace/qt/opencv_test/build-opecv_test-Desktop_Qt_5_7_1_GCC_64bit-Debug/opecv_test...

  Cannot mix incompatible Qt library (version 0x50600) with this library (version 0x50701)

  The program has unexpectedly finished.

  /home/yyh/workspace/qt/opencv_test/build-opecv_test-Desktop_Qt_5_7_1_GCC_64bit-Debug/opecv_test crashed.

  照网络上的说法,应该去删除OpenCV 安装目录下的QT动态库,但是我目前没有找到

【参考链接】

http://jingyan.baidu.com/article/14bd256e466474bb6d2612db.html

在 Linux 下用 CMAKE 编译安装 OpenCV 3.2.0的更多相关文章

  1. 在ubunt14.04(linux)下利用cmake编译运行opencv程序

    今天在电脑上安装好了opencv环境,迫不及待的想写个程序来测试一下.但是在windows下我们用vs等集成开发工具.可是在linux下我们应该怎么办呢? 这里我们用了opencv推荐的cmake来编 ...

  2. Windows下CMake编译安装OpenCV

    Windows下CMake编译安装OpenCV 这是一个面向新手的在windows上运进opencv, helloword的教程. 在这里我们使用vs2019来编译opencv, 并运行一个hello ...

  3. Linux下指定版本编译安装LAMP

    说明: 操作系统:CentOS 6.5 64位 需求: 编译安装LAMP运行环境 各软件版本如下: MySQL:mysql-5.1.73 Apache:httpd-2.2.31 PHP:php-5.2 ...

  4. Linux下源码编译安装rpy2

    R(又称R语言)是一款开源的跨平台的数值统计和数值图形化展现工具.rpy2是Python直接调用R的第三方库,它可以实现使用python读取R的对象.调用R的方法以及Python与R数据结构转换等.这 ...

  5. Linux 下源码编译安装 vim 8.1

    前言 目前 linux 的各个发行版基本上都是带了一个 vi 编辑器的,而本文要说的 vim 编辑器对 vi 做了一些优化升级,更好用.当我们需要远程操作一台 linux 服务器的时候,只能使用命令行 ...

  6. linux下Python2.7编译安装PyQt5

    ---作者吴疆,未经允许,严禁转载,违权必究--- ---欢迎指正,需要源码和文件可站内私信联系--- -----------点击此处链接至博客园原文----------- 功能说明:在ubuntu系 ...

  7. Centos 6下使用cmake编译安装MariaDB

    写在前面 最近在学习Maria DB,为了方便查阅,又为了将所学的知识重新的梳理,特作此随笔一篇,希望过后阅读时能有所感,也希望对大家能够有所帮助. 安装前的准备 大家都知道,在Linux上安装软件一 ...

  8. 1、Linux下源码编译安装PostgreSQL

    操作系统:Centos7 说明:postgresql必须在postgres用户下初始化数据库和启动,否则报错. PostgreSQL的特性 PostgreSQL是一种几乎可以运行在各种平台上的免费的开 ...

  9. CentOS下使用cmake编译安装mysql

    一.下载安装所必需的依赖包 1.因为高版本mysql都用cmake安装,所以下载cmake wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.g ...

随机推荐

  1. Linux性能优化之CPU优化(一)

    前言 何为性能优化?个人认为,性能优化是为了提高应用程序或系统能力为目的.那么如何才能实现对应用程序的性能调优呢?这里很设计到很多的内容,包括Linux内核.CPU架构以及Linux内核对资源的分配以 ...

  2. Wireshark、Netcat

    Wireshark Wireshark是一个网络数据包分析软件,功能是截取网络数据包,并尽可能显示出最为详细的网络数据包数据.为了安全考虑,wireshark只能查看封包,而不能修改封包的内容,或者发 ...

  3. jenkins 整合maven,svn(配置钩子程序实现提交代码自动构建),tomcat实现热部署(windows+linux分别实现)

    springboot : https://blog.csdn.net/zjh_746140129/article/details/80904876 1 准备工作: (1)运行jenkins的tomca ...

  4. SpringMVC框架04——RESTful入门

    1.RESTful的基本概念 REST(Representational State Transfer)表述性状态转移,REST并不是一种创新技术,它指的是一组架构约束条件和原则,符合REST的约束条 ...

  5. BZOJ4280 : [ONTAK2015]Stumilowy sad

    线段树每个区间维护上下界以及要整体增加的标记即可,时间复杂度$O(m\log n)$. #include<cstdio> #define inf 1500000000 int n,m,op ...

  6. 吴恩达-coursera-机器学习-week7

    十二.支持向量机(Support Vector Machines) 12.1 优化目标 12.2 大边界的直观理解 12.3 数学背后的大边界分类(选修) 12.4 核函数1 12.5 核函数2 12 ...

  7. 机器学习算法(5):卷积神经网络原理及其keras实现

    1.原理 CNN的资料特别多,这里不再赘述,仅收集相关的资料供大家参考: a.Deep learning:五十一(CNN的反向求导及练习) b.Deep Learning 2.实现 我们使用keras ...

  8. MikroTik RouterOS使用VirtualBox挂载物理硬盘作为虚拟机硬盘进行安装

    说明:这一切似乎在Windows下更好操作.虚拟机操作不是难点,难点在于虚拟磁盘的转换挂载 一.先挂载硬盘 # 创建虚拟镜像并映射到物理硬盘 cd "c:\Program Files\Ora ...

  9. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  10. 在windows server 2008 R2 64bit上面配置PI OPC Server的DCOM

    今天想配置PI OPC SERVER的DCOM设置,但是发现在“运行dcomcnfg->组件服务-计算机-我的电脑-DCOM设置”中找不到PI OSI DA Server.如下图所示 这是以前从 ...