当前位置:网站首页>基于QT的tensorRT加速的yolov5
基于QT的tensorRT加速的yolov5
2022-07-03 03:06:00 【AphilGuo】
个人记录
yolov5Detection.h
#pragma once
#pragma execution_character_set("utf-8")
#include <QtWidgets/QMainWindow>
#include <opencv2/opencv.hpp>
#include "ui_Yolov5Detection.h"
#include <QLabel>
class Yolov5Detection : public QMainWindow
{
Q_OBJECT
public:
Yolov5Detection(QWidget *parent = Q_NULLPTR);
// ~Yolov5Detection();
void ShowImage(QImage& src);
QImage MatToImage(cv::Mat& image);
void YoloDetect(cv::Mat& image);
private:
Ui::Yolov5DetectionClass ui;
cv::Mat img;
cv::Mat c_img;
cv::Mat* temp_img;
QImage src;
QLabel* label;
int click_num=0;
int close_num = 0;
// cv::VideoCapture* capture;
private slots:
void on_OpenImagePushButton_clicked();
void on_DetectPushButton_clicked();
void on_OpenCamPushButton_clicked();
void on_ExitPushButton_clicked();
};
yolov5Detection.cpp
#include "Yolov5Detection.h"
#include <QFileDialog>
#include <QDir>
#include <QPixmap>
#include <QByteArray>
#include <QMessageBox>
#include <QLabel>
#include "Detection.h"
#include "yololayer.h"
#include <opencv2/dnn.hpp>
Yolov5Detection::Yolov5Detection(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void Yolov5Detection::ShowImage(QImage& src)
{
label = new QLabel;
label->setPixmap(QPixmap::fromImage(src));
ui.ShowImageScrollArea->setWidget(label);
}
QImage Yolov5Detection::MatToImage(cv::Mat& img)
{
QImage new_img((uchar*)img.data, img.cols, img.rows, img.cols * 3, QImage::Format_BGR888);
return new_img;
}
void Yolov5Detection::on_OpenImagePushButton_clicked()
{
close_num = 1;
auto strPath = QFileDialog::getOpenFileName(nullptr, "选择图片", QDir::homePath(), "Images (*.jpg *.jpeg *png *bmp)");
this->src.load(strPath);
ShowImage(src);
cv::String imgPath = strPath.toStdString();
img = cv::imread(imgPath);
c_img = img.clone();
click_num = 0;
}
void Yolov5Detection::YoloDetect(cv::Mat& image)
{
Connect connect;
YOLOV5* yolo = connect.Create_YOLOV5_Object();
std::vector<cv::Rect> Boxes;
std::vector<const char*> ClassLables;
yolo->Initialize("./yolov5.engine", 0);
yolo->Detecting(image, Boxes, ClassLables);
connect.Delete_YOLOV5_Object(yolo);
}
void Yolov5Detection::on_DetectPushButton_clicked()
{
temp_img = new cv::Mat();
temp_img = &c_img;
QMessageBox::information(nullptr, "提示", "开始检测");
YoloDetect(*temp_img);
QImage temp = MatToImage(*temp_img);
ShowImage(temp);
click_num = 1;
}
void Yolov5Detection::on_OpenCamPushButton_clicked()
{
close_num = 0;
cv::VideoCapture capture;
capture.open(0);
while(true)
{
cv::Mat frame;
capture >> frame;
c_img = frame;
if (click_num%2==1)
YoloDetect(frame);
QImage temp = MatToImage(frame);
ShowImage(temp);
cv::waitKey(10);
if (close_num == 1)
break;
}
capture.release();
cv::destroyAllWindows();
}
void Yolov5Detection::on_ExitPushButton_clicked()
{
close_num = 1;
QWidget::close();
}
边栏推荐
- Force deduction ----- the minimum path cost in the grid
- Super easy to use logzero
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
- Agile certification (professional scrum Master) simulation exercises
- The difference between left value and right value in C language
- The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
- SqlServer行转列PIVOT
- Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
- SQL server queries the table structure of the specified table
- TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
猜你喜欢

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)

MySql实战45讲【索引】

C语言初阶-指针详解-庖丁解牛篇

Left connection, inner connection

Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记

Sqlserver row to column pivot

Your family must be very poor if you fight like this!

敏捷认证(Professional Scrum Master)模拟练习题-2

Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training

Kubernetes family container housekeeper pod online Q & A?
随机推荐
Yiwen takes you to know ZigBee
左连接,内连接
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
Anhui University | small target tracking: large-scale data sets and baselines
I2C 子系统(二):I3C spec
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
MySql实战45讲【全局锁和表锁】
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
How to implement append in tensor
How to make backgroundworker return an object
Pytest (6) -fixture (Firmware)
tensor中的append应该如何实现
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
【PyG】理解MessagePassing过程,GCN demo详解
Introduction to cron expression
open file in 'w' mode: IOError: [Errno 2] No such file or directory
Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常