Qt+OpenCV實現(xiàn)目標檢測詳解_第1頁
Qt+OpenCV實現(xiàn)目標檢測詳解_第2頁
Qt+OpenCV實現(xiàn)目標檢測詳解_第3頁
Qt+OpenCV實現(xiàn)目標檢測詳解_第4頁
Qt+OpenCV實現(xiàn)目標檢測詳解_第5頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

第Qt+OpenCV實現(xiàn)目標檢測詳解QStringfilename=QFileDialog::getOpenFileName(this,"打開文件",".","*.mp4*.avi;;*.png*.jpg*.jpeg*.bmp");

if(!QFile::exists(filename)){

return;

ui-statusbar-showMessage(filename);

IsDetect_ok+=1;

if(IsDetect_ok==2)

ui-pushButton_StartDetect-setEnabled(true);

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);

QImageimg=QImage((uchar*)temp.data,temp.cols,temp.rows,temp.step,QImage::Format_RGB888);

ui-label_raw-setPixmap(QPixmap::fromImage(img));

ui-label_raw-resize(ui-label_raw-pixmap()-size());

filename.clear();

}elseif(().startsWith("video/")){

capture-open(filename.toLatin1().data());

if(!capture-isOpened()){

ui-textEdit_log-append("failtoopenMP4!");

return;

ui-textEdit_log-append(QString::fromUtf8("Openvideo:%1succesfully!").arg(filename));

//獲取整個幀數(shù)

longtotalFrameNumber=capture-get(CV_CAP_PROP_FRAME_COUNT);

ui-textEdit_log-append(QString::fromUtf8("整個視頻共%1幀").arg(totalFrameNumber));

ui-label_raw-resize(QSize(capture-get(CV_CAP_PROP_FRAME_WIDTH),capture-get(CV_CAP_PROP_FRAME_HEIGHT)));

//設置開始幀()

longframeToStart=0;

capture-set(CV_CAP_PROP_POS_FRAMES,frameToStart);

ui-textEdit_log-append(QString::fromUtf8("從第%1幀開始讀").arg(frameToStart));

//獲取幀率

doublerate=capture-get(CV_CAP_PROP_FPS);

ui-textEdit_log-append(QString::fromUtf8("幀率為:%1").arg(rate));

voidMainWindow::on_pushButton_StartDetect_clicked()

timer-start();

ui-pushButton_StartDetect-setEnabled(false);

ui-pushButton_StopDetect-setEnabled(true);

voidMainWindow::on_pushButton_StopDetect_clicked()

ui-pushButton_StartDetect-setEnabled(true);

ui-pushButton_StopDetect-setEnabled(false);

timer-stop();

voidMainWindow::on_pushButton_FlushDevice_clicked()

QStringxmlfilename=QFileDialog::getOpenFileName(this,"打開文件",".","*.xml");

if(!QFile::exists(xmlfilename)){

return;

ui-statusbar-showMessage(xmlfilename);

if(!classifier-load(xmlfilename.toLatin1().data())){

ui-textEdit_log-append("failtoopenclassifier_path!");

return;

IsDetect_ok+=1;

ui-textEdit_log-append(QString::fromUtf8("Openxmlfile:%1succesfully!").arg(xmlfilename));

if(IsDetect_ok==2)

ui-pushButton_StartDetect-setEnabled(true);

}

演示效果

拓展閱讀

直接在屬性欄目搜索中設置(如下圖),或者pushbutton設置icon和文字

下面是pushbutton設置icon和文字的四種方法詳解

1.使用系統(tǒng)自帶api

ui-pushButton-setIconSize(QSize(32,32));

ui-pushButton-setIcon(QIcon(":/images/Setting.png"));

ui-pushButton-setText(QString::fromLocal8Bit("系統(tǒng)設置"));

ui-pushButton-setStyleSheet("QPushButton{border:1pxsolidblue;background:white;}"

"QPushButton:hover{border:0px;background:blue;}"

"QPushButton:pressed{border:0px;background:red;}");

無法設置icon和文字之間的距離。

2.如果想讓icon顯示在文字上方可使用QToolButton

ui-toolButton-setIconSize(QSize(32,32));

ui-toolButton-setIcon(QIcon(":/images/Setting.png"));

ui-toolButton-setText(QString::fromLocal8Bit("系統(tǒng)設置"));

ui-toolButton-setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

3.在pushbutton上面使用label進行布局

QLabel*iconLabel=newQLabel;

QLabel*textLabel=newQLabel;

iconLabel-setFixedSize(32,32);

iconLabel-setStyleSheet("border:1pxsolidred;");

textLabel-setStyleSheet("border:1pxsolidred;");

iconLabel-setPixmap(QPixmap(":/images/Setting.png"));

textLabel-setText(QString::fromLocal8Bit("系統(tǒng)設置"));

textLabel-setFixedWidth(60);

QHBoxLayout*myLayout=newQHBoxLayout();

myLayout-addSpacing(10);

myLayout-addWidget(iconLabel);

myLayout-addSpacing(30);

myLayout-addWidget(textLabel);

myLayout-addStretch();

ui-pushButton_2-setLayout(myLayout);

ui-pushButton_2-setStyleSheet("QPushButton{border:1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論