Qt+OpenCV(一) 读取图像及程序发布流程

本文主要内容如下:

1.运行环境配置

2.图像读取及处理程序

3.程序发布流程

 

1.运行环境配置

1.1 Qt和OpenCV库下载

  • Qt下载官网:https://www.qt.io/download

选择开源版,下载对应系统的版本。首次进入需要进行注册,感觉麻烦的话,可以用百度云下载(版本:qt-opensource-windows-x86-msvc2013_64-5.7.1)  链接:https://pan.baidu.com/s/1OeoxNATMmCinCbZ4oRVTXQ      提取码:4t8e  

  • OpenCV下载官网:https://opencv.org/releases/

进入页面,选择对应的系统和版本进行下载。

 

1.2环境安装与配置

电脑已安装Visual Studio 2013

  • Qt版本:qt-opensource-windows-x86-msvc2013_64-5.7.1
  • OpenCV版本:opencv-2.4.9

 

  • 1.分别双击应用程序,进行Qt和OpenCV库的安装。建议不要安装在系统盘上,记住OpenCV库安装的路径,流程与一般软件安装类似

  • 2.环境变量设置
    选中桌面计算机图标,右击——>选择属性——>高级系统设置——>环境变量设置——>系统变量——>path中添加OpenCV和Qt路径

Qt+OpenCV(一) 读取图像及程序发布流程_第1张图片

Qt+OpenCV(一) 读取图像及程序发布流程_第2张图片

  • Qt头文件配置
    Qt头文件配置是将外部的OpenCV的库连接到Qt中,因此,新建一个项目时,需要配置一下头文件一般配置如下
    INCLUDEPATH += D:/ProtocolYue/Vison/opencv/build/include
    
    CONFIG(debug, debug|release): {
    LIBS +=  -LD:/ProtocolYue/Vison/opencv/build/x64/vc12/lib \
    -lopencv_core249d \
    -lopencv_imgproc249d \
    -lopencv_highgui249d \
    -lopencv_ml249d \
    -lopencv_video249d \
    -lopencv_features2d249d \
    -lopencv_calib3d249d \
    -lopencv_objdetect249d \
    -lopencv_contrib249d \
    -lopencv_legacy249d \
    -lopencv_flann249d
    } else:CONFIG(release, debug|release): {
    LIBS += -LD:/ProtocolYue/Vison/opencv/build/x64/vc12/lib \
    -lopencv_core249 \
    -lopencv_imgproc249 \
    -lopencv_highgui249 \
    -lopencv_ml249 \
    -lopencv_video249 \
    -lopencv_features2d249 \
    -lopencv_calib3d249 \
    -lopencv_objdetect249 \
    -lopencv_contrib249 \
    -lopencv_legacy249 \
    -lopencv_flann249
    }
    

    2.图像读取及处理程序

  • Qt工程文件
    #-------------------------------------------------
    #
    # Project created by QtCreator 2019-06-09T10:14:16
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = loadeImageAndProcess
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated 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\
            widget.cpp
    
    HEADERS  += widget.h
    
    FORMS    += widget.ui
    
    INCLUDEPATH += D:/ProtocolYue/Vison/opencv/build/include
    
    CONFIG(debug, debug|release): {
    LIBS +=  -LD:/ProtocolYue/Vison/opencv/build/x64/vc12/lib \
    -lopencv_core249d \
    -lopencv_imgproc249d \
    -lopencv_highgui249d \
    -lopencv_ml249d \
    -lopencv_video249d \
    -lopencv_features2d249d \
    -lopencv_calib3d249d \
    -lopencv_objdetect249d \
    -lopencv_contrib249d \
    -lopencv_legacy249d \
    -lopencv_flann249d
    } else:CONFIG(release, debug|release): {
    LIBS += -LD:/ProtocolYue/Vison/opencv/build/x64/vc12/lib \
    -lopencv_core249 \
    -lopencv_imgproc249 \
    -lopencv_highgui249 \
    -lopencv_ml249 \
    -lopencv_video249 \
    -lopencv_features2d249 \
    -lopencv_calib3d249 \
    -lopencv_objdetect249 \
    -lopencv_contrib249 \
    -lopencv_legacy249 \
    -lopencv_flann249
    }
    
  • widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include 

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

//读取图像与显示
void Widget::on_ReadImage_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this,tr("Open Image"),
                                        ".",tr("Image Files (*.png *.jpg *.bmp)"));
            qDebug()<<"filenames:"<imagelabel->size(),Qt::KeepAspectRatio);
   // ui->imagelabel->setPixmap(QPixmap::fromImage(img));
     ui->imagelabel->setPixmap(QPixmap::fromImage(imgScaled));
    ui->imagelabel->resize(ui->imagelabel->pixmap()->size());
}

//显示函数
void Widget::displayMat_2(Mat image)
{
    Mat rgb;
    QImage img;
    QImage imgScaled;

    qDebug()<<"channelsNum:"<imagelabel_2->size(),Qt::KeepAspectRatio);
     ui->imagelabel_2->setPixmap(QPixmap::fromImage(imgScaled));
    ui->imagelabel_2->resize(ui->imagelabel_2->pixmap()->size());
}


//图像处理
void  Widget::on_IdealImage_clicked()
{
    Mat image1,src_gray,dst;

//    QString fileName = QFileDialog::getOpenFileName(this,tr("Open Image"),
//                                        ".",tr("Image Files (*.png *.jpg *.bmp)"));
//    qDebug()<<"filenames:"<horizontalSlider->value();
     //   QString str = QString("%1").arg(pos);
        QString str = QString("%1").arg(value);
        ui->label->setText(str);
        Qvalue = value;

}

 

  • ·界面

Qt+OpenCV(一) 读取图像及程序发布流程_第3张图片

3.程序发布流程

在Qt中使用Release,运行工程文件。参考https://jingyan.baidu.com/article/af9f5a2d60997343140a45b3.html

依据连接中操作,完成了Qt软件的相关库添加。但还缺少Opencv的库文件,下载depends,打开Release时,生成的exe文件,即可查看依赖的OpenCV库,找到对应的文件,并复制到exe可执行的文件夹下,至此整个流程结束。
 

Qt+OpenCV(一) 读取图像及程序发布流程_第4张图片

 

Qt+OpenCV(一) 读取图像及程序发布流程_第5张图片

 

 

你可能感兴趣的:(Qt+OpenCV(一) 读取图像及程序发布流程)