From 8f1e2f327ff90808eada5e37ba728a733bc3a440 Mon Sep 17 00:00:00 2001 From: developer0hye Date: Thu, 8 Nov 2018 20:49:55 +0900 Subject: [PATCH] Fix bug: label index initialize --- label_img.cpp | 16 ++++++++++++++-- main.cpp | 3 ++- mainwindow.cpp | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/label_img.cpp b/label_img.cpp index 527c6f5..c51aa51 100644 --- a/label_img.cpp +++ b/label_img.cpp @@ -82,7 +82,6 @@ void label_img::mouseReleaseEvent(QMouseEvent *ev) void label_img::init() { m_objBoundingBoxes.clear(); - m_bLabelingStarted = false; m_focusedObjectLabel = 0; @@ -115,7 +114,20 @@ void label_img::openImage(const QString &qstrImg) m_inputImg = QImage(qstrImg); m_inputImg = m_inputImg.convertToFormat(QImage::Format_RGB888); - init(); + m_objBoundingBoxes.clear(); + m_bLabelingStarted = false; + + QPoint mousePosInUi = this->mapFromGlobal(QCursor::pos()); + bool mouse_is_in_image = QRect(0, 0, this->width(), this->height()).contains(mousePosInUi); + + if (mouse_is_in_image) + { + setMousePosition(mousePosInUi.x(), mousePosInUi.y()); + } + else + { + setMousePosition(0., 0.); + } } void label_img::showImage() diff --git a/main.cpp b/main.cpp index b48f94e..29e1450 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ 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 index abd75df..faeb66e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -83,6 +83,7 @@ void MainWindow::on_pushButton_open_files_clicked() load_label_list_data(fileLabelList); + ui->label_image->init(); init(); } @@ -277,6 +278,7 @@ void MainWindow::set_label(int labelIndex) if(!indexIsOutOfRange) { + std::cout << "m_labelIndex = "<< m_labelIndex << std::endl; m_labelIndex = labelIndex; ui->label_image->setFocusObjectLabel(m_labelIndex); ui->label_image->setFocusObjectName(m_labelNameList.at(m_labelIndex));