Implemented remove function
This commit is contained in:
parent
79771affed
commit
0922d38ba5
@ -107,11 +107,22 @@ void label_img::setMousePosition(int x, int y)
|
|||||||
m_relative_mouse_pos_in_ui = cvtAbsoluteToRelativePoint(QPoint(x, y));
|
m_relative_mouse_pos_in_ui = cvtAbsoluteToRelativePoint(QPoint(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void label_img::openImage(const QString &qstrImg)
|
void label_img::openImage(const QString &qstrImg, bool &ret)
|
||||||
{
|
{
|
||||||
|
QImage img(qstrImg);
|
||||||
|
|
||||||
|
if(img.isNull())
|
||||||
|
{
|
||||||
|
m_inputImg = QImage();
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = true;
|
||||||
|
|
||||||
m_objBoundingBoxes.clear();
|
m_objBoundingBoxes.clear();
|
||||||
|
|
||||||
m_inputImg = QImage(qstrImg);
|
m_inputImg = img.copy();
|
||||||
m_inputImg = m_inputImg.convertToFormat(QImage::Format_RGB888);
|
m_inputImg = m_inputImg.convertToFormat(QImage::Format_RGB888);
|
||||||
|
|
||||||
m_bLabelingStarted = false;
|
m_bLabelingStarted = false;
|
||||||
@ -128,6 +139,7 @@ void label_img::openImage(const QString &qstrImg)
|
|||||||
setMousePosition(0., 0.);
|
setMousePosition(0., 0.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void label_img::showImage()
|
void label_img::showImage()
|
||||||
{
|
{
|
||||||
@ -199,6 +211,11 @@ void label_img::setFocusObjectName(QString qstrName)
|
|||||||
m_foucsedObjectName = qstrName;
|
m_foucsedObjectName = qstrName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool label_img::isOpened()
|
||||||
|
{
|
||||||
|
return !m_inputImg.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
QImage label_img::crop(QRect rect)
|
QImage label_img::crop(QRect rect)
|
||||||
{
|
{
|
||||||
return m_inputImg.copy(rect);
|
return m_inputImg.copy(rect);
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
QVector <ObjectLabelingBox> m_objBoundingBoxes;
|
QVector <ObjectLabelingBox> m_objBoundingBoxes;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void openImage(const QString &);
|
void openImage(const QString &, bool& ret);
|
||||||
void showImage();
|
void showImage();
|
||||||
|
|
||||||
void loadLabelData(const QString & );
|
void loadLabelData(const QString & );
|
||||||
@ -47,6 +47,8 @@ public:
|
|||||||
void setFocusObjectLabel(int);
|
void setFocusObjectLabel(int);
|
||||||
void setFocusObjectName(QString);
|
void setFocusObjectName(QString);
|
||||||
|
|
||||||
|
|
||||||
|
bool isOpened();
|
||||||
QImage crop(QRect);
|
QImage crop(QRect);
|
||||||
|
|
||||||
QRectF getRelativeRectFromTwoPoints(QPointF , QPointF);
|
QRectF getRelativeRectFromTwoPoints(QPointF , QPointF);
|
||||||
|
116
mainwindow.cpp
116
mainwindow.cpp
@ -30,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(new QShortcut(QKeySequence(Qt::Key_D), this), SIGNAL(activated()), this, SLOT(next_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()));
|
connect(new QShortcut(QKeySequence(Qt::Key_Space), this), SIGNAL(activated()), this, SLOT(next_img()));
|
||||||
|
|
||||||
init_tableWidget();
|
init_table_widget();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -43,11 +43,11 @@ void MainWindow::on_pushButton_open_files_clicked()
|
|||||||
bool bRetImgDir = false;
|
bool bRetImgDir = false;
|
||||||
bool bRetObjFile = false;
|
bool bRetObjFile = false;
|
||||||
|
|
||||||
openImgDir(bRetImgDir);
|
open_img_dir(bRetImgDir);
|
||||||
|
|
||||||
if (!bRetImgDir) return ;
|
if (!bRetImgDir) return ;
|
||||||
|
|
||||||
openObjListFile(bRetObjFile);
|
open_obj_file(bRetObjFile);
|
||||||
|
|
||||||
if (!bRetObjFile) return ;
|
if (!bRetObjFile) return ;
|
||||||
|
|
||||||
@ -58,16 +58,8 @@ void MainWindow::init()
|
|||||||
{
|
{
|
||||||
ui->label_image->init();
|
ui->label_image->init();
|
||||||
|
|
||||||
ui->horizontalSlider_images->setEnabled(true);
|
init_button_event();
|
||||||
ui->pushButton_next->setEnabled(true);
|
init_horizontal_slider();
|
||||||
ui->pushButton_prev->setEnabled(true);
|
|
||||||
ui->pushButton_save->setEnabled(true);
|
|
||||||
|
|
||||||
ui->horizontalSlider_images->setRange(0, m_imgList.size() - 1);
|
|
||||||
|
|
||||||
ui->horizontalSlider_images->blockSignals(true);
|
|
||||||
ui->horizontalSlider_images->setValue(0);
|
|
||||||
ui->horizontalSlider_images->blockSignals(false);
|
|
||||||
|
|
||||||
set_label(0);
|
set_label(0);
|
||||||
goto_img(0);
|
goto_img(0);
|
||||||
@ -88,35 +80,19 @@ void MainWindow::set_focused_file(const int fileIndex)
|
|||||||
|
|
||||||
void MainWindow::goto_img(const int fileIndex)
|
void MainWindow::goto_img(const int fileIndex)
|
||||||
{
|
{
|
||||||
bool indexIsOutOfRange = (fileIndex < 0 || fileIndex > m_imgList.size() - 1);
|
bool bIndexIsOutOfRange = (fileIndex < 0 || fileIndex > m_imgList.size() - 1);
|
||||||
|
if (bIndexIsOutOfRange) return;
|
||||||
|
|
||||||
if(!indexIsOutOfRange)
|
|
||||||
{
|
|
||||||
m_imgIndex = fileIndex;
|
m_imgIndex = fileIndex;
|
||||||
|
|
||||||
ui->label_image->openImage(m_imgList.at(m_imgIndex));
|
bool bImgOpened;
|
||||||
|
ui->label_image->openImage(m_imgList.at(m_imgIndex), bImgOpened);
|
||||||
|
|
||||||
ui->label_image->loadLabelData(get_labeling_data(m_imgList.at(m_imgIndex)));
|
ui->label_image->loadLabelData(get_labeling_data(m_imgList.at(m_imgIndex)));
|
||||||
ui->label_image->showImage();
|
ui->label_image->showImage();
|
||||||
|
|
||||||
set_label_progress(m_imgIndex);
|
set_label_progress(m_imgIndex);
|
||||||
set_focused_file(m_imgIndex);
|
set_focused_file(m_imgIndex);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::next_img()
|
|
||||||
{
|
|
||||||
save_label_data();
|
|
||||||
goto_img(m_imgIndex + 1);
|
|
||||||
|
|
||||||
ui->horizontalSlider_images->blockSignals(true);
|
|
||||||
ui->horizontalSlider_images->setValue(m_imgIndex);
|
|
||||||
ui->horizontalSlider_images->blockSignals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::prev_img()
|
|
||||||
{
|
|
||||||
save_label_data();
|
|
||||||
goto_img(m_imgIndex - 1);
|
|
||||||
|
|
||||||
//it blocks crash with slider change
|
//it blocks crash with slider change
|
||||||
ui->horizontalSlider_images->blockSignals(true);
|
ui->horizontalSlider_images->blockSignals(true);
|
||||||
@ -124,6 +100,18 @@ void MainWindow::prev_img()
|
|||||||
ui->horizontalSlider_images->blockSignals(false);
|
ui->horizontalSlider_images->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::next_img(bool bSavePrev)
|
||||||
|
{
|
||||||
|
if(bSavePrev && ui->label_image->isOpened()) save_label_data();
|
||||||
|
goto_img(m_imgIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::prev_img(bool bSavePrev)
|
||||||
|
{
|
||||||
|
if(bSavePrev) save_label_data();
|
||||||
|
goto_img(m_imgIndex - 1);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::save_label_data()const
|
void MainWindow::save_label_data()const
|
||||||
{
|
{
|
||||||
if(m_imgList.size() == 0) return;
|
if(m_imgList.size() == 0) return;
|
||||||
@ -252,7 +240,7 @@ void MainWindow::set_label(const int labelIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::set_label_color(int index, QColor color)
|
void MainWindow::set_label_color(const int index, const QColor color)
|
||||||
{
|
{
|
||||||
ui->label_image->m_drawObjectBoxColor.replace(index, color);
|
ui->label_image->m_drawObjectBoxColor.replace(index, color);
|
||||||
}
|
}
|
||||||
@ -272,7 +260,7 @@ void MainWindow::pjreddie_style_msgBox(QMessageBox::Icon icon, QString title, QS
|
|||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openImgDir(bool& ret)
|
void MainWindow::open_img_dir(bool& ret)
|
||||||
{
|
{
|
||||||
pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 1. Open Your Data Set Directory");
|
pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 1. Open Your Data Set Directory");
|
||||||
|
|
||||||
@ -289,21 +277,21 @@ void MainWindow::openImgDir(bool& ret)
|
|||||||
|
|
||||||
if(fileList.empty())
|
if(fileList.empty())
|
||||||
{
|
{
|
||||||
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty");
|
|
||||||
ret = false;
|
ret = false;
|
||||||
|
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ret = true;
|
||||||
m_imgDir = imgDir;
|
m_imgDir = imgDir;
|
||||||
m_imgList = fileList;
|
m_imgList = fileList;
|
||||||
|
|
||||||
for(QString& str: m_imgList)
|
for(QString& str: m_imgList)
|
||||||
str = m_imgDir + "/" + str;
|
str = m_imgDir + "/" + str;
|
||||||
ret = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openObjListFile(bool& ret)
|
void MainWindow::open_obj_file(bool& ret)
|
||||||
{
|
{
|
||||||
pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 2. Open Your Label List File(*.txt or *.names)");
|
pjreddie_style_msgBox(QMessageBox::Information,"Help", "Step 2. Open Your Label List File(*.txt or *.names)");
|
||||||
|
|
||||||
@ -315,16 +303,21 @@ void MainWindow::openObjListFile(bool& ret)
|
|||||||
|
|
||||||
if(fileLabelList.size() == 0)
|
if(fileLabelList.size() == 0)
|
||||||
{
|
{
|
||||||
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()");
|
|
||||||
ret = false;
|
ret = false;
|
||||||
|
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
load_label_list_data(fileLabelList);
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
load_label_list_data(fileLabelList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::reupdate_img_list()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::wheelEvent(QWheelEvent *ev)
|
void MainWindow::wheelEvent(QWheelEvent *ev)
|
||||||
{
|
{
|
||||||
if(ev->delta() > 0) // up Wheel
|
if(ev->delta() > 0) // up Wheel
|
||||||
@ -371,6 +364,30 @@ void MainWindow::on_pushButton_save_clicked()
|
|||||||
save_label_data();
|
save_label_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_remove_clicked()
|
||||||
|
{
|
||||||
|
//remove a image
|
||||||
|
QFile::remove(m_imgList.at(m_imgIndex));
|
||||||
|
|
||||||
|
//remove a txt file
|
||||||
|
QString qstrOutputLabelData = get_labeling_data(m_imgList.at(m_imgIndex));
|
||||||
|
QFile::remove(qstrOutputLabelData);
|
||||||
|
|
||||||
|
m_imgList.removeAt(m_imgIndex);
|
||||||
|
|
||||||
|
if(m_imgList.size() == 0)
|
||||||
|
{
|
||||||
|
pjreddie_style_msgBox(QMessageBox::Information,"End", "In directory, there are not any image. program quit.");
|
||||||
|
QCoreApplication::quit();
|
||||||
|
}
|
||||||
|
else if( m_imgIndex == m_imgList.size())
|
||||||
|
{
|
||||||
|
m_imgIndex --;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto_img(m_imgIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_tableWidget_label_cellDoubleClicked(int row, int column)
|
void MainWindow::on_tableWidget_label_cellDoubleClicked(int row, int column)
|
||||||
{
|
{
|
||||||
bool bColorAttributeClicked = (column == 1);
|
bool bColorAttributeClicked = (column == 1);
|
||||||
@ -398,11 +415,24 @@ void MainWindow::on_horizontalSlider_images_sliderMoved(int position)
|
|||||||
goto_img(position);
|
goto_img(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_horizontalSlider_images_sliderPressed()
|
void MainWindow::init_button_event()
|
||||||
{
|
{
|
||||||
|
ui->pushButton_next->setEnabled(true);
|
||||||
|
ui->pushButton_prev->setEnabled(true);
|
||||||
|
ui->pushButton_save->setEnabled(true);
|
||||||
|
ui->pushButton_remove->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::init_tableWidget()
|
void MainWindow::init_horizontal_slider()
|
||||||
|
{
|
||||||
|
ui->horizontalSlider_images->setEnabled(true);
|
||||||
|
ui->horizontalSlider_images->setRange(0, m_imgList.size() - 1);
|
||||||
|
ui->horizontalSlider_images->blockSignals(true);
|
||||||
|
ui->horizontalSlider_images->setValue(0);
|
||||||
|
ui->horizontalSlider_images->blockSignals(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::init_table_widget()
|
||||||
{
|
{
|
||||||
ui->tableWidget_label->horizontalHeader()->setVisible(true);
|
ui->tableWidget_label->horizontalHeader()->setVisible(true);
|
||||||
ui->tableWidget_label->horizontalHeader()->setStyleSheet("");
|
ui->tableWidget_label->horizontalHeader()->setStyleSheet("");
|
||||||
|
25
mainwindow.h
25
mainwindow.h
@ -24,30 +24,31 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_open_files_clicked();
|
void on_pushButton_open_files_clicked();
|
||||||
void on_pushButton_save_clicked();
|
void on_pushButton_save_clicked();
|
||||||
|
void on_pushButton_remove_clicked();
|
||||||
|
|
||||||
void on_pushButton_prev_clicked();
|
void on_pushButton_prev_clicked();
|
||||||
void on_pushButton_next_clicked();
|
void on_pushButton_next_clicked();
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent *);
|
void keyPressEvent(QKeyEvent *);
|
||||||
|
|
||||||
void next_img();
|
void next_img(bool bSavePrev = true);
|
||||||
void prev_img();
|
void prev_img(bool bSavePrev = true);
|
||||||
void save_label_data() const;
|
void save_label_data() const;
|
||||||
void clear_label_data();
|
void clear_label_data();
|
||||||
|
|
||||||
void next_label();
|
void next_label();
|
||||||
void prev_label();
|
void prev_label();
|
||||||
|
|
||||||
void on_tableWidget_label_cellDoubleClicked(int row, int column);
|
void on_tableWidget_label_cellDoubleClicked(int , int );
|
||||||
void on_tableWidget_label_cellClicked(int row, int column);
|
void on_tableWidget_label_cellClicked(int , int );
|
||||||
|
|
||||||
void on_horizontalSlider_images_sliderMoved(int position);
|
void on_horizontalSlider_images_sliderMoved(int );
|
||||||
void on_horizontalSlider_images_sliderPressed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init_tableWidget();
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
void init_table_widget();
|
||||||
|
void init_button_event();
|
||||||
|
void init_horizontal_slider();
|
||||||
|
|
||||||
void img_open(const int);
|
void img_open(const int);
|
||||||
void set_label_progress(const int);
|
void set_label_progress(const int);
|
||||||
@ -59,12 +60,14 @@ private:
|
|||||||
QString get_labeling_data(QString)const;
|
QString get_labeling_data(QString)const;
|
||||||
|
|
||||||
void set_label(const int);
|
void set_label(const int);
|
||||||
void set_label_color(const int , QColor);
|
void set_label_color(const int , const QColor);
|
||||||
|
|
||||||
void pjreddie_style_msgBox(QMessageBox::Icon, QString, QString);
|
void pjreddie_style_msgBox(QMessageBox::Icon, QString, QString);
|
||||||
|
|
||||||
void openImgDir(bool&);
|
void open_img_dir(bool&);
|
||||||
void openObjListFile(bool&);
|
void open_obj_file(bool&);
|
||||||
|
|
||||||
|
void reupdate_img_list();
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ border-color: rgb(0, 255, 255);</string>
|
|||||||
<widget class="QPushButton" name="pushButton_open_files">
|
<widget class="QPushButton" name="pushButton_open_files">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>271</width>
|
<width>200</width>
|
||||||
<height>91</height>
|
<height>91</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
@ -384,7 +384,7 @@ border-color: rgb(0, 255, 255);</string>
|
|||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>271</width>
|
<width>200</width>
|
||||||
<height>91</height>
|
<height>91</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
@ -427,6 +427,37 @@ border-color: rgb(0, 255, 255);</string>
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>91</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>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_cropping">
|
<widget class="QCheckBox" name="checkBox_cropping">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
@ -450,6 +481,9 @@ border-color: rgb(0, 255, 255);</string>
|
|||||||
<property name="cursor">
|
<property name="cursor">
|
||||||
<cursorShape>ArrowCursor</cursorShape>
|
<cursorShape>ArrowCursor</cursorShape>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
|
<string notr="true">background-color : rgb(0, 0, 17);color : rgb(0, 255, 255);
|
||||||
border-style: outset;
|
border-style: outset;
|
||||||
@ -664,7 +698,7 @@ QTableView {
|
|||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="horizontalHeaderVisible">
|
<attribute name="horizontalHeaderVisible">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="horizontalHeaderHighlightSections">
|
<attribute name="horizontalHeaderHighlightSections">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
Loading…
Reference in New Issue
Block a user