




版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 八年級物理:光和眼睛復(fù)習(xí)-新滬粵版八年級課件
- 七彩童年快樂六一兒童節(jié)活動策劃課件
- 執(zhí)業(yè)藥師考試公式與試題及答案
- 考試架構(gòu)衛(wèi)生資格考試試題及答案
- 2025年自考行政管理的關(guān)鍵試題與答案推介
- 2025年執(zhí)業(yè)藥師考試感染防控試題及答案
- 2025年衛(wèi)生資格考試高效備考指南試題及答案
- 藥師職業(yè)選擇及考試指導(dǎo)試題及答案
- 探索經(jīng)濟(jì)法概論考試試題及答案的多樣性
- 2025年衛(wèi)生資格考試自我提升試題及答案
- 物業(yè)承接查驗標(biāo)準(zhǔn)及表格
- 馬克思主義基本原理智慧樹知到課后章節(jié)答案2023年下湖南大學(xué)
- (完整版)數(shù)字信號處理教案(東南大學(xué))
- 第三章-綠色植物與生物圈的水循環(huán)-課件
- 公園EPC建設(shè)項目合同管理的監(jiān)理措施
- 保密警示教育課件
- 滬科版八年級全一冊《空氣的“力量”》教案及教學(xué)反思
- 青海省魚卡礦區(qū)魚卡二號井礦山地質(zhì)環(huán)境保護(hù)與土地復(fù)墾方案
- 提高大面積混凝土地面表面平整度課件
- 活動板房材料規(guī)格表大全
- 臺區(qū)線損綜合分析臺區(qū)線損分類及計算方法
評論
0/150
提交評論