你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu 16.04中安装OpenCV 2.4.11

[日期:2016-07-04] 来源:Linux社区  作者:darkknightzh [字体: ]

Ubuntu 16.04中安装OpenCV 2.4.11参考网址如下:

http://www.linuxidc.com/Linux/2016-07/132879.htm

http://www.linuxidc.com/Linux/2016-07/132880.htm

1 预先安装一些软件:

sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev  

2 去管网下载opencv压缩包

3 解压压缩包到某文件夹(用windows习惯了,直接右键提取到此处。。。)

4 command中cd到该解压缩的文件夹中,然后创建build文件夹 mkdir build

5 进入build目录 cd build

6 编译opencv源码

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

7 安装

sudo make install

测试:

1. 写helloworld.cpp

#include <opencv2/opencv.hpp>
using namespace cv;

#include <stdio.h>

int main( int argc, char** argv )
{
    if( argc != 2 )//判断参数是否是两个
    {
        printf( " No image data \n " );
        return -1;
    }

    char* imageName = argv[1];
    Mat image = imread( imageName, 1 );//读入图片;
    if(  !image.data)//判断是否有数据
    {
        printf( " No image data \n " );
        return -1;
    }

    namedWindow( imageName, CV_WINDOW_AUTOSIZE );
    imshow( imageName, image );//显示图片

    waitKey(0);
    return 0;
}

2. 写cmake的makefile,即CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(helloworld)
add_executable(helloworld helloworld.cpp)
find_package(OpenCV REQUIRED)
target_link_libraries(helloworld ${OpenCV_LIBS})

3. 进入该文件夹,创建build,mkdir build

4. 之后:

cmake .
make

得到可执行文件 helloworld

5. 拷贝一张图像到该可执行文件文件夹中,输入

./helloworld 11.jpg

显示图像,说明安装成功

ps

1. 之前未使用步骤1,结果编译没错,运行后,提示

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/XXX/file/program/opencv2411/modules/highgui/src/window.cpp, line 483 terminate called after throwing an instance of 'cv::Exception'

执行步骤1并重新编译了opencv之后,运行便显示图像了(感觉不需要所有的库都装上去,但是还是都装了)。

2. 如果提示没有安装cmake的话,安装一下cmake

3. 第6步中,/usr/local ..这样用就行了。开始一直以为这个是自己设置的目录,结果怎么编译都提示没有文件夹(对linux真心不熟)。。。

4. 如果使用NetBeans IDE的话,

不执行步骤1编译没错,运行时会有如下错误:

编译完之后,需要设置连接器中的库:

库目录如下:

 

添加opencv的库:

本来左侧是没有那一串的,点击“添加PkgConfig库”

出现如下界面,点击“opencv”

最终库里面如下(下图中应该还有库目录的设置,首先截的是这个图,所以没有):

编译后可成功运行。

并未像参考网址中那样,设置libiary等,但是可能那样以后会方便吧。

OpenCV官方教程中文版(For Python) PDF  http://www.linuxidc.com/Linux/2015-08/121400.htm

Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

OpenCV的详细介绍请点这里
OpenCV的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-07/132882.htm

linux
相关资讯       OpenCV 2.4.11  Ubuntu 16.04中安装OpenCV