当前位置:网站首页>QT based tensorrt accelerated yolov5
QT based tensorrt accelerated yolov5
2022-07-03 03:09:00 【AphilGuo】
Personal records
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, " Select Picture ", 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, " Tips ", " Start detection ");
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();
}
边栏推荐
- docker安装redis
- [C language] MD5 encryption for account password
- 力扣------网格中的最小路径代价
- 分布式事务
- Concrete CMS vulnerability
- Three. JS local environment setup
- Cron表达式介绍
- The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
- Sqlserver row to column pivot
- Source code analysis | layout file loading process
猜你喜欢
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/c7/6b5ab4ff7379bfccff7cdbb358ff8f.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

用docker 連接mysql的過程

【PyG】理解MessagePassing过程,GCN demo详解
![MySQL practice 45 [global lock and table lock]](/img/23/fd58c185ae49ed6c04f1a696f10ff4.png)
MySQL practice 45 [global lock and table lock]

你真的懂继电器吗?

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制

Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
![MySQL practice 45 lecture [row lock]](/img/71/344daddee537a96f0d38241e6896e1.png)
MySQL practice 45 lecture [row lock]

What is the way out for children from poor families?
![MySQL practice 45 [SQL query and update execution process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL practice 45 [SQL query and update execution process]
随机推荐
Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
I2C 子系统(二):I3C spec
从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
C # general interface call
Process the dataset and use labelencoder to convert all IDs to start from 0
模型转换onnx2engine
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
Kubernetes cluster log and efk architecture log scheme
I2C subsystem (I): I2C spec
Destroy the session and empty the specified attributes
Spark on yarn资源优化思路笔记
MySql实战45讲【SQL查询和更新执行流程】
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]
基于Qt的yolov5工程
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
Source code analysis | resource loading resources
C语言初阶-指针详解-庖丁解牛篇
左值右指解释的比较好的