C语言Qt5+opencv4——基础界面、读图、显示视频、显示本地文件

C语言Qt5——基础界面、读图、显示视频、显示本地文件

先上效果图

在这里插入图片描述
在这里插入图片描述

源码备份

配置文件.pro

#-------------------------------------------------
#
# Project created by QtCreator 2021-05-15T15:38:21
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 21_0515_Qt_test3
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has 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

CONFIG += c++11
INCLUDEPATH+= D:/Opencv420/opencv420_build/install/include/opencv2 \
                   D:/Opencv420/opencv420_build/install/include


LIBS+=D:/Opencv420/opencv420_build/install/x64/vc14/lib/opencv_*d.lib

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

mainwindow.h

#if defined(_MSC_VER) && (_MSC_VER >= 1600)
# pragma execution_character_set("utf-8")
#endif
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

/*Qt相关*/
#include <QMainWindow>
#include <QWidget>
#include <QPushButton>
#include <QFileDialog>
#include <QLabel>
#include<QVBoxLayout>//窗口布局,垂直变化
#include<QHBoxLayout>//窗口布局,水平变化
#include<QGridLayout>//格子窗口
#include<QLabel>//提示文字
#include<QTimer>//定时器,用于显示图像

#include<QTextCodec>
#include<QMessageBox>

#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <time.h>
#include <ctime>
#include <iostream>
#include <string>
#include<opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <stdlib.h> //
#include <time.h> //
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/ml/ml.hpp>
#include<opencv2\opencv.hpp>
#include <opencv2\imgproc\types_c.h>


using namespace cv;
using namespace std;

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
private:
    /*控件*/
    QPushButton *MainButton_1;
    QPushButton *MainButton_2;
    QPushButton *MainButton_3;
    QPushButton *MainButton_4;
    QLabel      *Label_1;

    /*opencv相关*/
    cv::Mat frame;
    cv::VideoCapture capture;
    QImage  image;
    QTimer *timer1, *timer2;
    double rate; //FPS
    cv::VideoWriter writer;   //make a video record

private slots:
    void on_pushButton_open_picture_clicked();
    void on_pushButton_open_camera_clicked();
    void on_pushButton_open_local_video_clicked();
    void on_pushButton_start_detetion_clicked();
    void nextFrame_yuanshitu();
};

#endif // MAINWINDOW_H

完整代码见:C语言Qt5+opencv4——基础界面、读图、显示视频、显示本地文件

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翟羽嚄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值