当前位置:网站首页>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();
}
边栏推荐
- Edit and preview in the back pipe to get the value writing method of the form
- C # general interface call
- Spark on yarn资源优化思路笔记
- Three.js本地环境搭建
- 左值右指解释的比较好的
- The core idea of performance optimization, dry goods sharing
- VS 2019 配置tensorRT生成engine
- Le processus de connexion mysql avec docker
- Opengauss database development and debugging tool guide
- Use cve-2021-43893 to delete files on the domain controller
猜你喜欢
Agile certification (professional scrum Master) simulation exercise-2
Sous - système I2C (IV): débogage I2C
左连接,内连接
docker安装mysql
Pytest (6) -fixture (Firmware)
VS 2019配置tensorRT
MySQL practice 45 lecture [transaction isolation]
Anhui University | small target tracking: large-scale data sets and baselines
Your family must be very poor if you fight like this!
docker安装redis
随机推荐
Do you really understand relays?
js根据树结构查找某个节点的下面的所有父节点或者子节点
Getting started | jetpack hilt dependency injection framework
Pytest (6) -fixture (Firmware)
Sous - système I2C (IV): débogage I2C
labelimg生成的xml文件转换为voc格式
Docker install MySQL
I2C 子系統(四):I2C debug
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
分布式事务
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
I2C 子系统(一):I2C spec
Are there any recommended term life insurance products? I want to buy a term life insurance.
As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
el-tree搜索方法使用
docker安装mysql
Sqlserver row to column pivot
I2C 子系统(三):I2C Driver
模糊查询时报错Parameter index out of range (1 > number of parameters, which is 0)
BigVision代码