Repository: lanbing510/ImageLabel Branch: master Commit: 849716a17d45 Files: 14 Total size: 84.9 KB Directory structure: gitextract_xq1sfgw6/ ├── README.md ├── released/ │ ├── history.ini │ └── set.ini └── src/ ├── Label.pro ├── Label.pro.user ├── Label.pro.user.61d9454 ├── Label.pro.user.722262d ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── setparameterdialog.cpp ├── setparameterdialog.h └── setparameterdialog.ui ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # 图像标注工具 前段时间由于工作需要对图像中目标进行像素级标注,自己写的小工具,在此分享给大家 ###环境: QT+Opencv实现 ###实现功能: 1 标注任意格式的图像 2 可手动绘制轮廓进行标注 3 可利用GrabCut进行半自动标注 4 支持Hull类型及Poly类型多种轮廓 5 支持各种后退重做等快捷键功能 6 可记录标注进度及标注所用时间 软件截图如下: 左侧第一个目标为GrabCut进行标注的示例,第二个为手动标注的结果 ###快捷键说明: 1 CTRL+S Save,保存标注的图像 2 CTRL+R Redo,重新进行标注 3 CTRL+U Undo,后退一步 4 手动模式下,鼠标左键进行轮廓绘制,鼠标中键也可进行后退一步的操作,绘制完成后右键进行填充完成 5 自动模式下,鼠标左键直接在目标周围拖出一个矩形-->右键-->Ctrl+右键进行轮廓绘制-->Ctrl+右键填充;为了更精确的提取轮廓,可为GrabCut提供更多的信息:Shift+左键: GC_FG,Ctrl+左键: GC_BG,Alt+左键: GC_PR_FG,LeftClick: GC_PR_BG,参数相关信息可以查阅Opencv文档 ================================================ FILE: released/history.ini ================================================ ================================================ FILE: released/set.ini ================================================ SequencePath=E:\Research\HP\Data\VIVID\egtest04_bmp FileFormat=frame%.5d.bmp OutputPath=E:\Research\HP\Data\Labeled\egtest04 StartFrame=0 ================================================ FILE: src/Label.pro ================================================ #------------------------------------------------- # # Project created by QtCreator 2015-04-02T15:13:39 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Label TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ setparameterdialog.cpp HEADERS += mainwindow.h \ setparameterdialog.h FORMS += mainwindow.ui \ setparameterdialog.ui INCLUDEPATH += D:/Libraries/opencv249/build/include/ \ D:/Libraries/opencv249/build/include/opencv LIBS += -LD:/Libraries/opencv249/build/x64/vc12/lib \ -LD:/Libraries/opencv249/build/x64/vc12/bin \ -lopencv_calib3d249 \ -lopencv_contrib249 \ -lopencv_core249 \ -lopencv_features2d249 \ -lopencv_flann249 \ -lopencv_gpu249 \ -lopencv_highgui249 \ -lopencv_imgproc249 \ -lopencv_legacy249 \ -lopencv_ml249 \ -lopencv_nonfree249 \ -lopencv_objdetect249 \ -lopencv_ocl249 \ -lopencv_photo249 \ -lopencv_stitching249 \ -lopencv_superres249 \ -lopencv_ts249 \ -lopencv_video249 \ -lopencv_videostab249 \ ================================================ FILE: src/Label.pro.user ================================================ EnvironmentId {dbd1f9ef-49c6-4a07-a222-5d5c8e36393a} ProjectExplorer.Project.ActiveTarget 0 ProjectExplorer.Project.EditorSettings true false true Cpp CppGlobal QmlJS QmlJSGlobal 2 UTF-8 false 4 false 80 true true 1 true false 0 true 0 8 true 1 true true true false ProjectExplorer.Project.PluginSettings ProjectExplorer.Project.Target.0 Desktop Qt 5.4.0 MSVC2013 OpenGL 64bit Desktop Qt 5.4.0 MSVC2013 OpenGL 64bit qt.54.win64_msvc2013_64_opengl_kit 1 0 0 E:/2015/Project/Qt/build-Label-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Debug true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 构建 ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 清理 ProjectExplorer.BuildSteps.Clean 2 false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true E:/2015/Project/Qt/build-Label-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Release true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 构建 ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 清理 ProjectExplorer.BuildSteps.Clean 2 false Release Qt4ProjectManager.Qt4BuildConfiguration 0 true 2 0 部署 ProjectExplorer.BuildSteps.Deploy 1 在本地部署 ProjectExplorer.DefaultDeployConfiguration 1 false false false false true 0.01 10 true 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 Label Label2 Qt4ProjectManager.Qt4RunConfiguration:E:/2015/Project/Qt/SemiAutoLabel/Label.pro Label.pro false false 3768 false true false false true 1 ProjectExplorer.Project.TargetCount 1 ProjectExplorer.Project.Updater.FileVersion 18 Version 18 ================================================ FILE: src/Label.pro.user.61d9454 ================================================ EnvironmentId {61d94545-019b-4e36-b6c5-2e4867b1f291} ProjectExplorer.Project.ActiveTarget 0 ProjectExplorer.Project.EditorSettings true false true Cpp CppGlobal QmlJS QmlJSGlobal 2 UTF-8 false 4 false 80 true true 1 true false 0 true 0 8 true 1 true true true false ProjectExplorer.Project.PluginSettings ProjectExplorer.Project.Target.0 Desktop Qt 5.4.0 MSVC2013 OpenGL 64bit Desktop Qt 5.4.0 MSVC2013 OpenGL 64bit qt.54.win64_msvc2013_64_opengl_kit 1 0 0 E:/2015/Project/Qt/build-Label-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Debug true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 构建 ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 清理 ProjectExplorer.BuildSteps.Clean 2 false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true E:/2015/Project/Qt/build-Label-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Release true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 构建 ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 清理 ProjectExplorer.BuildSteps.Clean 2 false Release Qt4ProjectManager.Qt4BuildConfiguration 0 true 2 0 部署 ProjectExplorer.BuildSteps.Deploy 1 在本地部署 ProjectExplorer.DefaultDeployConfiguration 1 false false false false true 0.01 10 true 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 Label Qt4ProjectManager.Qt4RunConfiguration:E:/2015/Project/Qt/Label/Label.pro Label.pro false false 3768 false true false false true 1 ProjectExplorer.Project.TargetCount 1 ProjectExplorer.Project.Updater.FileVersion 18 Version 18 ================================================ FILE: src/Label.pro.user.722262d ================================================ EnvironmentId {722262d8-1a19-4320-a67d-98abab6abdea} ProjectExplorer.Project.ActiveTarget 0 ProjectExplorer.Project.EditorSettings true false true Cpp CppGlobal QmlJS QmlJSGlobal 2 UTF-8 false 4 false 80 true true 1 true false 0 true 0 8 true 1 true true true false ProjectExplorer.Project.PluginSettings ProjectExplorer.Project.Target.0 Desktop Qt 5.4.1 MSVC2013 OpenGL 64bit Desktop Qt 5.4.1 MSVC2013 OpenGL 64bit qt.54.win64_msvc2013_64_opengl_kit 1 0 0 C:/Users/culan/Desktop/build-Label-Desktop_Qt_5_4_1_MSVC2013_OpenGL_64bit-Debug true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true C:/Users/culan/Desktop/build-SemiAutoLabel-Desktop_Qt_5_4_1_MSVC2013_OpenGL_64bit-Release true qmake QtProjectManager.QMakeBuildStep false true false false true Make Qt4ProjectManager.MakeStep false 2 Build ProjectExplorer.BuildSteps.Build true Make Qt4ProjectManager.MakeStep true clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Release Qt4ProjectManager.Qt4BuildConfiguration 0 true 2 0 Deploy ProjectExplorer.BuildSteps.Deploy 1 Deploy locally ProjectExplorer.DefaultDeployConfiguration 1 false false false false true 0.01 10 true 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 Label Label2 Qt4ProjectManager.Qt4RunConfiguration:C:/Users/culan/Desktop/SemiAutoLabel/Label.pro Label.pro false false 3768 false true false false true 1 ProjectExplorer.Project.TargetCount 1 ProjectExplorer.Project.Updater.FileVersion 18 Version 18 ================================================ FILE: src/main.cpp ================================================ #include "mainwindow.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } ================================================ FILE: src/mainwindow.cpp ================================================ #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->label->setScaledContents(true); ui->openPushButton->setEnabled(false); ui->autoPushButton->setEnabled(false); ui->savePushButton->setEnabled(false); ui->redoPushButton->setEnabled(false); ui->undoPushButton->setEnabled(false); ui->contourModelPushButton->setEnabled(false); ui->savePushButton->setShortcut(tr("ctrl+s")); ui->redoPushButton->setShortcut(tr("ctrl+r")); ui->undoPushButton->setShortcut(tr("ctrl+u")); validRegion.x=ui->label->frameGeometry().x(); validRegion.y=ui->label->frameGeometry().y()+10; validRegion.height=ui->label->frameGeometry().height(); validRegion.width=ui->label->frameGeometry().width(); prSetDlg=new SetParameterDialog(); file.setFileName("set.ini"); if(!file.open(QIODevice::ReadWrite)) { QMessageBox::information(NULL, "File Read Error", file.errorString(),QMessageBox::Ok , QMessageBox::Ok); } while(!file.atEnd()) { QByteArray line=file.readLine(); QString strTmp(line); strTmp.trimmed(); if(strTmp.startsWith("SequencePath=")) { prSetDlg->setSeqPath(strTmp.mid(13).trimmed()); } if(strTmp.startsWith("FileFormat=")) { prSetDlg->setFileFormat(strTmp.mid(11).trimmed()); } if(strTmp.startsWith("OutputPath=")) { prSetDlg->setOutputPath(strTmp.mid(11).trimmed()); } if(strTmp.startsWith("StartFrame=")) { prSetDlg->setStartFrame(strTmp.mid(11).trimmed()); } } hisfile.setFileName("history.ini"); if(!hisfile.open(QIODevice::WriteOnly|QIODevice::Append)) { QMessageBox::information(NULL, "File Read Error", file.errorString(),QMessageBox::Ok , QMessageBox::Ok); } inputPath=""; outputPath=""; imgInputPath=""; imgOutputPath=""; frameIdx=0; drawMouseMove=false; useHull=true; //Hull Model When Start autoModel=true; //Auto Model When Start rectState=NOT_SET; lblsState=NOT_SET; prLblsState=NOT_SET; isInitialized=false; isf=true; } MainWindow::~MainWindow() { QTextStream out(&file); QString strTmp; strTmp=QString("%1%2").arg("StartFrame=").arg(prSetDlg->getStartFrame()); out<label->setPixmap(QPixmap::fromImage(img)); ui->label->resize(ui->label->pixmap()->size()); ui->label->show(); } void MainWindow::on_setPushButton_clicked() { ui->openPushButton->setEnabled(false); ui->autoPushButton->setEnabled(false); ui->savePushButton->setEnabled(false); ui->redoPushButton->setEnabled(false); ui->undoPushButton->setEnabled(false); ui->contourModelPushButton->setEnabled(false); if(prSetDlg->exec()==QDialog::Accepted) { QString seqPath=prSetDlg->getSeqPath(); QString fileFormat=prSetDlg->getFileFormat(); QString oPath=prSetDlg->getOutputPath(); QString startFrame=prSetDlg->getStartFrame(); file.resize(0); QTextStream out(&file); QString strTmp; strTmp=QString("%1%2").arg("SequencePath=").arg(seqPath); out<openPushButton->setEnabled(true); } } else { QMessageBox::information(NULL, "Information", "Please Set The Parematers",QMessageBox::Ok , QMessageBox::Ok); } } void MainWindow::on_openPushButton_clicked() { readImage(); ui->openPushButton->setEnabled(false); ui->autoPushButton->setEnabled(true); ui->savePushButton->setEnabled(true); ui->redoPushButton->setEnabled(true); ui->undoPushButton->setEnabled(true); ui->contourModelPushButton->setEnabled(true); startIdx=prSetDlg->getStartFrame().toInt(); startTime=QDateTime::currentDateTime(); timerId=startTimer(1000); } void MainWindow::on_autoPushButton_clicked() { if(autoModel) { autoModel=false; ui->autoPushButton->setText("Auto"); } else { resetAMParameters(); autoModel=true; ui->autoPushButton->setText("Manual"); } } void MainWindow::on_savePushButton_clicked() { cv::resize(img_cur,img_cur,Size(640,480)); imgOutputPath.sprintf(outputPath.toStdString().c_str(),frameIdx); if(!imwrite(imgOutputPath.toStdString(),img_cur)) { QMessageBox::information(NULL,"Save Error","Please Check Your Save Path!",QMessageBox::Ok); } else { frameIdx++; readImage(); if(!readImage()) { frameIdx--; } } } void MainWindow::on_redoPushButton_clicked() { readImage(); } void MainWindow::on_undoPushButton_clicked() { img_pre.copyTo(img_cur); img_pre.copyTo(img_cur_copy); displayMat(img_cur); contour.clear(); resetAMParameters(); } void MainWindow::on_contourModelPushButton_clicked() { if(useHull) { useHull=false; ui->contourModelPushButton->setText("Hull"); } else { useHull=true; ui->contourModelPushButton->setText("Poly"); } } void MainWindow::mousePressEvent(QMouseEvent *event) { if(event->button()==Qt::LeftButton) //{Left Button Be Pressed} { Point pointTmp(event->x(),event->y()); restrictPoint(pointTmp); if(autoModel) //[Auto Model] { if(rectState==NOT_SET) // RectMask { rect.x=pointTmp.x; rect.y=pointTmp.y; rectState=IN_PROCESS; } else if(rectState==SET&&QApplication::keyboardModifiers()==Qt::ShiftModifier) // Shift+LeftClick: GC_FG { isf=true; lblsState=IN_PROCESS; } else if(rectState==SET&&QApplication::keyboardModifiers()==Qt::ControlModifier) // Ctrl+LeftClick: GC_BG { isf=false; lblsState=IN_PROCESS; } else if(rectState==SET&&QApplication::keyboardModifiers()==Qt::AltModifier) // Alt+LeftClick: GC_PR_FG { isf=true; prLblsState=IN_PROCESS; } else if(rectState==SET) // LeftClick: GC_PR_BG { isf=false; prLblsState=IN_PROCESS; } } else //[Manual Model] { contour.push_back(pointTmp); drawConnects(); } drawMouseMove=true; } else if(event->button()==Qt::RightButton) //{Right Button Be Pressed} { if(autoModel) //[Auto Model] { //Ctrl+RightClick One: Draw The Contour; Double: Fill The Contour if(rectState!=IN_PROCESS&&lblsState!=IN_PROCESS&&prLblsState!=IN_PROCESS) { if(QApplication::keyboardModifiers()==Qt::ControlModifier) { static int rightClickCount=0; if(rightClickCount==0) { Mat binMask; getBinMask(mask, binMask); vector> contours; findContours(binMask, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); if(contours.size()==1) { contour=contours[0]; } else { QMessageBox::information(NULL,"Information","Please Label One Foreground Object !",QMessageBox::Ok); } drawConnects(); resetAMParameters(); rightClickCount=1; } else if(rightClickCount==1) { contourFill(); rightClickCount=0; } } else //RightClick: Cut The Foreground Iteratively { if (isInitialized) grabCut(img_cur, mask, rect, bgdModel, fgdModel, 1); else { if (lblsState == SET || prLblsState == SET) grabCut(img_cur, mask, rect, bgdModel, fgdModel, 1, GC_INIT_WITH_MASK); else grabCut(img_cur, mask, rect, bgdModel, fgdModel, 1, GC_INIT_WITH_RECT); isInitialized = true; } bgdPxls.clear(); fgdPxls.clear(); prBgdPxls.clear(); prFgdPxls.clear(); Mat binMask; Mat res; if (!isInitialized) img_cur.copyTo(img_cur_copy); else { img_cur_copy.setTo(Scalar::all(0)); getBinMask(mask, binMask); img_cur.copyTo(img_cur_copy, binMask); } displayMat(img_cur_copy); } } else { resetAMParameters(); } } else //[Manual Model] { contourFill(); } } else if(event->button()==Qt::MiddleButton) //{Middle button be pressed} { if(!contour.empty()) { contour.pop_back(); drawConnects(); } else { QMessageBox::information(NULL,"Information","Points Pool Is Empty !",QMessageBox::Ok); } } } void MainWindow::mouseReleaseEvent(QMouseEvent *event) { if(event->button()==Qt::LeftButton) { Point pointTmp(event->x(),event->y()); restrictPoint(pointTmp); if(autoModel) //[Auto Model] { if(rectState==IN_PROCESS) { rect.width=abs(pointTmp.x-rect.x); rect.height=abs(pointTmp.y-rect.y); rect.x=rect.x>pointTmp.x?pointTmp.x:rect.x; rect.y=rect.y>pointTmp.y?pointTmp.y:rect.y; if(rect.area()>10) //The Area Of The Rect Should Not Be Too Small { mask.setTo(GC_BGD); (mask(rect)).setTo(Scalar(GC_PR_FGD)); rectState=SET; } else { resetAMParameters(); } } vector::const_iterator it; if(lblsState==IN_PROCESS&&isf) { for(it=fgdPxls.begin();it!=fgdPxls.end();++it) circle(mask,*it,2,GC_FGD,-1); lblsState=SET; } if(lblsState==IN_PROCESS&&!isf) { for(it=bgdPxls.begin();it!=bgdPxls.end();++it) circle(mask,*it,2,GC_BGD,-1); lblsState=SET; } if(prLblsState==IN_PROCESS&&isf) { for(it=prFgdPxls.begin();it!=prFgdPxls.end();++it) circle(mask,*it,2,GC_PR_FGD,-1); prLblsState=SET; } if(prLblsState==IN_PROCESS&&!isf) { for(it=prBgdPxls.begin();it!=prBgdPxls.end();++it) circle(mask,*it,2,GC_PR_BGD,-1); prLblsState=SET; } } else //[Manual Model] { } drawMouseMove=false; } } void MainWindow::mouseMoveEvent(QMouseEvent *event) { if(drawMouseMove) { Point pointTmp(event->x(),event->y()); restrictPoint(pointTmp); if(autoModel) //[Auto Model] { if(rectState==IN_PROCESS) { img_cur.copyTo(img_cur_copy); rectangle(img_cur_copy,Point(rect.x,rect.y),Point(pointTmp.x,pointTmp.y),Scalar(0,255,0),2); displayMat(img_cur_copy); } if(lblsState==IN_PROCESS&&isf) { fgdPxls.push_back(pointTmp); circle(img_cur_copy,pointTmp,2,Scalar(0,0,255),-1); displayMat(img_cur_copy); } if(lblsState==IN_PROCESS&&!isf) { bgdPxls.push_back(pointTmp); circle(img_cur_copy,pointTmp,2,Scalar(255,0,0),-1); displayMat(img_cur_copy); } if(prLblsState==IN_PROCESS&&isf) { prFgdPxls.push_back(pointTmp); circle(img_cur_copy,pointTmp,2,Scalar(230,130,255),-1); displayMat(img_cur_copy); } if(prLblsState==IN_PROCESS&&!isf) { prBgdPxls.push_back(pointTmp); circle(img_cur_copy,pointTmp,2,Scalar(255,255,160),-1); displayMat(img_cur_copy); } } else //[Manual Model] { contour.push_back(pointTmp); drawConnects(); } } } bool MainWindow::readImage() { contour.clear(); imgInputPath.sprintf(inputPath.toStdString().c_str(),frameIdx); img_cur=imread(imgInputPath.toStdString()); if(!img_cur.empty()) { img_cur.copyTo(img_pre); displayMat(img_cur); prSetDlg->setStartFrame(QString("%1").arg(frameIdx)); mask.create(img_cur.size(),CV_8UC1); return true; } else { QMessageBox::information(NULL,"Read Failure","Failed To Read "+imgInputPath,QMessageBox::Ok,QMessageBox::Ok); return false; } } void MainWindow::drawConnects() { img_pre.copyTo(img_cur); for(int i=0;i> contours; if(!useHull) { approxPolyDP(contour,contour,0,true); } else { convexHull(Mat(contour),contour); } contours.push_back(contour); img_pre.copyTo(img_cur); drawContours(img_cur, contours, -1, Scalar(0,0,255), CV_FILLED); displayMat(img_cur); img_cur.copyTo(img_pre); img_cur.copyTo(img_cur_copy); contour.clear(); } } void MainWindow::getBinMask(const Mat& comMask, Mat& binMask) { if (comMask.empty() || comMask.type() != CV_8UC1) CV_Error(CV_StsBadArg, "ComMask Is Empty Or Has Incorrect Type (Not CV_8UC1)"); if (binMask.empty() || binMask.rows != comMask.rows || binMask.cols != comMask.cols) binMask.create(comMask.size(), CV_8UC1); binMask = comMask & 1; } void MainWindow::resetAMParameters() { if (!mask.empty()) mask.setTo(Scalar::all(GC_BGD)); bgdPxls.clear(); fgdPxls.clear(); prBgdPxls.clear(); prFgdPxls.clear(); isInitialized = false; rectState = NOT_SET; lblsState = NOT_SET; prLblsState = NOT_SET; } void MainWindow::restrictPoint(Point & _point) { _point.x-=validRegion.x; _point.y-=validRegion.y; _point.x=_point.x>0?_point.x:0; _point.y=_point.y>0?_point.y:0; _point.x=_point.xlabel->frameGeometry().width()/float(validRegion.width); float yscale=ui->label->frameGeometry().height()/float(validRegion.height); if(!contour.empty()) { for(int i=0;i::iterator it; for(it=fgdPxls.begin();it!=fgdPxls.end();++it) { (*it).x*=xscale; (*it).y*=yscale; } for(it=bgdPxls.begin();it!=bgdPxls.end();++it) { (*it).x*=xscale; (*it).y*=yscale; } for(it=prFgdPxls.begin();it!=prFgdPxls.end();++it) { (*it).x*=xscale; (*it).y*=yscale; } for(it=prBgdPxls.begin();it!=prBgdPxls.end();++it) { (*it).x*=xscale; (*it).y*=yscale; } validRegion.x=ui->label->frameGeometry().x(); validRegion.y=ui->label->frameGeometry().y()+10; validRegion.height=ui->label->frameGeometry().height(); validRegion.width=ui->label->frameGeometry().width(); if(!img_cur.empty()&&!img_pre.empty()) { cv::Size sz=cv::Size(validRegion.width,validRegion.height); cv::resize(img_pre,img_pre,sz); cv::resize(img_cur,img_cur,sz); } if(!mask.empty()&&!img_cur_copy.empty()) { cv::Size sz=cv::Size(validRegion.width,validRegion.height); cv::resize(mask,mask,sz); cv::resize(img_cur_copy,img_cur_copy,sz); } } void MainWindow::timerEvent(QTimerEvent *event) { curTime=QDateTime::currentDateTime(); qint64 elapsedSec=startTime.msecsTo(curTime)/1000; ui->frameshowLabel->setText(QString("%1 %2 %3:%4:%5").arg(frameIdx).arg(frameIdx-startIdx).arg(elapsedSec/3600).arg((elapsedSec%3600)/60).arg(elapsedSec%60)); } ================================================ FILE: src/mainwindow.h ================================================ #ifndef MAINWINDOW_H #define MAINWINDOW_H #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include "setparameterdialog.h" using std::vector; using namespace cv; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_setPushButton_clicked(); void on_openPushButton_clicked(); void on_autoPushButton_clicked(); void on_savePushButton_clicked(); void on_redoPushButton_clicked(); void on_undoPushButton_clicked(); void on_contourModelPushButton_clicked(); private: Ui::MainWindow *ui; SetParameterDialog * prSetDlg; QString inputPath; QString outputPath; QString imgInputPath; QString imgOutputPath; unsigned int startIdx,frameIdx; Mat img_cur,img_pre; vector contour; Rect validRegion; QFile file,hisfile; QDateTime startTime,curTime; int timerId; bool drawMouseMove; bool useHull; bool autoModel; enum{NOT_SET=0,IN_PROCESS=1,SET=2}; Mat mask; Mat img_cur_copy; Mat bgdModel,fgdModel; Rect rect; uchar rectState,lblsState,prLblsState; vector fgdPxls,bgdPxls,prFgdPxls,prBgdPxls; bool isInitialized; bool isf; private: void displayMat(Mat mat); bool readImage(); void drawConnects(); void contourFill(); void getBinMask(const Mat& comMask, Mat& binMask); void resetAMParameters(); void restrictPoint(Point& _point); protected: void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); void timerEvent(QTimerEvent *event); }; #endif // MAINWINDOW_H ================================================ FILE: src/mainwindow.ui ================================================ MainWindow 0 0 660 573 MainWindow Open Save Set Redo Poly Undo Manual 0 0 660 21 TopToolBarArea false ================================================ FILE: src/setparameterdialog.cpp ================================================ #include "setparameterdialog.h" #include "ui_setparameterdialog.h" #include SetParameterDialog::SetParameterDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SetParameterDialog) { ui->setupUi(this); } SetParameterDialog::~SetParameterDialog() { delete ui; } QString SetParameterDialog::getSeqPath() { return ui->lineEdit_SequencePath->text(); } QString SetParameterDialog::getFileFormat() { return ui->lineEdit_FileFormat->text(); } QString SetParameterDialog::getOutputPath() { return ui->lineEdit_OutputPath->text(); } QString SetParameterDialog::getStartFrame() { return ui->lineEdit_StartFrame->text(); } void SetParameterDialog::setSeqPath(const QString& str) { ui->lineEdit_SequencePath->setText(str); } void SetParameterDialog::setFileFormat(const QString& str) { ui->lineEdit_FileFormat->setText(str); } void SetParameterDialog::setOutputPath(const QString& str) { ui->lineEdit_OutputPath->setText(str); } void SetParameterDialog::setStartFrame(const QString& str) { ui->lineEdit_StartFrame->setText(str); } ================================================ FILE: src/setparameterdialog.h ================================================ #ifndef SETPARAMETERDIALOG_H #define SETPARAMETERDIALOG_H #include namespace Ui { class SetParameterDialog; } class SetParameterDialog : public QDialog { Q_OBJECT public: explicit SetParameterDialog(QWidget *parent = 0); ~SetParameterDialog(); QString getSeqPath(); QString getFileFormat(); QString getOutputPath(); QString getStartFrame(); void setSeqPath(const QString& str); void setFileFormat(const QString& str); void setOutputPath(const QString& str); void setStartFrame(const QString& str); private: Ui::SetParameterDialog *ui; }; #endif // SETPARAMETERDIALOG_H ================================================ FILE: src/setparameterdialog.ui ================================================ SetParameterDialog 0 0 400 300 Dialog 30 240 341 32 Qt::Horizontal QDialogButtonBox::Cancel|QDialogButtonBox::Ok 10 40 91 21 Sequences Path : 110 41 271 20 C:\Users\culan\Desktop\VIVIDJPG\egtest04 10 90 71 16 File Format : 110 90 113 20 frame%.5d.jpg 10 140 81 16 Output Path : 110 140 271 20 C:\Users\culan\Desktop\Labeled\egtest04 10 190 91 16 Start Frame : 110 190 81 20 0 buttonBox accepted() SetParameterDialog accept() 248 254 157 274 buttonBox rejected() SetParameterDialog reject() 316 260 286 274