commit 00cbe9b3b9790d2ec1cbab581a74d556cdaf199c Author: yonghye Date: Mon Oct 29 13:26:06 2018 +0900 first commit diff --git a/ImageLabelingTool.pro b/ImageLabelingTool.pro new file mode 100644 index 0000000..4638d6c --- /dev/null +++ b/ImageLabelingTool.pro @@ -0,0 +1,40 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-10-23T15:07:41 +# +#------------------------------------------------- + +QT += core gui widgets + +TARGET = ImageLabelingTool +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG += c++11 + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + label_img.cpp + +HEADERS += \ + mainwindow.h \ + label_img.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/README.md b/README.md new file mode 100644 index 0000000..42a0e9a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# ImageLabelingTool-YOLO-Style diff --git a/label_img.cpp b/label_img.cpp new file mode 100644 index 0000000..923f83f --- /dev/null +++ b/label_img.cpp @@ -0,0 +1,268 @@ +#include "label_img.h" +#include + +using std::ifstream; + +QColor label_img::BOX_COLORS[10] ={ Qt::green, + Qt::darkGreen, + Qt::blue, + Qt::darkBlue, + Qt::yellow, + Qt::darkYellow, + Qt::red, + Qt::darkRed, + Qt::cyan, + Qt::darkCyan}; + +label_img::label_img(QWidget *parent) + :QLabel(parent), + m_bMouseLeftButtonClicked(false), + m_focusedObjectLabel(0) + +{ +} + +void label_img::mouseMoveEvent(QMouseEvent *ev) +{ + std::cout<< "moved"<< std::endl; + + setMousePosition(ev->x(), ev->y()); + + showImage(); + emit Mouse_Moved(); +} + +void label_img::mousePressEvent(QMouseEvent *ev) +{ + std::cout<< "clicked"<< std::endl; + + setMousePosition(ev->x(), ev->y()); + + if(ev->button() == Qt::RightButton) + { + removeFocusedObjectBox(m_mouse_pos_in_image_coordinate); + showImage(); + } + else if(ev->button() == Qt::LeftButton) + { + m_bMouseLeftButtonClicked = true; + m_objStartPoint = m_mouse_pos_in_image_coordinate; + } + + emit Mouse_Pressed(); +} + +void label_img::mouseReleaseEvent(QMouseEvent *ev) +{ + std::cout<< "released"<< std::endl; + + if(ev->button() == Qt::LeftButton) + { + m_bMouseLeftButtonClicked = false; + + setMousePosition(ev->x(), ev->y()); + m_objEndPoint = m_mouse_pos_in_image_coordinate; + + ObjectLabelingBox objBoundingbox; + objBoundingbox.label = m_focusedObjectLabel; + objBoundingbox.box = getRectFromTwoPoints(m_objEndPoint, m_objStartPoint); + + bool width_is_too_small = objBoundingbox.box.width() < m_inputImg.width() * 0.01; + bool height_is_too_small = objBoundingbox.box.height() < m_inputImg.height() * 0.01; + + if(!width_is_too_small && !height_is_too_small) + { + m_objBoundingBoxes.push_back(objBoundingbox); + } + + showImage(); + } + emit Mouse_Release(); +} + +void label_img::setMousePosition(int x, int y) +{ + if(x < 0) x = 0; + if(y < 0) y = 0; + + if(x > this->width()) x = this->width() - 1; + if(y > this->height()) y = this->height() - 1; + + m_mouse_pos_in_ui_coordinate = QPoint(x, y); + m_mouse_pos_in_image_coordinate = QPoint(static_cast(m_mouse_pos_in_ui_coordinate.x() * m_aspectRatioWidth), + static_cast(m_mouse_pos_in_ui_coordinate.y() * m_aspectRatioHeight)); +} + +void label_img::openImage(const QString &qstrImg) +{ + m_inputImg = QImage(qstrImg); + m_inputImgCopy = m_inputImg; + + m_aspectRatioWidth = static_cast(m_inputImg.width()) / this->width(); + m_aspectRatioHeight = static_cast(m_inputImg.height()) / this->height(); + + m_objBoundingBoxes.clear(); + + m_objStartPoint = QPoint(); + + QPoint curMousePos = this->mapFromGlobal(QCursor::pos()); + bool mouse_is_not_in_image = (curMousePos.x() < 0 || curMousePos.x() > this->width() - 1) + || (curMousePos.y() < 0 || curMousePos.y() > this->height() - 1); + + if (mouse_is_not_in_image) + { + m_objEndPoint = QPoint(); + } + else + { + setMousePosition(curMousePos.x(), curMousePos.y()); + m_objEndPoint = m_mouse_pos_in_image_coordinate; + } +} + +void label_img::showImage() +{ + if(m_inputImg.isNull()) return; + + m_inputImg = m_inputImgCopy; + + QPainter painter(&m_inputImg); + + int penThick = (m_inputImg.width() + m_inputImg.height())/400; + + QColor crossLineColor(255, 187, 0); + + drawCrossLine(painter, crossLineColor, penThick); + drawFocusedObjectBox(painter, Qt::magenta, penThick); + drawObjectBoxes(painter, penThick); + + this->setPixmap(QPixmap::fromImage(m_inputImg)); +} + +void label_img::loadLabelData(const QString& labelFilePath) +{ + ifstream inputFile(labelFilePath.toStdString()); + + if(inputFile.is_open()){ + + double inputFileValue; + QVector inputFileValues; + + while(inputFile >> inputFileValue) + inputFileValues.push_back(inputFileValue); + + for(int i = 0; i < inputFileValues.size(); i += 5) + { + try { + ObjectLabelingBox objBox; + objBox.label = static_cast(inputFileValues[i]); + + double midX = inputFileValues.at(i + 1) * m_inputImg.width(); + double midY = inputFileValues.at(i + 2) * m_inputImg.height(); + double width = inputFileValues.at(i + 3) * m_inputImg.width(); + double height = inputFileValues.at(i + 4) * m_inputImg.height(); + + objBox.box.setX(static_cast(midX - width/2)); + objBox.box.setY(static_cast(midY - height/2)); + objBox.box.setWidth(static_cast(width)); + objBox.box.setHeight(static_cast(height)); + + m_objBoundingBoxes.push_back(objBox); + } + catch (const std::out_of_range& e) { + std::cout << "loadLabelData: Out of Range error."; + } + } + } +} + +void label_img::setFocusObjectLabel(int nLabel) +{ + m_focusedObjectLabel = nLabel; +} + +void label_img::setFocusObjectName(QString qstrName) +{ + m_foucsedObjectName = qstrName; +} + +void label_img::drawCrossLine(QPainter& painter, QColor color, int thickWidth) +{ + if(m_objEndPoint == QPoint()) return; + + QPen pen; + pen.setWidth(thickWidth); + + pen.setColor(color); + painter.setPen(pen); + + //draw cross line + painter.drawLine(QPoint(m_mouse_pos_in_image_coordinate.x(),0), QPoint(m_mouse_pos_in_image_coordinate.x(),m_inputImg.height() - 1)); + painter.drawLine(QPoint(0,m_mouse_pos_in_image_coordinate.y()), QPoint(m_inputImg.width() - 1, m_mouse_pos_in_image_coordinate.y())); +} + +void label_img::drawFocusedObjectBox(QPainter& painter, Qt::GlobalColor color, int thickWidth) +{ + if(m_bMouseLeftButtonClicked) + { + QPen pen; + pen.setWidth(thickWidth); + + pen.setColor(color); + painter.setPen(pen); + painter.drawRect(QRect(m_objStartPoint, m_mouse_pos_in_image_coordinate)); + } +} + +void label_img::drawObjectBoxes(QPainter& painter, int thickWidth) +{ + QPen pen; + pen.setWidth(thickWidth); + + for(ObjectLabelingBox boundingbox: m_objBoundingBoxes) + { + pen.setColor(m_drawObjectBoxColor.at(boundingbox.label)); + painter.setPen(pen); + + painter.drawRect(boundingbox.box); + } +} + +void label_img::removeFocusedObjectBox(QPoint point) +{ + int removeBoxIdx = -1; + double nearestBoxDistance = 99999999999999.; + + for(int i = 0; i < m_objBoundingBoxes.size(); i++) + { + QRect objBox = m_objBoundingBoxes.at(i).box; + + if(objBox.contains(point)) + { + double distance = sqrt(pow(objBox.center().x() - point.x(), 2)+ pow(objBox.center().y() - point.y(), 2)); + if(distance < nearestBoxDistance) + { + nearestBoxDistance = distance; + removeBoxIdx = i; + } + } + } + + if(removeBoxIdx != -1) + { + m_objBoundingBoxes.remove(removeBoxIdx); + } +} + +QRect label_img::getRectFromTwoPoints(QPoint p1, QPoint p2) +{ + int midX = (p1.x() + p2.x()) / 2; + int midY = (p1.y() + p2.y()) / 2; + int width = abs(p1.x() - p2.x()); + int height = abs(p1.y() - p2.y()); + + QPoint topLeftPoint(midX - width/2, midY - height/2); + QPoint bottomRightPoint(midX + width/2, midY + height/2); + + return QRect(topLeftPoint, bottomRightPoint); +} diff --git a/label_img.h b/label_img.h new file mode 100644 index 0000000..6731a88 --- /dev/null +++ b/label_img.h @@ -0,0 +1,83 @@ +#ifndef LABEL_IMG_H +#define LABEL_IMG_H + +#include +#include +#include +#include +#include +#include + +struct ObjectLabelingBox +{ + int label; + QRect box; +}; + +class label_img : public QLabel +{ + Q_OBJECT +public: + label_img(QWidget *parent = nullptr); + + void mouseMoveEvent(QMouseEvent *ev); + void mousePressEvent(QMouseEvent *ev); + void mouseReleaseEvent(QMouseEvent *ev); + + QImage m_inputImg; + QImage m_inputImgCopy;//for drawing + + QPoint m_mouse_pos_in_ui_coordinate; + QPoint m_mouse_pos_in_image_coordinate; + + QVector m_drawObjectBoxColor; + + int m_uiX; + int m_uiY; + + int m_imgX; + int m_imgY; + + bool m_bMouseLeftButtonClicked; + + static QColor BOX_COLORS[10]; + + QVector m_objBoundingBoxes; + + void openImage(const QString &); + void showImage(); + + void loadLabelData(const QString & ); + + void setFocusObjectLabel(int); + void setFocusObjectName(QString); + +signals: + void Mouse_Moved(); + void Mouse_Pressed(); + void Mouse_Release(); + +private: + int m_focusedObjectLabel; + QString m_foucsedObjectName; + + double m_aspectRatioWidth; + double m_aspectRatioHeight; + + QPoint m_objStartPoint; + QPoint m_objEndPoint; + + void setMousePosition(int , int); + + void drawCrossLine(QPainter& , QColor , int thickWidth = 3); + void drawFocusedObjectBox(QPainter& , Qt::GlobalColor , int thickWidth = 3); + void drawObjectBoxes(QPainter& , int thickWidth = 3); + + void removeFocusedObjectBox(QPoint point); + + QRect getRectFromTwoPoints(QPoint p1, QPoint p2); + + +}; + +#endif // LABEL_IMG_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..02914ed --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,381 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include +#include +#include +#include + +#include + +using std::cout; +using std::endl; +using std::ofstream; +using std::ifstream; +using std::string; + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + connect(ui->label_image, SIGNAL(Mouse_Moved()), this, SLOT(mouseCurrentPos())); + connect(ui->label_image, SIGNAL(Mouse_Pressed()), this, SLOT(mousePressed())); + connect(ui->label_image, SIGNAL(Mouse_Release()), this, SLOT(mouseReleased())); + + connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this), SIGNAL(activated()), this, SLOT(save_label_data())); + connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C), this), SIGNAL(activated()), this, SLOT(clear_label_data())); + + connect(new QShortcut(QKeySequence(Qt::Key_S), this), SIGNAL(activated()), this, SLOT(next_label())); + connect(new QShortcut(QKeySequence(Qt::Key_W), this), SIGNAL(activated()), this, SLOT(prev_label())); + connect(new QShortcut(QKeySequence(Qt::Key_A), this), SIGNAL(activated()), this, SLOT(prev_img())); + connect(new QShortcut(QKeySequence(Qt::Key_D), this), SIGNAL(activated()), this, SLOT(next_img())); + connect(new QShortcut(QKeySequence(Qt::Key_Space), this), SIGNAL(activated()), this, SLOT(next_img())); + + ui->tableWidget_label->horizontalHeader()->setStyleSheet(""); + disconnect(ui->tableWidget_label->horizontalHeader(), SIGNAL(sectionPressed(int)),ui->tableWidget_label, SLOT(selectColumn(int))); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_open_files_clicked() +{ + pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 1. Open Your Data Set Directory"); + + m_fileDir = QFileDialog::getExistingDirectory( + this, + tr("Open Dataset Directory"), + "C://"); + + QDir dir(m_fileDir); + + QStringList fileList = dir.entryList( + QStringList() << "*.jpg" << "*.JPG" << "*.png", + QDir::Files); + + if(fileList.size() == 0) + { + 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"), + "C://", + 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); + + init(); +} + +void MainWindow::init() +{ + ui->horizontalSlider_images->setEnabled(true); + ui->pushButton_next->setEnabled(true); + ui->pushButton_prev->setEnabled(true); + ui->pushButton_save->setEnabled(true); + + ui->horizontalSlider_images->setRange(0, m_fileList.size() - 1); + + set_label(0); + goto_img(0); +} + +void MainWindow::set_label_progress(const int fileIndex) +{ + QString strCurFileIndex = QString::number(fileIndex); + QString strEndFileIndex = QString::number(m_fileList.size() - 1); + + ui->label_progress->setText(strCurFileIndex + " / " + strEndFileIndex); +} + +void MainWindow::set_focused_file(const int fileIndex) +{ + ui->label_file->setText("File: " + m_fileList.at(fileIndex)); +} + +void MainWindow::goto_img(int fileIndex) +{ + bool indexIsOutOfRange = (fileIndex < 0 || fileIndex > m_fileList.size() - 1); + + if(!indexIsOutOfRange) + { + m_fileIndex = fileIndex; + + ui->label_image->openImage(m_fileList.at(m_fileIndex)); + ui->label_image->loadLabelData(get_labeling_data(m_fileList.at(m_fileIndex))); + ui->label_image->showImage(); + + set_label_progress(m_fileIndex); + set_focused_file(m_fileIndex); + } +} + +void MainWindow::next_img() +{ + save_label_data(); + goto_img(m_fileIndex + 1); + + ui->horizontalSlider_images->blockSignals(true); + ui->horizontalSlider_images->setValue(m_fileIndex); + ui->horizontalSlider_images->blockSignals(false); +} + +void MainWindow::prev_img() +{ + save_label_data(); + goto_img(m_fileIndex - 1); + + //it blocks crash with slider change + ui->horizontalSlider_images->blockSignals(true); + ui->horizontalSlider_images->setValue(m_fileIndex); + ui->horizontalSlider_images->blockSignals(false); +} + +void MainWindow::save_label_data()const +{ + if(m_fileList.size() == 0) return; + + QString qstrOutputLabelData = get_labeling_data(m_fileList.at(m_fileIndex)); + + ofstream fileOutputLabelData(qstrOutputLabelData.toStdString()); + + if(fileOutputLabelData.is_open()) + { + for(int i = 0; i < ui->label_image->m_objBoundingBoxes.size(); i++) + { + if(i != 0) fileOutputLabelData << '\n'; + + ObjectLabelingBox objBox = ui->label_image->m_objBoundingBoxes[i]; + + double midX = static_cast(objBox.box.center().x()) / ui->label_image->m_inputImg.width(); + double midY = static_cast(objBox.box.center().y()) / ui->label_image->m_inputImg.height(); + double width = static_cast(objBox.box.width()) / ui->label_image->m_inputImg.width(); + double height = static_cast(objBox.box.height()) / ui->label_image->m_inputImg.height(); + + fileOutputLabelData << objBox.label; + fileOutputLabelData << " "; + fileOutputLabelData << std::fixed << std::setprecision(6) << midX; + fileOutputLabelData << " "; + fileOutputLabelData << std::fixed << std::setprecision(6) << midY; + fileOutputLabelData << " "; + fileOutputLabelData << std::fixed << std::setprecision(6) << width; + fileOutputLabelData << " "; + fileOutputLabelData << std::fixed << std::setprecision(6) << height; + } + + fileOutputLabelData.close(); + + ui->textEdit_log->setText(qstrOutputLabelData + " saved."); + } +} + +void MainWindow::clear_label_data() +{ + ui->label_image->m_objBoundingBoxes.clear(); + ui->label_image->showImage(); +} + +void MainWindow::next_label() +{ + set_label(m_labelIndex + 1); +} + +void MainWindow::prev_label() +{ + set_label(m_labelIndex - 1); +} + +void MainWindow::load_label_list_data(QString qstrLabelListFile) +{ + ifstream inputLabelListFile(qstrLabelListFile.toStdString()); + + if(inputLabelListFile.is_open()) + { + m_labelNameList.clear(); + + string strLabel; + QStringList verticalHeaderLabels; + + int fileIndex = 0; + while(inputLabelListFile >> strLabel) + { + int nRow = ui->tableWidget_label->rowCount(); + + QString qstrLabel = QString().fromStdString(strLabel); + QColor labelColor = label_img::BOX_COLORS[(fileIndex++)%10]; + m_labelNameList << qstrLabel; + + ui->tableWidget_label->insertRow(nRow); + ui->tableWidget_label->setItem(nRow, 0, new QTableWidgetItem(qstrLabel)); + ui->tableWidget_label->setItem(nRow, 1, new QTableWidgetItem(QString().fromStdString(""))); + ui->tableWidget_label->item(nRow, 1)->setBackgroundColor(labelColor); + ui->tableWidget_label->item(nRow, 0)->setFlags(ui->tableWidget_label->item(nRow, 0)->flags() ^ Qt::ItemIsEditable); + ui->tableWidget_label->item(nRow, 1)->setFlags(ui->tableWidget_label->item(nRow, 1)->flags() ^ Qt::ItemIsEditable ^ Qt::ItemIsSelectable); + + ui->label_image->m_drawObjectBoxColor.push_back(labelColor); + } + } +} + +QString MainWindow::get_labeling_data(QString qstrImgFile)const +{ + string strImgFile = qstrImgFile.toStdString(); + string strLabelData = strImgFile.substr(0, strImgFile.find_last_of('.')) + ".txt"; + + return QString().fromStdString(strLabelData); +} + +void MainWindow::set_label(int labelIndex) +{ + bool indexIsOutOfRange = (labelIndex < 0 || labelIndex > m_labelNameList.size() - 1); + + if(!indexIsOutOfRange) + { + m_labelIndex = labelIndex; + ui->label_image->setFocusObjectLabel(m_labelIndex); + ui->label_image->setFocusObjectName(m_labelNameList.at(m_labelIndex)); + ui->tableWidget_label->setCurrentCell(m_labelIndex, 0); + } +} + +void MainWindow::set_label_color(int index, QColor color) +{ + ui->label_image->m_drawObjectBoxColor.replace(index, color); +} + +void MainWindow::pjreddie_style_msgBox(QMessageBox::Icon icon, QString title, QString content) +{ + QMessageBox msgBox(icon, title, content, QMessageBox::Ok); + + QFont font; + font.setBold(true); + msgBox.setFont(font); + msgBox.button(QMessageBox::Ok)->setFont(font); + msgBox.button(QMessageBox::Ok)->setStyleSheet("border-style: outset; border-width: 2px; border-color: rgb(0, 255, 0); color : rgb(0, 255, 0);"); + msgBox.setStyleSheet("background-color : rgb(34, 0, 85); color : rgb(0, 255, 0);"); + + msgBox.exec(); +} + +void MainWindow::wheelEvent(QWheelEvent *ev) +{ + if(ev->delta() > 0) // up Wheel + prev_img(); + else if(ev->delta() < 0) //down Wheel + next_img(); +} + +void MainWindow::on_pushButton_prev_clicked() +{ + prev_img(); +} + +void MainWindow::on_pushButton_next_clicked() +{ + next_img(); +} + +void MainWindow::keyPressEvent(QKeyEvent * event) +{ + cout << "key pressed" <key(); + bool graveAccentKeyIsPressed = (nKey == Qt::Key_QuoteLeft); + bool numKeyIsPressed = (nKey >= Qt::Key_0 && nKey <= Qt::Key_9 ); + + if(graveAccentKeyIsPressed) + { + ui->label_image->setFocusObjectLabel(0); + ui->label_image->setFocusObjectName(m_labelNameList.at(0)); + ui->tableWidget_label->setCurrentCell(0, 0); //foucs cell(0,0) + } + else if(numKeyIsPressed) + { + int asciiToNumber = nKey - Qt::Key_0; + + if(asciiToNumber < m_labelNameList.size() ) + { + ui->label_image->setFocusObjectLabel(asciiToNumber); + ui->label_image->setFocusObjectName(m_labelNameList.at(asciiToNumber)); + ui->tableWidget_label->setCurrentCell(asciiToNumber, 0); + } + } +} + +void MainWindow::mouseCurrentPos() +{ + +} + +void MainWindow::mousePressed() +{ + +} + +void MainWindow::mouseReleased() +{ + +} + +void MainWindow::on_horizontalSlider_images_valueChanged(int value) +{ + + // cout<<"kiff"<tableWidget_label->item(row, 1)->setBackgroundColor(color); + } + set_label(row); + ui->label_image->showImage(); + } +} + +void MainWindow::on_tableWidget_label_cellClicked(int row, int column) +{ + set_label(row); +} + +void MainWindow::on_horizontalSlider_images_sliderMoved(int position) +{ + goto_img(position); +} + +void MainWindow::on_horizontalSlider_images_sliderPressed() +{ + //save_label_data(); //prev data save +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..ce458b4 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,87 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include + +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +Q_SIGNALS: + +private slots: + void on_pushButton_open_files_clicked(); + void on_pushButton_save_clicked(); + + + void on_pushButton_prev_clicked(); + void on_pushButton_next_clicked(); + + void on_horizontalSlider_images_valueChanged(int value); + + void keyPressEvent(QKeyEvent *); + + void mouseCurrentPos(); + void mousePressed(); + void mouseReleased(); + + void next_img(); + void prev_img(); + void save_label_data() const; + void clear_label_data(); + + void next_label(); + void prev_label(); + + void on_tableWidget_label_cellDoubleClicked(int row, int column); + void on_tableWidget_label_cellClicked(int row, int column); + + void on_horizontalSlider_images_sliderMoved(int position); + + 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(); + + void img_open(const int); + void set_label_progress(const int); + void set_focused_file(const int); + + void goto_img(int); + + void load_label_list_data(QString); + QString get_labeling_data(QString)const; + + void set_label(int); + void set_label_color(int , QColor); + + void pjreddie_style_msgBox(QMessageBox::Icon, QString, QString); + +protected: + void wheelEvent(QWheelEvent *); +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..a9ffe4b --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,700 @@ + + + MainWindow + + + + 0 + 0 + 1514 + 953 + + + + + 0 + 0 + + + + + 1400 + 920 + + + + + 16777215 + 16777215 + + + + Qt::StrongFocus + + + Image Labeling Tool + + + background-color : rgb(0, 0, 17); + + + + + 0 + 0 + + + + + 1363 + 867 + + + + + 16777215 + 16777215 + + + + + + + + + + + + 1275 + 20 + + + + + 16777215 + 20 + + + + + 13 + 75 + true + + + + color : rgb(255, 187, 0); + + + File: + + + + + + + + 0 + 0 + + + + + 1280 + 720 + + + + + 18 + 75 + true + + + + ArrowCursor + + + true + + + QLabel { background-color : rgb(0, 0, 17); color : rgb(187, 255, 254); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255);} + + + + + QFrame::StyledPanel + + + QFrame::Plain + + + 3 + + + Open Data Set Directory... + + + true + + + Qt::AlignCenter + + + -1 + + + label_image + + + + + + + + + + + false + + + + 75 + 23 + + + + + 75 + true + + + + Qt::NoFocus + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + Prev + + + + + + false + + + false + + + false + + + + + + + false + + + + 75 + 23 + + + + + 75 + true + + + + Qt::NoFocus + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + Next + + + Del + + + false + + + false + + + false + + + + + + + false + + + + 1 + 0 + + + + + 881 + 22 + + + + Qt::ClickFocus + + + +QSlider::groove:horizontal { + border: 1px solid #999999; + height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */ + background: rgb(0, 255, 255); + margin: 2px 0; +} + + +QSlider::handle:horizontal { + background: rgb(255, 187, 0); + border: 1px solid #5c5c5c; + width: 18px; + margin: -10px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */ + border-radius: 3px; +} + + + + 0 + + + 10 + + + false + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 211 + 21 + + + + + 75 + true + + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + QFrame::StyledPanel + + + 2 + + + 0 / 0 + + + Qt::AlignCenter + + + + + + + + + + + + 291 + 91 + + + + + 16777215 + 91 + + + + + 75 + true + true + + + + Qt::NoFocus + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + Open Files + + + false + + + false + + + + + + + false + + + + 291 + 91 + + + + + 16777215 + 91 + + + + + 75 + true + true + + + + Qt::NoFocus + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + Save + + + + + + false + + + false + + + false + + + + + + + + + true + + + + 0 + 0 + + + + + 41 + 12 + + + + + 16777215 + 12 + + + + + 75 + false + true + + + + color : rgb(0, 255, 255); + + + Log + + + + + + + + 0 + 0 + + + + + 640 + 70 + + + + + 16777215 + 70 + + + + + 75 + true + + + + Qt::NoFocus + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + false + + + true + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 202 + 20 + + + + + 202 + 20 + + + + + 13 + 75 + true + + + + + + + + + + + + 0 + 0 + + + + + 204 + 851 + + + + + 204 + 16777215 + + + + + 10 + 75 + true + + + + Qt::NoFocus + + + QHeaderView::section { + background-color: rgb(0, 0, 17); + color: rgb(255, 187, 0); + padding-left: 4px; + border: 2px solid rgb(0, 255, 255); + font-weight: bold; +} +QTableWidget +{ +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); +color:rgb(187, 255, 254); +gridline-width:2px; +gridline-color: rgb(0, 255, 255); +} + +QTableView { + selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 1.0, y2: 1.0, stop: 0 rgb(34, 0, 85), stop: 1 white); + selection-color: rgb(0, 255, 0); +} + + + QFrame::WinPanel + + + QFrame::Plain + + + 5 + + + true + + + false + + + true + + + true + + + 2 + + + true + + + true + + + true + + + false + + + false + + + false + + + + Name + + + + + Color + + + + + + + + + + + + + + 0 + 0 + 1514 + 21 + + + + + + TopToolBarArea + + + false + + + + + + + + label_img + QLabel +
label_img.h
+
+
+ + +