Implemented remove function

This commit is contained in:
developer0hye 2018-12-14 13:44:18 +09:00
parent 79771affed
commit 0922d38ba5
5 changed files with 161 additions and 75 deletions

View File

@ -107,11 +107,22 @@ void label_img::setMousePosition(int x, int 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_inputImg = QImage(qstrImg);
m_inputImg = img.copy();
m_inputImg = m_inputImg.convertToFormat(QImage::Format_RGB888);
m_bLabelingStarted = false;
@ -128,6 +139,7 @@ void label_img::openImage(const QString &qstrImg)
setMousePosition(0., 0.);
}
}
}
void label_img::showImage()
{
@ -199,6 +211,11 @@ void label_img::setFocusObjectName(QString qstrName)
m_foucsedObjectName = qstrName;
}
bool label_img::isOpened()
{
return !m_inputImg.isNull();
}
QImage label_img::crop(QRect rect)
{
return m_inputImg.copy(rect);

View File

@ -39,7 +39,7 @@ public:
QVector <ObjectLabelingBox> m_objBoundingBoxes;
void init();
void openImage(const QString &);
void openImage(const QString &, bool& ret);
void showImage();
void loadLabelData(const QString & );
@ -47,6 +47,8 @@ public:
void setFocusObjectLabel(int);
void setFocusObjectName(QString);
bool isOpened();
QImage crop(QRect);
QRectF getRelativeRectFromTwoPoints(QPointF , QPointF);

View File

@ -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_Space), this), SIGNAL(activated()), this, SLOT(next_img()));
init_tableWidget();
init_table_widget();
}
MainWindow::~MainWindow()
@ -43,11 +43,11 @@ void MainWindow::on_pushButton_open_files_clicked()
bool bRetImgDir = false;
bool bRetObjFile = false;
openImgDir(bRetImgDir);
open_img_dir(bRetImgDir);
if (!bRetImgDir) return ;
openObjListFile(bRetObjFile);
open_obj_file(bRetObjFile);
if (!bRetObjFile) return ;
@ -58,16 +58,8 @@ void MainWindow::init()
{
ui->label_image->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_imgList.size() - 1);
ui->horizontalSlider_images->blockSignals(true);
ui->horizontalSlider_images->setValue(0);
ui->horizontalSlider_images->blockSignals(false);
init_button_event();
init_horizontal_slider();
set_label(0);
goto_img(0);
@ -88,35 +80,19 @@ void MainWindow::set_focused_file(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;
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->showImage();
set_label_progress(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
ui->horizontalSlider_images->blockSignals(true);
@ -124,6 +100,18 @@ void MainWindow::prev_img()
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
{
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);
}
@ -272,7 +260,7 @@ void MainWindow::pjreddie_style_msgBox(QMessageBox::Icon icon, QString title, QS
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");
@ -289,21 +277,21 @@ void MainWindow::openImgDir(bool& ret)
if(fileList.empty())
{
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty");
ret = false;
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "This folder is empty");
}
else
{
ret = true;
m_imgDir = imgDir;
m_imgList = fileList;
for(QString& str: m_imgList)
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)");
@ -315,16 +303,21 @@ void MainWindow::openObjListFile(bool& ret)
if(fileLabelList.size() == 0)
{
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()");
ret = false;
pjreddie_style_msgBox(QMessageBox::Critical,"Error", "LabelList file is not opened()");
}
else
{
load_label_list_data(fileLabelList);
ret = true;
load_label_list_data(fileLabelList);
}
}
void MainWindow::reupdate_img_list()
{
}
void MainWindow::wheelEvent(QWheelEvent *ev)
{
if(ev->delta() > 0) // up Wheel
@ -371,6 +364,30 @@ void MainWindow::on_pushButton_save_clicked()
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)
{
bool bColorAttributeClicked = (column == 1);
@ -398,11 +415,24 @@ void MainWindow::on_horizontalSlider_images_sliderMoved(int 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()->setStyleSheet("");

View File

@ -24,30 +24,31 @@ public:
private slots:
void on_pushButton_open_files_clicked();
void on_pushButton_save_clicked();
void on_pushButton_remove_clicked();
void on_pushButton_prev_clicked();
void on_pushButton_next_clicked();
void keyPressEvent(QKeyEvent *);
void next_img();
void prev_img();
void next_img(bool bSavePrev = true);
void prev_img(bool bSavePrev = true);
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_tableWidget_label_cellDoubleClicked(int , int );
void on_tableWidget_label_cellClicked(int , int );
void on_horizontalSlider_images_sliderMoved(int position);
void on_horizontalSlider_images_sliderPressed();
void on_horizontalSlider_images_sliderMoved(int );
private:
void init_tableWidget();
void init();
void init_table_widget();
void init_button_event();
void init_horizontal_slider();
void img_open(const int);
void set_label_progress(const int);
@ -59,12 +60,14 @@ private:
QString get_labeling_data(QString)const;
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 openImgDir(bool&);
void openObjListFile(bool&);
void open_img_dir(bool&);
void open_obj_file(bool&);
void reupdate_img_list();
Ui::MainWindow *ui;

View File

@ -340,7 +340,7 @@ border-color: rgb(0, 255, 255);</string>
<widget class="QPushButton" name="pushButton_open_files">
<property name="minimumSize">
<size>
<width>271</width>
<width>200</width>
<height>91</height>
</size>
</property>
@ -384,7 +384,7 @@ border-color: rgb(0, 255, 255);</string>
</property>
<property name="minimumSize">
<size>
<width>271</width>
<width>200</width>
<height>91</height>
</size>
</property>
@ -427,6 +427,37 @@ border-color: rgb(0, 255, 255);</string>
</property>
</widget>
</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>
<widget class="QCheckBox" name="checkBox_cropping">
<property name="minimumSize">
@ -450,6 +481,9 @@ border-color: rgb(0, 255, 255);</string>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</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;
@ -664,7 +698,7 @@ QTableView {
<number>2</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>