def mouseMoveEvent(self, event):
        if self.image.isNull() or self.w == 0 or self.h == 0:
            return

        mousePosOrig = QtCore.QPointF(event.x(), event.y())
        mousePosScaled = QtCore.QPointF(float(mousePosOrig.x() - self.xoff) / self.scale,
                                        float(mousePosOrig.y() - self.yoff) / self.scale)
        mouseOutsideImage = not self.image.rect().contains(mousePosScaled.toPoint())

        mousePosScaled.setX(max(mousePosScaled.x(), 0.))
        mousePosScaled.setY(max(mousePosScaled.y(), 0.))
        mousePosScaled.setX(min(mousePosScaled.x(), self.image.rect().right()))
        mousePosScaled.setY(min(mousePosScaled.y(), self.image.rect().bottom()))

        if not self.image.rect().contains(mousePosScaled.toPoint()):
            print(self.image.rect())
            print(mousePosScaled.toPoint())
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePosScaled = mousePosScaled
        self.mousePosOrig = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

        # Redraw
        self.updateMouseObject()
        self.update()
 def scaleBoundingBox(self, bbox):
     bboxToDraw = copy.deepcopy(bbox)
     x, y, w, h = bboxToDraw.getRect()
     bboxToDraw.setTopLeft(QtCore.QPointF(x * self.scale, y * self.scale))
     bboxToDraw.setSize(QtCore.QSizeF(w * self.scale, h * self.scale))
     return bboxToDraw
 def getPolygon(self, obj):
     poly = QtGui.QPolygonF()
     for pt in obj.polygon:
         point = QtCore.QPointF(pt.x, pt.y)
         poly.append(point)
     return poly