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