From 496d6932007c8eaacc1dff8403b8e5b9dd47d18d Mon Sep 17 00:00:00 2001 From: developer0hye Date: Fri, 14 Dec 2018 10:39:28 +0900 Subject: [PATCH] Modified pushbutton_open_files_clicked() --- mainwindow.cpp | 96 ++++++++++++++++++++++++++++++++------------------ mainwindow.h | 23 ++++++------ 2 files changed, 74 insertions(+), 45 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 635cb33..c18d573 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -44,51 +44,24 @@ MainWindow::~MainWindow() void MainWindow::on_pushButton_open_files_clicked() { - pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 1. Open Your Data Set Directory"); + bool bRetImgDir = false; + bool bRetObjFile = false; - m_fileDir = QFileDialog::getExistingDirectory( - this, - tr("Open Dataset Directory"), - "./",QFileDialog::ShowDirsOnly); + openImgDir(bRetImgDir); - QDir dir(m_fileDir); + if (!bRetImgDir) return ; - QStringList fileList = dir.entryList( - QStringList() << "*.jpg" << "*.JPG" << "*.png", - QDir::Files); + openObjListFile(bRetObjFile); - if(fileList.size() == 0) - { - pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty"); - return; - } + if (!bRetObjFile) return ; - pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 2. Open Your Label List File(*.txt or *.names)"); - - - QString fileLabelList = QFileDialog::getOpenFileName( - this, - tr("Open LabelList file"), - "./", - tr("LabelList Files (*.txt *.names)")); - - if(fileLabelList.size() == 0) - { - pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()"); - return; - } - - m_fileList = fileList; - for(QString& str: m_fileList) str = m_fileDir + "/" + str; - - load_label_list_data(fileLabelList); - - ui->label_image->init(); init(); } void MainWindow::init() { + ui->label_image->init(); + ui->horizontalSlider_images->setEnabled(true); ui->pushButton_next->setEnabled(true); ui->pushButton_prev->setEnabled(true); @@ -304,6 +277,59 @@ void MainWindow::pjreddie_style_msgBox(QMessageBox::Icon icon, QString title, QS msgBox.exec(); } +void MainWindow::openImgDir(bool& ret) +{ + pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 1. Open Your Data Set Directory"); + + QString imgDir = QFileDialog::getExistingDirectory( + this, + tr("Open Dataset Directory"), + "./",QFileDialog::ShowDirsOnly); + + QDir dir(imgDir); + + QStringList fileList = dir.entryList( + QStringList() << "*.jpg" << "*.JPG" << "*.png", + QDir::Files); + + if(fileList.empty()) + { + pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty"); + ret = false; + } + else + { + m_imgDir = imgDir; + m_fileList = fileList; + + for(QString& str: m_fileList) + str = m_imgDir + "/" + str; + ret = true; + } +} + +void MainWindow::openObjListFile(bool& ret) +{ + pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 2. Open Your Label List File(*.txt or *.names)"); + + QString fileLabelList = QFileDialog::getOpenFileName( + this, + tr("Open LabelList file"), + "./", + tr("LabelList Files (*.txt *.names)")); + + if(fileLabelList.size() == 0) + { + pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()"); + ret = false; + } + else + { + load_label_list_data(fileLabelList); + ret = true; + } +} + void MainWindow::wheelEvent(QWheelEvent *ev) { if(ev->delta() > 0) // up Wheel diff --git a/mainwindow.h b/mainwindow.h index 1f730ae..31878a2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -49,16 +49,6 @@ private slots: void on_horizontalSlider_images_sliderPressed(); private: - Ui::MainWindow *ui; - - QString m_fileDir; - QStringList m_fileList; - int m_fileIndex; - - QStringList m_labelNameList; - int m_labelIndex; - - void init_tableWidget(); void init(); @@ -77,6 +67,19 @@ private: void pjreddie_style_msgBox(QMessageBox::Icon, QString, QString); + void openImgDir(bool&); + void openObjListFile(bool&); + + + Ui::MainWindow *ui; + + QString m_imgDir; + QStringList m_fileList; + int m_fileIndex; + + QStringList m_labelNameList; + int m_labelIndex; + protected: void wheelEvent(QWheelEvent *); };