From 520e6f88151db4848d41f52e5149fdde078162b8 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Mon, 29 Aug 2022 22:52:31 +0900 Subject: [PATCH] command yolo-label --- main.cpp | 2 +- mainwindow.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- mainwindow.h | 5 ++++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 29e1450..d4087b9 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; + MainWindow w(nullptr, argc, argv); w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 4c867bf..047fcb9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -16,7 +16,7 @@ using std::ofstream; using std::ifstream; using std::string; -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QWidget *parent, int argc, char *argv[]) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -34,6 +34,15 @@ MainWindow::MainWindow(QWidget *parent) : connect(new QShortcut(QKeySequence(Qt::Key_Delete), this), SIGNAL(activated()), this, SLOT(remove_img())); init_table_widget(); + + if(argc == 3) + { + std::cout << "Dataset Path: " << argv[1] << std::endl; + std::cout << "Label List File Path: " << argv[2] << std::endl; + open_img_dir(argv[1]); + open_obj_file(argv[2]); + init(); + } } MainWindow::~MainWindow() @@ -334,6 +343,33 @@ void MainWindow::open_img_dir(bool& ret) } } +void MainWindow::open_img_dir(char* img_dir) +{ + QString imgDir(img_dir); + QDir dir(imgDir); + QCollator collator; + collator.setNumericMode(true); + + QStringList fileList = dir.entryList( + QStringList() << "*.jpg" << "*.JPG" << "*.png" << "*.bmp", + QDir::Files); + + std::sort(fileList.begin(), fileList.end(), collator); + + if(fileList.empty()) + { + pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty"); + } + else + { + m_imgDir = imgDir; + m_imgList = fileList; + + for(QString& str: m_imgList) + str = m_imgDir + "/" + str; + } +} + void MainWindow::open_obj_file(bool& ret) { pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 2. Open Your Label List File(*.txt or *.names)"); @@ -360,6 +396,24 @@ void MainWindow::open_obj_file(bool& ret) } } +void MainWindow::open_obj_file(char* file) +{ + QString opened_dir; + if(m_imgDir.size() > 0) opened_dir = m_imgDir; + else opened_dir = QDir::currentPath(); + + QString fileLabelList(file); + + if(fileLabelList.size() == 0) + { + pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()"); + } + else + { + load_label_list_data(fileLabelList); + } +} + void MainWindow::reupdate_img_list() { diff --git a/mainwindow.h b/mainwindow.h index 9312377..6e1f2dc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QWidget *parent = nullptr, int argc=0, char *argv[]=nullptr); ~MainWindow(); private slots: @@ -71,6 +71,9 @@ private: void open_img_dir(bool&); void open_obj_file(bool&); + void open_img_dir(char *); + void open_obj_file(char *); + void reupdate_img_list(); Ui::MainWindow *ui;