QT5.9.3安裝及編譯&與vs2013環境配置&opencv配置及呼叫
初次使用QT,安裝時就遇到了一些問題,除錯加整理檔案用了三天,現在總結出來,希望有所幫助。
最終選擇版本:
Windows7+Qt5.9.3(包含QtCreator4.4.1)+VS2013+OpenCV3.3.0+cmake3.10.0
一、 Qt及QtCreator的下載與安裝
在資源下載頁面(http://download.qt.io/archive/qt/)進行下載,這裡羅列了多有可用版本,便於選擇。根據自己的開發需要,我們這裡下載的版本是:qt-opensource-windows-x86-5.9.3.exe
二、 QT安裝
執行qt-opensource-windows-x86-5.9.3.exe,下一步即可;
Skip即可;
直接點選下一步;
選擇好安裝資料夾,建議不要將QT安裝在C盤,其他保持預設即可,點選下一步;
我們這裡勾選了MinGW及VS(msvc2013)相關的編譯器;Tools全部進行了勾選。
接著,在開啟的頁面中勾選“我已閱讀並同意條款”,然後一路下一步,直到安裝完成就可以了。
等待至安裝完成。
三、 三、QT creator開啟與建立
安裝好的QT5.9.3直接包含qt creator4.4.1在內,開啟qt creator4.4.1。
點選工具——>選項——>構建與執行——>構建套件——>選擇系統自動檢測出的編譯器並配置編譯器如圖所示:
點選ok。
新建專案進行程式設計操作即可。
四、 VS2013與opencv3.3.0配置
參考連結如下:
(2)為方便實現永久配置,配置OpenCV3.3動態連結庫及以後的操作,參照第二個連結如下:
五、 QT5.9.3與opencv3.3.0配置
參考連結如下:
https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows (windows下QT5.9.3與opencv3.3.0配置)需要注意的的地方是,在configure cmake對opencv產生解決方案前,需將cmake的路徑:D:\opencv\cmake-3.10.0-rc1-win64-x64\bin(才開始因解壓時未注意,路徑為
及MinGW的路徑:D:\Qt\Qt5.9.3\5.9.3\mingw53_32\bin與D:\Qt\Qt5.9.3\Tools\mingw530_32\bin 這三個環境變數都新增至系統環境變數的path中,才能進行的了configure操作。其餘詳細參照以上鍊接操作即可。更改QT中檔案程式碼如檔案《opencv在QT中配置程式碼》,詳細如下:
modify the .pro file like this:
#-------------------------------------------------
#
# Project created by QtCreator2017-03-05T12:30:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
# The following define makes yourcompiler emit warnings if you use
# any feature of Qt which as been markedas deprecated (the exact warnings
# depend on your compiler). Pleaseconsult the documentation of the
# deprecated API in order to know how toport your code away from it.
DEFINES +=QT_DEPRECATED_WARNINGS
# You can also make your code fail tocompile if you use deprecated APIs.
# In order to do so, uncomment thefollowing line.
# You can also select to disabledeprecated APIs only up to a certain version of Qt.
#DEFINES +=QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_core330.dll
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_highgui330.dll
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_imgcodecs330.dll
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_imgproc330.dll
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_features2d330.dll
LIBS+=D:\opencv\OpenCV_QT\bin\libopencv_calib3d330.dll
# more correct variant, how setincludepath and libs for mingw
# add system variable:OPENCV_SDK_DIR=D:/opencv/build
# read http://doc.qt.io/qt-5/qmake-variable-reference.html#libs
#INCLUDEPATH += $$(OPENCV_SDK_DIR)/include
#LIBS +=-L$$(OPENCV_SDK_DIR)/x86/mingw/lib \
# -lopencv_core320 \
# -lopencv_highgui320 \
# -lopencv_imgcodecs320 \
# -lopencv_imgproc320 \
# -lopencv_features2d320 \
# -lopencv_calib3d320
and modify mainwindow.cpp like this:(測試程式碼)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget*parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// read an image
cv::Mat image = cv::imread("d://1.jpg", 1);
// create imagewindow named "My Image"
cv::namedWindow("My Image");
// show theimage on window
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
筆者因為粗心,在前面.pro檔案中的