首页 > 代码库 > ubuntu14.04 + Qt5.4 + opencv2.4.10

ubuntu14.04 + Qt5.4 + opencv2.4.10

1、安装cmake
sudo apt-get install cmake

CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的automakeOpenCV使用cmake进行makefile的创建。

2、安装 opencv
OpenCV包解压到用户目录下,得到opencv文件夹
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
(注意..”前有空格)
make
等待大概十分钟make完成
sudo make install
至此opencv库安装到了/usr/local/lib目录下,重启电脑,或者执行sudo ldconfig
(关于ldconfig:ubuntu把在开机时所有库文件装入到缓存,这样避免每次使用链接库都需装载,提高系统的效率,ldconfig命令就是重新装载,可通过ldconfig -v查看已经在缓存里的库。)

3、安装Qt


example:

.pro 文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2015-01-25T16:37:17
#
#-------------------------------------------------

QT       += core

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = test
TEMPLATE = app


SOURCES += main.cpp

HEADERS  +=

FORMS    +=

INCLUDEPATH += /usr/local/include \
                /usr/local/include/opencv \
                /usr/local/include/opencv2

LIBS += /usr/local/lib/libopencv_highgui.so \
        /usr/local/lib/libopencv_core.so    \
        /usr/local/lib/libopencv_imgproc.so

main.cpp文件如下:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

int main(int argc, char *argv[])
{

    namedWindow( "src", WINDOW_AUTOSIZE );
    Mat src1 = imread( "lena.jpg" );
    while(1)
    {
        imshow( "src", src1 );
        char c =  waitKey(30);
        if( 27==c )
            return 0;
    }

}


ubuntu14.04 + Qt5.4 + opencv2.4.10