Exemple #1
0
 def wrapper(*args, **kwargs):
     try:
         if args or kwargs:
             return function(*args, **kwargs)
         else:
             return function()
     except Exception:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         GUIUtilities.show_error_message("{}".format(
             str(traceback.format_exception_only(exc_type, exc_value)[0])))
        def done_work(args):
            result, error = args
            if result:
                label, annotations = result
                if label:
                    self._class_label.setVisible(True)
                    self._class_label.setText(label)
                else:
                    self._class_label.setVisible(False)
                    self._class_label.setText("")

                if annotations:
                    img_bbox: QRectF = self.image_viewer.pixmap.sceneBoundingRect(
                    )
                    offset = QPointF(img_bbox.width() / 2,
                                     img_bbox.height() / 2)
                    for entry in annotations:
                        try:
                            vo: AnnotaVO = entry
                            points = map(float, vo.points.split(","))
                            points = list(more_itertools.chunked(points, 2))
                            if vo.kind == "box" or vo.kind == "ellipse":
                                x = points[0][0] - offset.x()
                                y = points[0][1] - offset.y()
                                w = math.fabs(points[0][0] - points[1][0])
                                h = math.fabs(points[0][1] - points[1][1])
                                roi: QRectF = QRectF(x, y, w, h)
                                if vo.kind == "box":
                                    item = EditableBox(roi)
                                else:
                                    item = EditableEllipse()
                                item.tag = self.tag.dataset
                                item.setRect(roi)
                                item.label = vo.label
                                self.image_viewer.scene().addItem(item)
                            elif vo.kind == "polygon":
                                item = EditablePolygon()
                                item.label = vo.label
                                item.tag = self.tag.dataset
                                self.image_viewer.scene().addItem(item)
                                for p in points:
                                    item.addPoint(
                                        QPoint(p[0] - offset.x(),
                                               p[1] - offset.y()))
                        except Exception as ex:
                            GUIUtilities.show_error_message(
                                "Error loading the annotations: {}".format(ex),
                                "Error")