first commit

This commit is contained in:
yonghye 2018-10-29 13:26:06 +09:00
commit 00cbe9b3b9
8 changed files with 1571 additions and 0 deletions

40
ImageLabelingTool.pro Normal file
View File

@ -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

1
README.md Normal file
View File

@ -0,0 +1 @@
# ImageLabelingTool-YOLO-Style

268
label_img.cpp Normal file
View File

@ -0,0 +1,268 @@
#include "label_img.h"
#include <QPainter>
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<int>(m_mouse_pos_in_ui_coordinate.x() * m_aspectRatioWidth),
static_cast<int>(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<double>(m_inputImg.width()) / this->width();
m_aspectRatioHeight = static_cast<double>(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<double> inputFileValues;
while(inputFile >> inputFileValue)
inputFileValues.push_back(inputFileValue);
for(int i = 0; i < inputFileValues.size(); i += 5)
{
try {
ObjectLabelingBox objBox;
objBox.label = static_cast<int>(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<int>(midX - width/2));
objBox.box.setY(static_cast<int>(midY - height/2));
objBox.box.setWidth(static_cast<int>(width));
objBox.box.setHeight(static_cast<int>(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);
}

83
label_img.h Normal file
View File

@ -0,0 +1,83 @@
#ifndef LABEL_IMG_H
#define LABEL_IMG_H
#include <QObject>
#include <QLabel>
#include <QImage>
#include <QMouseEvent>
#include <iostream>
#include <fstream>
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<QColor> m_drawObjectBoxColor;
int m_uiX;
int m_uiY;
int m_imgX;
int m_imgY;
bool m_bMouseLeftButtonClicked;
static QColor BOX_COLORS[10];
QVector <ObjectLabelingBox> 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

11
main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

381
mainwindow.cpp Normal file
View File

@ -0,0 +1,381 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QColorDialog>
#include <QKeyEvent>
#include <QDebug>
#include <QShortcut>
#include <iomanip>
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<double>(objBox.box.center().x()) / ui->label_image->m_inputImg.width();
double midY = static_cast<double>(objBox.box.center().y()) / ui->label_image->m_inputImg.height();
double width = static_cast<double>(objBox.box.width()) / ui->label_image->m_inputImg.width();
double height = static_cast<double>(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" <<endl;
int nKey = event->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"<<endl;
// save_label_data(); //prev data save
// goto_img(value);
}
void MainWindow::on_pushButton_save_clicked()
{
save_label_data();
}
void MainWindow::on_tableWidget_label_cellDoubleClicked(int row, int column)
{
if(column == 1)
{
QColor color = QColorDialog::getColor(Qt::white,this,"Set Label Color");
if(color.isValid())
{
set_label_color(row, color);
ui->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
}

87
mainwindow.h Normal file
View File

@ -0,0 +1,87 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWheelEvent>
#include <QTableWidgetItem>
#include <QMessageBox>
#include <iostream>
#include <fstream>
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

700
mainwindow.ui Normal file
View File

@ -0,0 +1,700 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1514</width>
<height>953</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1400</width>
<height>920</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>Image Labeling Tool</string>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1363</width>
<height>867</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_file">
<property name="minimumSize">
<size>
<width>1275</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color : rgb(255, 187, 0);</string>
</property>
<property name="text">
<string>File:</string>
</property>
</widget>
</item>
<item>
<widget class="label_img" name="label_image">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1280</width>
<height>720</height>
</size>
</property>
<property name="font">
<font>
<pointsize>18</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="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);}
</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>3</number>
</property>
<property name="text">
<string>Open Data Set Directory...</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>-1</number>
</property>
<property name="buddy">
<cstring>label_image</cstring>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_prev">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>23</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="text">
<string>Prev</string>
</property>
<property name="shortcut">
<string/>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_next">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>23</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="text">
<string>Next</string>
</property>
<property name="shortcut">
<string>Del</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_images">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>881</width>
<height>22</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">
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;
}
</string>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="pageStep">
<number>10</number>
</property>
<property name="tracking">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_progress">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>211</width>
<height>21</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="text">
<string>0 / 0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_open_files">
<property name="minimumSize">
<size>
<width>291</width>
<height>91</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>91</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="text">
<string>Open Files</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>291</width>
<height>91</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>91</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="shortcut">
<string/>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_log">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>12</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>12</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color : rgb(0, 255, 255);</string>
</property>
<property name="text">
<string>Log</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit_log">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>640</width>
<height>70</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>70</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
border-style: outset;
border-width: 2px;
border-color: rgb(0, 255, 255);</string>
</property>
<property name="tabChangesFocus">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_table_widget_padding">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>202</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>202</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>204</width>
<height>851</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>204</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">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);
}</string>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>5</number>
</property>
<property name="showGrid">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="cornerButtonEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Color</string>
</property>
</column>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1514</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>label_img</class>
<extends>QLabel</extends>
<header location="global">label_img.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>