当前位置:网站首页>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();
}
边栏推荐
- VS 2019安装及配置opencv
- Basic information of Promethus (I)
- The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
- Use optimization | points that can be optimized in recyclerview
- SqlServer行转列PIVOT
- BigVision代码
- PHP constructor with parameters - PHP constructor with a parameter
- Parameter index out of range (1 > number of parameters, which is 0)
- Counter统计数量后,如何返回有序的key
- Force deduction ----- the minimum path cost in the grid
猜你喜欢
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
MySql实战45讲【索引】
I2C subsystem (III): I2C driver
The process of connecting MySQL with docker
idea 加载不了应用市场解决办法(亲测)
VS 2019 配置tensorRT生成engine
I2C 子系统(四):I2C debug
MySql实战45讲【事务隔离】
I2C subsystem (II): I3C spec
Pytest (6) -fixture (Firmware)
随机推荐
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
二维数组中的元素求其存储地址
VS 2019配置tensorRT
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
The core idea of performance optimization, dry goods sharing
I2C 子系统(二):I3C spec
The process of connecting MySQL with docker
labelme标记的文件转换为yolov5格式
[error record] the parameter 'can't have a value of' null 'because of its type, but the im
分布式事务
Change cell color in Excel using C - cell color changing in Excel using C
Agile certification (professional scrum Master) simulation exercise-2
ComponentScan和ComponentScans的区别
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
用docker 连接mysql的过程
[leectode 2022.2.15] lucky numbers in the matrix
Source code analysis | resource loading resources
Add automatic model generation function to hade
Kubernetes family container housekeeper pod online Q & A?