def fetch_all(self, entity_id: int): anns = AnnotationEntity.alias() lbl = LabelEntity.alias() query = ( anns.select( anns.id.alias("annot_id"), anns.entry.alias("annot_entry"), anns.kind.alias("annot_kind"), anns.points.alias("annot_points"), lbl.id.alias("label_id"), lbl.name.alias("label_name"), lbl.color.alias("label_color") ) .join(lbl, on=(anns.label == lbl.id), join_type="LEFT") .where(anns.entry == entity_id) ) cursor = query.dicts().execute() result = [] for row in cursor: ann_vo = AnnotaVO() ann_vo.id = row["annot_id"] ann_vo.entry = row["annot_entry"] ann_vo.kind = row["annot_kind"] ann_vo.points = row["annot_points"] ann_vo.label = None if row["label_id"]: label = LabelVO() label.id = row["label_id"] label.name = row["label_name"] label.color = row["label_color"] ann_vo.label = label result.append(ann_vo) return result
def do_work(): annotations = [] for xml_file in files: tree = ET.parse(xml_file) root = tree.getroot() objects = root.findall('object') image_path = root.find('path').text image_vo = self._ds_dao.find_by_path( dataset_vo.id, image_path) if image_vo: for roi in objects: label_name = roi.find('name').text label_name = label_name.title() label_vo = self._labels_dao.find_by_name( dataset_vo.id, label_name) if label_vo is None: label_vo = LabelVO() label_vo.name = label_name label_vo.dataset = dataset_vo.id label_vo.color = colors[random.randint( 0, len(colors))] label_vo = self._labels_dao.save( label_vo) box = roi.find("bndbox") if box: x1 = int(box.find('xmin').text) y1 = int(box.find('ymin').text) x2 = int(box.find('xmax').text) y2 = int(box.find('ymax').text) box = AnnotaVO() box.label = label_vo.id box.entry = image_vo.id box.kind = "box" box.points = ",".join( map(str, [x1, y1, x2, y2])) annotations.append(box) if len(annotations) > 0: print(annotations) self._annot_dao.save(dataset_vo.id, annotations) return annotations, None
def result(self) -> LabelVO: vo = LabelVO() vo.name = self.nameLineEdit.text() vo.color = self.colorLineEdit.text() return vo