当前位置:网站首页>基于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();
}
边栏推荐
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- Serious security vulnerabilities reported by moxa mxview network management software
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
- MySql实战45讲【索引】
- HW initial preparation
- MySQL practice 45 [global lock and table lock]
- Docker install MySQL
- HTB-Devel
- ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
- Edit and preview in the back pipe to get the value writing method of the form
猜你喜欢

内存泄漏工具VLD安装及使用

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

Le processus de connexion mysql avec docker

分布式事务

Distributed transaction

用docker 連接mysql的過程

I2C 子系統(四):I2C debug
![ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc](/img/cb/145937a27ef08050a370d5a255215a.jpg)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc

Spark on yarn资源优化思路笔记

一文带你了解 ZigBee
随机推荐
Distributed transaction
后管中编辑与预览获取表单的值写法
Creation and destruction of function stack frame
45 lectures on MySQL [index]
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
Force deduction ----- the minimum path cost in the grid
用docker 連接mysql的過程
I2C 子系统(一):I2C spec
vfork执行时出现Segmentation fault
你真的懂继电器吗?
从输入URL到页面展示这中间发生了什么?
Left connection, inner connection
内存泄漏工具VLD安装及使用
tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
Today, it's time to copy the bottom!
[C language] MD5 encryption for account password
Agile certification (professional scrum Master) simulation exercise-2
MySQL practice 45 [SQL query and update execution process]
Two dimensional format array format index subscript continuity problem leads to return JSON format problem