From 43ce2bd7c03bc3d5c91f96b3b740dedb623acf22 Mon Sep 17 00:00:00 2001 From: yonghye Date: Wed, 31 Oct 2018 19:30:27 +0900 Subject: [PATCH] add cropped image save option --- label_img.h | 1 + mainwindow.cpp | 18 ++++++++++++++---- mainwindow.ui | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/label_img.h b/label_img.h index 8249250..0e5fb68 100644 --- a/label_img.h +++ b/label_img.h @@ -24,6 +24,7 @@ public: void mousePressEvent(QMouseEvent *ev); void mouseReleaseEvent(QMouseEvent *ev); + QImage m_inputImg; QImage m_inputImgCopy;//for drawing diff --git a/mainwindow.cpp b/mainwindow.cpp index 76c4aa5..8430718 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -68,10 +68,10 @@ void MainWindow::on_pushButton_open_files_clicked() QString fileLabelList = QFileDialog::getOpenFileName( - this, - tr("Open LabelList file"), - "./", - tr("LabelList Files (*.txt *.names)")); + this, + tr("Open LabelList file"), + "./", + tr("LabelList Files (*.txt *.names)")); if(fileLabelList.size() == 0) { @@ -168,6 +168,16 @@ void MainWindow::save_label_data()const ObjectLabelingBox objBox = ui->label_image->m_objBoundingBoxes[i]; + if(ui->checkBox_cropping->isChecked()) + { + QImage cropped = ui->label_image->m_inputImgCopy.copy(objBox.box); + + string strImgFile = m_fileList.at(m_fileIndex).toStdString(); + strImgFile = strImgFile.substr( strImgFile.find_last_of('/') + 1, + strImgFile.find_last_of('.') - strImgFile.find_last_of('/') - 1); + + cropped.save(QString().fromStdString(strImgFile) + "_cropped_" + QString::number(i) + ".png"); + } 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(); diff --git a/mainwindow.ui b/mainwindow.ui index c6a4e99..2ff7bbc 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -112,7 +112,7 @@ - ArrowCursor + CrossCursor true @@ -342,7 +342,7 @@ border-color: rgb(0, 255, 255); - 291 + 271 91 @@ -386,7 +386,7 @@ border-color: rgb(0, 255, 255); - 291 + 271 91 @@ -429,6 +429,34 @@ border-color: rgb(0, 255, 255); + + + + + 90 + 21 + + + + + 75 + true + + + + ArrowCursor + + + background-color : rgb(0, 0, 17);color : rgb(0, 255, 255); +border-style: outset; +border-width: 2px; +border-color: rgb(0, 255, 255); + + + with crop + + + @@ -632,7 +660,7 @@ QTableView { 2 - true + false false @@ -684,6 +712,7 @@ QTableView { false +