【OpenCV】在Linux下用CMAKE编译安装OpenCV3.2.0
【安装相关软件和库】
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]
在终端输入:
export LD_LIBRARY_PATH=/home/yyh/Qt5.7.1/5.7/gcc_64/lib/
执行 ./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
转载于:https://www.cnblogs.com/guiguzhixing/p/6347602.html
【OpenCV】在Linux下用CMAKE编译安装OpenCV3.2.0相关推荐
- 在 Linux 下用 CMAKE 编译安装 OpenCV 3.2.0
[安装相关软件和库] 1.安装CMAKE:这里使用apt-get来安装; CMAKE 是一个跨平台编译工具,能够输出各种makefile,和project 文件,指导编译器编译,对CMAKE具体的可以 ...
- Python 3.10版本及其依赖项 Linux下源码编译 安装到指定路径/目录
Python 3.10版本及其依赖项 Linux下源码编译 安装到指定路径/目录 安装需求 准备工作 Python及其依赖项 libffi glibc GDBM mpdecimal bz2 xz re ...
- 【Python 笔记】Linux 下源码编译安装 python
本文记录在 Linux 上源码编译安装 python 的过程. 文章目录 1. 源码编译安装说明 2. 安装 python2.7 3. 安装 python3.6 1. 源码编译安装说明 安装过程比我想 ...
- 【OpenCV】Linux 下用 g++ 编译 OpenCV 程序
编译命令: g++ gaussianBlur.cpp -o test `pkg-config --cflags --libs opencv` 执行编译生成的可执行文件: ./test gaussian ...
- Linux下源码编译安装Redis及如何后台启动Redis
操作系统:Centos 下载源码包 http://download.redis.io/releases/redis-4.0.9.tar.gz 解压 # tar -zxvf redis-4.0.9.ta ...
- linux下caffe-gpu的编译安装
服务器的环境 Ubuntu18.04, python3.6 CUDA 10.0, cuDNN 7.6.3 opencv3.4.6 查看cuda和cudnn版本 nvcc -V cat /usr/loc ...
- Linux 下源码编译安装 vim 8.1
前言 目前 linux 的各个发行版基本上都是带了一个 vi 编辑器的,而本文要说的 vim 编辑器对 vi 做了一些优化升级,更好用.当我们需要远程操作一台 linux 服务器的时候,只能使用命令行 ...
- Linux下源码编译安装新版libxcb
前言 上一篇文章提到,linux 下编译Qt源码如果要用到Quick的话,那么运行时会依赖qxcb库,而编译生成qxcb库就需要先安装libxcb,并且最低要求 版本大于1.9.1 Requires ...
- centos cmake安装mysql_CentOS下使用cmake编译安装mysql
一.下载安装所必需的依赖包 1.因为高版本mysql都用cmake安装,所以下载cmake wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.g ...
最新文章
- Vi编辑器中查找替换
- 父亲节用计算机给惊喜,2015父亲节的惊喜作文:给爸爸特殊的礼物
- Oracle死锁情况
- java blueprint_blueprint(蓝本/蓝图)学习笔记
- abp 使用 hangfire结合mysql
- oracle,sqlserver,mysql区别
- 删除百度网盘“我的应用数据”文件夹
- android xml 注释快捷键,xml注释(xml注释掉一段代码)
- 高斯克吕格投影,将经纬度转换为投影坐标
- 技巧篇:常用的vba代码汇总
- 开源python爬虫软件下载_33款可用来抓数据的开源爬虫软件工具
- 2022国开中国现代文学专题阶段作业2-4答案
- css中cale()函数的使用
- 微信生态圈盈利模式分析
- 关于计算机作文的结束语,关于行动的作文结尾
- 2011考研数学二第(11)题——第一类曲线积分球弧长
- ESP8266 入门 AT指令
- 固态硬盘中的数据该怎么恢复
- mybatis的parameterType可以不写(我一般都不写)
- vuex存储什么数据_【存储知识小讲堂系列】为什么数据隔离很重要_热点新闻-新闻频道-中文科技资讯...