【安装相关软件和库】

  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. 【AtCoder】ARC098题解

    C - Attention 枚举,计算前缀和即可 代码 #include <bits/stdc++.h> #define fi first #define se second #defin ...

  2. date命令使用文档

    date命令的帮助信息 [root@localhost source]# date --help用法:date [选项]... [+格式] 或:date [-u|--utc|--universal] ...

  3. MySQL数据库之视图

    1 引言 为了简化复杂SQL语句编写,以及提高数据库安全性,MySQL数据库视图特性.视图是一张虚拟表,不在数据库中以储存的数据值形式存在.在开发中,开发者往往只对某些特定数据和所负责的特定任务感兴趣 ...

  4. [CC-XXOR]Chef and Easy Problem

    [CC-XXOR]Chef and Easy Problem 题目大意: 给你一个长度为\(n(n\le10^5)\)的序列\(A(A_i<2^{31})\).\(m(m\le10^5)\)次询 ...

  5. hdu 4451 37届金华赛区 J题

    题意:给出衣服裤子鞋子的数目,有一些衣服和裤子,裤子和鞋子不能搭配,求最终的搭配方案总数 wa点很多,我写wa了很多次,代码能力需要进一步提升 #include<cstdio> #incl ...

  6. STM32 System and Timer Clock Configurations

    STM32 System and Timer Clock Configurations I've started writing some software to drive a series of  ...

  7. delphi 文件查找

    FindFirst  是用来寻找目标目录下的第一个文件, FindFirst函数在delphi帮助下的定义: function FindFirst(const Path: string; Attr: ...

  8. JavaScript中0和""的比较问题

    今天在公司的时候发现了一个很奇怪的Js的问题,以前也没有注意到,我从数据库中取出某一个字段的值,而这个字段值刚好是0,然后我在判断这个值是不是等于""时,就出现了如下的问题: 就是 ...

  9. .Net Discovery系列之十-深入理解平台机制与性能影响(上)

    转眼间<.Net Discovery>系列文章已经推出1年了,本文为该系列的第10-13篇文章,在本文中将对以前所讲的.Net平台知识做一个小小的总结与机制分析,引出并重点介绍这些机制对程 ...

  10. JBPM使用方法、过程记录

    一.How to call Web Service Using JBPM 5, designer https://204.12.228.236/browse.php?u=ObFK10b3HDFCQUN ...