【安装相关软件和库】

  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. Codeforces 1088E Ehab and a component choosing problem

    Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...

  2. CSS------让ul中高度不同的li底部对齐

    如图: 代码:(需要将li中vertical-align属性设置为bottom) <ul style="margin-top:50px"> <li style=& ...

  3. Class PropertyPlaceholderHelper的使用

    1.代码 private static Properties properties = new Properties(); public static String getProperties(Str ...

  4. miniblink+golang开发windows gui应用

    golang的优点自不必说了,这么好的语言怎么能缺少界面库呢?所以我使用miniblink开发了一个可以用html,css,js开发界面的浏览器,通过它你能为你的golang开发简单的界面.说白了其实 ...

  5. 附001.etcd配置文件详解

    一 示例yml配置文件 # This is the configuration file for the etcd server.   # Human-readable name for this m ...

  6. 006.MySQL双主-Master02可用配置

    [root@Master02 ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_de ...

  7. JavaWeb中Tomcat与Eclipse的集成—步骤详解

    前面会简单介绍,下翻Tomcat与Eclipse的集成 一.先介绍一下应用程序的结构: 1.到目前为止应用程序物理结构有两种: C/S——Client / server:这种结构的应用,客户端与服务端 ...

  8. 使用 jquery 开发用户通讯录

    由于开发需求,需要做一个通讯录界面,点击右侧首字母菜单,列表会将对应字母列表成员滑动至顶部,效果如下图(包括点击事件+长按事件): 1.需求分析 (1)首先,我们需要把数据里用户名转换为首拼,然后归类 ...

  9. 1,EasyNetQ-链接到RabbitMQ

    一.链接到RabbitMQ 1,创建连接 注意不能有空格 var bus = RabbitHutch.CreateBus(“host=myServer;virtualHost=myVirtualHos ...

  10. AES advanced encryption standard 3

    This optimized <../aesbench/> AES implementation conforms to FIPS-. aes.h #ifndef _AES_H #defi ...