From 40b30f1ceef0266ffc6a4f8b9fbe0d91aacf5740 Mon Sep 17 00:00:00 2001 From: Lieven Govaerts Date: Thu, 27 Dec 2018 13:42:20 +0100 Subject: [PATCH] labelImg.py/loadLabels: correct shapes that are out of image bounds. --- labelImg.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/labelImg.py b/labelImg.py index ece1d031..01bb3236 100755 --- a/labelImg.py +++ b/labelImg.py @@ -758,6 +758,15 @@ class MainWindow(QMainWindow, WindowMixin): for label, points, line_color, fill_color, difficult in shapes: shape = Shape(label=label) for x, y in points: + + # Ensure the labels are within the bounds of the image. If not, fix them. + if x < 0 or x > self.canvas.pixmap.width() or y < 0 or y > self.canvas.pixmap.height(): + x = max(x, 0) + y = max(y, 0) + x = min(x, self.canvas.pixmap.width()) + y = min(y, self.canvas.pixmap.height()) + self.setDirty() + shape.addPoint(QPointF(x, y)) shape.difficult = difficult shape.close()