Modified pushbutton_open_files_clicked()

This commit is contained in:
developer0hye 2018-12-14 10:39:28 +09:00
parent a2d9b55f6e
commit 496d693200
2 changed files with 74 additions and 45 deletions

View File

@ -44,51 +44,24 @@ MainWindow::~MainWindow()
void MainWindow::on_pushButton_open_files_clicked() 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( openImgDir(bRetImgDir);
this,
tr("Open Dataset Directory"),
"./",QFileDialog::ShowDirsOnly);
QDir dir(m_fileDir); if (!bRetImgDir) return ;
QStringList fileList = dir.entryList( openObjListFile(bRetObjFile);
QStringList() << "*.jpg" << "*.JPG" << "*.png",
QDir::Files);
if(fileList.size() == 0) if (!bRetObjFile) return ;
{
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty");
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(); init();
} }
void MainWindow::init() void MainWindow::init()
{ {
ui->label_image->init();
ui->horizontalSlider_images->setEnabled(true); ui->horizontalSlider_images->setEnabled(true);
ui->pushButton_next->setEnabled(true); ui->pushButton_next->setEnabled(true);
ui->pushButton_prev->setEnabled(true); ui->pushButton_prev->setEnabled(true);
@ -304,6 +277,59 @@ void MainWindow::pjreddie_style_msgBox(QMessageBox::Icon icon, QString title, QS
msgBox.exec(); 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) void MainWindow::wheelEvent(QWheelEvent *ev)
{ {
if(ev->delta() > 0) // up Wheel if(ev->delta() > 0) // up Wheel

View File

@ -49,16 +49,6 @@ private slots:
void on_horizontalSlider_images_sliderPressed(); void on_horizontalSlider_images_sliderPressed();
private: private:
Ui::MainWindow *ui;
QString m_fileDir;
QStringList m_fileList;
int m_fileIndex;
QStringList m_labelNameList;
int m_labelIndex;
void init_tableWidget(); void init_tableWidget();
void init(); void init();
@ -77,6 +67,19 @@ private:
void pjreddie_style_msgBox(QMessageBox::Icon, QString, QString); 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: protected:
void wheelEvent(QWheelEvent *); void wheelEvent(QWheelEvent *);
}; };