Qt5.7.0 + OpenCV2.4.9 + ffmpeg在Ubuntu 14.04LTS下的配置

Qt5.7.0 + OpenCV2.4.9 + ffmpeg在Ubuntu 14.04LTS下的配置


分類:
tags: Ubuntu Qt OpenCV

?版權聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉載。
搬運自本人 CSDN 博客:https://blog.csdn.net/ajianyingxiaoqinghan/article/details/62424132


前言:這是我的第一篇MarkDown文檔,試手 + 記錄用,希望MarkDown能給我?guī)Ыo我很好的記錄習慣~

一、Qt 5.7.0的安裝

參考鏈接:http://blog.csdn.net/laizhenghong2012/article/details/51758164

1、安裝g++

安裝Qt之前安裝g++,以便在Qt的安裝過程中能夠檢測到系統(tǒng)已經(jīng)安裝了g++。減少后期配置的困難。

sudo apt-get install g++

2、安裝Qt5.7.0

筆者電腦是64位的,所以應該下載對應的64位版本。安裝軟件是在學校的IPV6內網(wǎng)中下載的,平常狀況下,應該在官網(wǎng)下載。
筆者的qt-opensource-linux-x64-5.7.0.run放在/home/grq/src文件夾下,先對文件實行權限更改:

chmod u+x ./qt-opensource-linux-x64-5.7.0.run

執(zhí)行安裝文件:

./qt-opensource-linux-x64-5.7.0.run

進入安裝界面,依次登陸,選擇安裝位置(注意:最好選擇具有讀寫權限的/home目錄下)


image

直到文件最后安裝完成。

3、配置Qt

安裝完后,還要配置Qt,否則是不能使用的。
當你在命令行下輸入qmake時,會報這樣的錯誤

qmake:could not exec '/usr/lib/x86_64-Linux-gnu/qt4/bin/qmake':NO such file or directory

(32位的ubuntu報的是這樣的錯 qmake:could not exec '/usr/lib/i386-linux-gnu/qt4/bin/qmake':NO such file or directory)
跟隨報錯信息,進入下面路徑中:

cd /usr/lib/x86_64-linux-gnu/qt-default/qtchooser
image

打開目錄下的default.conf文件:

sudo gedit /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

將配置文件中的內容改為實際的Qt安裝位置。例如筆者的default.conf文件如下所示:
<code>
/home/grq/kit/Qt5.7.0/5.7/gcc_64/bin
/home/grq/kit/Qt5.7.0
</code>

4、寫Hello World(參考其他鏈接)

image

運行得到:


image

注:運行時報錯<code>can't find lGl</code>,請參考:http://blog.csdn.net/wwkaven/article/details/37755259

二、ffmpeg的配置

參考鏈接:http://blog.csdn.net/micheal_w/article/details/45343873

如果安裝OpenCV時沒有安裝ffmpeg,則在調用OpenCV視頻處理函數(shù)時,將會導致讀取視頻失敗。

1、源碼下載

終端輸入如下指令,獲取ffmpeg源碼。

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

注:獲取源碼后建議備份。

2、文件配置

進入ffmpeg文件夾中,進行文件配置:

cd ./ffmpeg
./configure --enable-shared --enable-gpl --enable-swscale

如果在<code>configure</code>中遇到提醒,缺少<code>--disable-yasm</code>時,添加該項即可:

./configure --enable-shared --enable-gpl --enable-swscale --disable-yasm

3、ffmpeg安裝

make
sudo make install

4、關于'cmp'的bug

當執(zhí)行<code>make</code>操作時,出現(xiàn)如下bug:
<code>
libavcodec/x86/h264_qpel_mmx.c: Assembler messages:
libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch for cmp' libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch forcmp'
libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch for cmp' libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch forcmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for cmp' libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch forcmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
make[5]: *** [libavcodec/x86/dsputil_mmx.o] Error 1
</code>
解決方案:
將目錄下的文件:<code>./ffmpeg/libavcodec/x86/h264_qpel_mmx.c</code>文件中的"g"替換為"rm"。
使用gedit打開文檔:

sudo gedit ./ffmpeg/libavcodec/x86/h264_qpel_mmx.c

然后可以使用gedit中的替換功能。

三、OpenCV 2.4.9 的安裝

參考鏈接:http://blog.csdn.net/guo8113/article/details/29211041
http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/

1、安裝build-essential:

sudo apt-get install build-essential

2、安裝CMake:

sudo apt-get install cmake

3、安裝一些依賴庫與組件:

sudo apt-get install libgtk2.0-dev pkg-config python-dev  python-numpy libavcodec-dev libavformat-dev libswscale-dev libdc1394-22  libjpeg-dev libpng-dev libtiff-dev libjasper-dev

其中,最后四個包是可選的。

4、獲取OpenCV源碼

可前往官網(wǎng),尋找下載OpenCV 2.4.9的Linux版源碼:http://opencv.org/releases.html
下載得到OpenCV2.4.9.zip,解壓到目錄中。

5、安裝OpenCV

此處使用release版本,所以在OpenCV文件夾下建造目錄release。

cd ./opencv-2.4.9
mkdir release
cd ./release

對OpenCV進行CMake,命令如下:

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

注:一定要加上后面兩個點 "..",兩個點..代表上級目錄的意思

cmake配置結束后,可以看到一系列編譯配置情況。其中一定要注意檢查ffmpeg的編譯情況:
[圖片上傳失敗...(image-27c196-1527078270078)]

確定編譯過程中會對如下模塊進行編譯:
<code>core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib java python stitching superres ts videostab viz.</code>

然后編譯、安裝OpenCV:

make
sudo make install

安裝過程比較慢,筆者較高的配置下也得編譯20分鐘。可以稍事休息。

6、更新系統(tǒng)庫文件配置

sudo ldconfig

這樣可以直接重新加載系統(tǒng)中使用的庫,就不用重啟電腦就可用OpenCV庫了。

四、OpenCV + Qt5.7.0程序測試

創(chuàng)建工程OpenCV_Test,在OpenCV_Test.pro文件中最后加入:
<code>
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
/usr/local/lib/libopencv_photo.so
/usr/local/lib/libopencv_calib3d.so
</code>
main.cpp如下:

#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <iostream>
#include <unistd.h>
#include <cctype>
#include <algorithm>

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

using namespace std;
using namespace cv;

int main(int argc, char **argv)
{
    char key;
    // 幀速率
    int fps = 25;

    string VideoPath = "/home/grq/style.mp4";
    VideoCapture video(VideoPath);

    if(!video.isOpened())
    {
        cout<<"Video Open Error!"<<endl;
        return 1;
    }
    else
        cout<<"Video Opened."<<endl;

    Mat frame;
    namedWindow("Frame");
    for(;;)
    {
        if(!video.read(frame))
        {
            cout<<"No Frame!"<<endl;
            break;
        }
        imshow("Frame", frame);

        key = (char) cvWaitKey(1000 / fps);
        if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
            break;
    }
    return 0;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容