From 32c05d2ca5dc3923f008fb3967b0a1cc98a38669 Mon Sep 17 00:00:00 2001 From: yonghye Date: Wed, 31 Oct 2018 18:18:58 +0900 Subject: [PATCH] fix bug that rouding off error accumulation --- label_img.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/label_img.cpp b/label_img.cpp index 72f1786..79517cf 100644 --- a/label_img.cpp +++ b/label_img.cpp @@ -86,8 +86,8 @@ void label_img::setMousePosition(int x, int y) if(x > this->width()) x = this->width() - 1; if(y > this->height()) y = this->height() - 1; - m_mouse_pos_in_image_coordinate = QPoint(static_cast(x * m_aspectRatioWidth), - static_cast(y * m_aspectRatioHeight)); + m_mouse_pos_in_image_coordinate = QPoint(static_cast(x * m_aspectRatioWidth + 0.5), + static_cast(y * m_aspectRatioHeight + 0.5)); } void label_img::openImage(const QString &qstrImg) @@ -160,10 +160,15 @@ void label_img::loadLabelData(const QString& labelFilePath) double width = inputFileValues.at(i + 3) * m_inputImg.width(); double height = inputFileValues.at(i + 4) * m_inputImg.height(); - objBox.box.setX(static_cast(midX - width/2)); - objBox.box.setY(static_cast(midY - height/2)); - objBox.box.setWidth(static_cast(width)); - objBox.box.setHeight(static_cast(height)); + + std::cout << "midX: " << midX << std::endl; + std::cout << "midX: " << midY << std::endl; + + + objBox.box.setX(static_cast(midX - width/2 + 0.5)); + objBox.box.setY(static_cast(midY - height/2 + 0.5)); + objBox.box.setWidth(static_cast(width + 0.5)); + objBox.box.setHeight(static_cast(height + 0.5)); m_objBoundingBoxes.push_back(objBox); }