




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第Qt結(jié)合OpenCV部署yolov5的實現(xiàn)connect(timer,SIGNAL(timeout()),this,SLOT(readFrame()));
ui-startdetect-setEnabled(false);
ui-stopdetect-setEnabled(false);
Init();
MainWindow::~MainWindow()
capture-release();
deletecapture;
delete[]yolo_nets;
deleteyolov5;
deleteui;
voidMainWindow::Init()
capture=newcv::VideoCapture();
yolo_nets=newNetConfig[4]{
{0.5,0.5,0.5,"yolov5s"},
{0.6,0.6,0.6,"yolov5m"},
{0.65,0.65,0.65,"yolov5l"},
{0.75,0.75,0.75,"yolov5x"}
conf=yolo_nets[0];
yolov5=newYOLOV5();
yolov5-Initialization(conf);
ui-textEditlog-append(QStringLiteral("默認(rèn)模型類別:yolov5sargs:%1%2%3")
.arg(conf.nmsThreshold)
.arg(conf.objThreshold)
.arg(conf.confThreshold));
voidMainWindow::readFrame()
cv::Matframe;
capture-read(frame);
if(frame.empty())return;
autostart=std::chrono::steady_clock::now();
yolov5-detect(frame);
autoend=std::chrono::steady_clock::now();
std::chrono::durationdouble,std::millielapsed=end-start;
ui-textEditlog-append(QString("cost_time:%1ms").arg(elapsed.count()));
//doublet0=static_castdouble(cv::getTickCount());
//yolov5-detect(frame);
//doublet1=static_castdouble(cv::getTickCount());
//ui-textEditlog-append(QStringLiteral("cost_time:%1").arg((t1-t0)/cv::getTickFrequency()));
cv::cvtColor(frame,frame,cv::COLOR_BGR2RGB);
QImagerawImage=QImage((uchar*)(frame.data),frame.cols,frame.rows,frame.step,QImage::Format_RGB888);
ui-label-setPixmap(QPixmap::fromImage(rawImage));
voidMainWindow::on_openfile_clicked()
QStringfilename=QFileDialog::getOpenFileName(this,QStringLiteral("打開文件"),".","*.mp4*.avi;;*.png*.jpg*.jpeg*.bmp");
if(!QFile::exists(filename)){
return;
ui-statusbar-showMessage(filename);
QMimeDatabasedb;
QMimeTypemime=db.mimeTypeForFile(filename);
if(().startsWith("image/")){
cv::Matsrc=cv::imread(filename.toLatin1().data());
if(src.empty()){
ui-statusbar-showMessage("圖像不存在!");
return;
cv::Mattemp;
if(src.channels()==4)
cv::cvtColor(src,temp,cv::COLOR_BGRA2RGB);
elseif(src.channels()==3)
cv::cvtColor(src,temp,cv::COLOR_BGR2RGB);
else
cv::cvtColor(src,temp,cv::COLOR_GRAY2RGB);
autostart=std::chrono::steady_clock::now();
yolov5-detect(temp);
autoend=std::chrono::steady_clock::now();
std::chrono::durationdouble,std::millielapsed=end-start;
ui-textEditlog-append(QString("cost_time:%1ms").arg(elapsed.count()));
QImageimg=QImage((uchar*)(temp.data),temp.cols,temp.rows,temp.step,QImage::Format_RGB888);
ui-label-setPixmap(QPixmap::fromImage(img));
ui-label-resize(ui-label-pixmap()-size());
filename.clear();
}elseif(().startsWith("video/")){
capture-open(filename.toLatin1().data());
if(!capture-isOpened()){
ui-textEditlog-append("failtoopenMP4!");
return;
IsDetect_ok+=1;
if(IsDetect_ok==2)
ui-startdetect-setEnabled(true);
ui-textEditlog-append(QString::fromUtf8("Openvideo:%1succesfully!").arg(filename));
//獲取整個幀數(shù)QStringLiteral
longtotalFrame=capture-get(cv::CAP_PROP_FRAME_COUNT);
ui-textEditlog-append(QStringLiteral("整個視頻共%1幀").arg(totalFrame));
ui-label-resize(QSize(capture-get(cv::CAP_PROP_FRAME_WIDTH),capture-get(cv::CAP_PROP_FRAME_HEIGHT)));
//設(shè)置開始幀()
longframeToStart=0;
capture-set(cv::CAP_PROP_POS_FRAMES,frameToStart);
ui-textEditlog-append(QStringLiteral("從第%1幀開始讀").arg(frameToStart));
//獲取幀率
doublerate=capture-get(cv::CAP_PROP_FPS);
ui-textEditlog-append(QStringLiteral("幀率為:%1").arg(rate));
voidMainWindow::on_loadfile_clicked()
QStringonnxFile=QFileDialog::getOpenFileName(this,QStringLiteral("選擇模型"),".","*.onnx");
if(!QFile::exists(onnxFile)){
return;
ui-statusbar-showMessage(onnxFile);
if(!yolov5-loadModel(onnxFile.toLatin1().data())){
ui-textEditlog-append(QStringLiteral("加載模型失敗!"));
return;
IsDetect_ok+=1;
ui-textEditlog-append(QString::fromUtf8("OpenonnxFile:%1succesfully!").arg(onnxFile));
if(IsDetect_ok==2)
ui-startdetect-setEnabled(true);
voidMainWindow::on_startdetect_clicked()
timer-start();
ui-startdetect-setEnabled(false);
ui-stopdetect-setEnabled(true);
ui-openfile-setEnabled(false);
ui-loadfile-setEnabled(false);
ui-comboBox-setEnabled(false);
ui-textEditlog-append(QStringLiteral("================\n"
"開始檢測\n"
"================\n"));
voidMainWindow::on_stopdetect_clicked()
ui-startdetect-setEnabled(true);
ui-stopdetect-setEnabled(false);
ui-openfile-setEnabled(true);
ui-loadfile-setEnabled(true);
ui-comboBox-setEnabled(true);
timer-stop();
ui-textEditlog-append(QStringLiteral("================\n"
"停止檢測\n"
"================\n"));
voidMainWindow::on_comboBox_activated(constQStringarg1)
if(arg1.contains("s")){
conf=yolo_nets[0];
}elseif(arg1.contains("m")){
conf=yolo_nets[1];
}elseif(arg1.contains("l")){
conf=yolo_nets[2];
}elseif(arg1.contains("x")){
conf=yolo_nets[3];}
yolov5-Initialization(conf);
ui-textEditlog-append(QStringLiteral("使用模型類別:%1args:%2%3%4")
.arg(arg1)
.arg(con
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)內(nèi)部管理中的區(qū)塊鏈技術(shù)應(yīng)用
- 從數(shù)據(jù)安全到業(yè)務(wù)協(xié)同看區(qū)塊鏈在供應(yīng)中的應(yīng)用價值
- 從行業(yè)視角看醫(yī)療數(shù)據(jù)安全及患者信息泄露的預(yù)防措施研究報告
- 醫(yī)療設(shè)備創(chuàng)新中的知識產(chǎn)權(quán)保護(hù)方法
- 醫(yī)療健康產(chǎn)業(yè)發(fā)展中的資源規(guī)劃與布局
- AI技術(shù)在醫(yī)療教育中的倫理挑戰(zhàn)與對策
- 公司出資買房合同范例
- 醫(yī)療大數(shù)據(jù)在健康管理中的價值與隱私保護(hù)的平衡
- 代理招商授權(quán)合同范例
- 亞馬遜運(yùn)營托管合同范例
- 中外比較文學(xué)研究專題智慧樹知到期末考試答案2024年
- 心臟康復(fù)護(hù)理專家共識
- CO2氣體保護(hù)焊-基本操作方法(焊接技能)
- (高清版)TDT 1012-2016 土地整治項目規(guī)劃設(shè)計規(guī)范
- 河南安陽的紅色故事
- 基于PLC的蔬菜大棚設(shè)計
- 家政保姆護(hù)工培訓(xùn)課件
- 糖尿病足圍手術(shù)期護(hù)理
- 鄉(xiāng)村振興中的鄉(xiāng)村安全與穩(wěn)定維護(hù)
- 《醫(yī)院勞動合同書》電子版
- 營銷策劃 -菌小寶益生菌2023品牌介紹手冊
評論
0/150
提交評論