Пример #1
0
def merge_voc(an1, an2):
    an = Annotation()
    if an1.width != an2.width or an1.height != an2.height or an1.depth != an2.depth or an1.filename != an2.filename:
        return None
    an.filename = an1.filename
    an.width = an1.width
    an.height = an1.height
    an.depth = an1.depth
    an.objs = an1.objs + an2.objs
    return an
Пример #2
0
def getCellsByTableID(TableID,db):
    rows = db.getTableCellsWithTableArticleData(TableID)
    cells = []
    for row in rows:
        cell = Cell.Cell()
        cell.idArticle = row[20]
        cell.idPMC = row[24]
        cell.idTable = row[13]
        cell.tableOrder = row[14]
        cell.pragmaticClass = row[22]
        cell.idCell = row[0]
        cell.cellID = row[1]
        cell.cellType = row[2]
        cell.rowN = row[4]
        cell.columnN = row[5]
        cell.Content = row[9]
        cell.Header = row[10]
        cell.Stub = row[11]
        cell.Super_row = row[12]
        cell.HeaderId = row[6]
        cell.StubId = row[7]
        cell.SuperRowId = row[8]
        roles = db.getCellRole(cell.idCell)
        for role in roles:
            if role[0]==1:
                cell.isHeader = True
            if role[0]==2:
                cell.isStub = True
            if role[0]==3:
                cell.isData = True
            if role[0]==4:
                cell.isSuperRow = True
        annotations = db.getCellAnnotation(cell.idCell)
        cell_annotations = []
        if(annotations!= None):
            for ann in annotations:
                Annot = Annotation.Annotation()
                Annot.annotationID = ann[0]
                Annot.Content = ann[1]
                Annot.Start = ann[2]
                Annot.End = ann[3]
                Annot.AnnotationCID = ann[4]
                Annot.AnnotationDesc =ann[5]
                Annot.AgentName = ann[6]
                Annot.AgentType = ann[7]
                Annot.AnnotationURL = ann[8]
                cell_annotations.append(Annot)
        cell.Annotations = cell_annotations
        cells.append(cell)
    return cells
Пример #3
0
    def saveAnnotations(self):

        inputParameters = self.getCurrentInputParameters()

        if self.window.editor.image is None:
            return

        assert self.openFile is not None

        def extractLeadAnnotation(lead: Lead) -> Annotation.LeadAnnotation:
            return Annotation.LeadAnnotation(
                Annotation.CropLocation(
                    lead.x,
                    lead.y,
                    lead.width,
                    lead.height,
                ), lead.startTime)

        metadataDirectory = self.openFile.parent / '.paperecg'
        if not metadataDirectory.exists():
            metadataDirectory.mkdir()

        filePath = metadataDirectory / (self.openFile.stem + '-' +
                                        self.openFile.suffix[1:] + '.json')

        print("leads\n", inputParameters.leads.items())

        leads = {
            name: extractLeadAnnotation(lead)
            for name, lead in inputParameters.leads.items()
        }

        currentDateTime = (
            datetime.datetime.now()).strftime("%m/%d/%Y, %H:%M:%S")

        Annotation.Annotation(timeStamp=currentDateTime,
                              image=Annotation.ImageMetadata(
                                  self.openFile.name,
                                  directory=str(
                                      self.openFile.parent.absolute())),
                              rotation=inputParameters.rotation,
                              timeScale=inputParameters.timeScale,
                              voltageScale=inputParameters.voltScale,
                              leads=leads).save(filePath)

        print("Metadata successfully saved to:", str(filePath))
        self.window.editor.EditPanelGlobalView.setLastSavedTimeStamp(
            currentDateTime)
Пример #4
0
标注进行纠正,保存到指定目录
'''

in_anno_dir = 'E:/DataSet/VOCdevkit/VOC2007/Annotations_bak'
in_img_dir = 'E:/DataSet/VOCdevkit/VOC2007/JPEGImages'
out_anno_dir = 'E:/DataSet/VOCdevkit/VOC2007/Annotations'
#out_img_dir = 'E:/DataSet/hand_face/image'


annotaion_list = os.listdir(in_anno_dir)
index = 0
for annotation_file in annotaion_list:
    print(index, ' :', annotation_file, 'is process...')
    index = index + 1
    annotation_path = os.path.join(in_anno_dir, annotation_file)
    anno = Annotation()
    flag = anno.read_from_xml(annotation_path)
    if flag == False:
        continue
    if len(anno.objs) == 0:
        continue
    img_name = anno.filename
    img_path = os.path.join(in_img_dir, img_name)
    img = io.imread(img_path)
    anno.height = img.shape[0]
    anno.width = img.shape[1]
    anno.depth = img.shape[2]
    anno.check()
    #out_img_path = os.path.join(out_img_dir, img_name)
    #io.imsave(out_img_path, img)
    out_anno_path = os.path.join(out_anno_dir, annotation_file)
Пример #5
0
anno_list2 = os.listdir(input_anno_dir2)

def merge_voc(an1, an2):
    an = Annotation()
    if an1.width != an2.width or an1.height != an2.height or an1.depth != an2.depth or an1.filename != an2.filename:
        return None
    an.filename = an1.filename
    an.width = an1.width
    an.height = an1.height
    an.depth = an1.depth
    an.objs = an1.objs + an2.objs
    return an

anno_set = []
for anno_file1 in anno_list1:
    an1 = Annotation()
    an1.read_from_xml(os.path.join(input_anno_dir1, anno_file1))
    bfind = 0
    for anno_file2 in anno_list2:
        if anno_file1 == anno_file2:
            anno_list2.remove(anno_file2)
            bfind = 1
            break
    if bfind:
        an2 = Annotation()
        an2.read_from_xml(os.path.join(input_anno_dir2, anno_file2))
        an = merge_voc(an1, an2)
        anno_set.append(an)
    else:
        anno_set.append(an1)
Пример #6
0
    def open_file(self, file_type, filename=None):

        title = 'Open Video / Images' if file_type == 'video' else 'Open Annotation'
        file_types = "Video Files (*.avi *.mp4);; Images Files (*.jpg *.bmp *.tif *.tiff *.png)" \
                     if file_type == 'video' else 'Annotation File (*.atc)'

        # if working on unsaved annotation
        if self.annotation and not self.annotation.is_file_saved():
            message_box = QtWidgets.QMessageBox()
            message_box.setText("Annotation has not been saved")
            message_box.setInformativeText("Create new anyway?")
            message_box.setStandardButtons(QtWidgets.QMessageBox.Yes
                                           | QtWidgets.QMessageBox.No)
            message_box.setDefaultButton(QtWidgets.QMessageBox.No)
            ret = message_box.exec_()

            # user wants not to create new one - do nothing
            if ret != QtWidgets.QMessageBox.Yes:
                return

            # user wants to discard his unsaved temp annotation
            self.annotation.close()

        # ask user if no filename given
        if not filename:
            # open file (the 'str' - some versions of pyqt return a QString instead of a normal string)
            filename = str(
                QtWidgets.QFileDialog.getOpenFileName(
                    QtWidgets.QFileDialog(), title, QtCore.QDir.currentPath(),
                    file_types)[0])

            # if user presses 'cancel' in dialog, null string is returned
            if not filename:
                return
        try:
            # open annotation
            self.annotation = Annotation.Annotation(filename)

            # Connect scene to annotation
            self.scene.set_annotation(self.annotation)

            # update slider maximum
            self.frameSlider.setMaximum(self.annotation.num_frames)

            # enable GUI
            self.enable_gui(True)

            # load classes to GUI comboBox
            self.populate_class_combobox(self.annotation.classes())

            # save filename to last video used file (check first that it is not the temporary workspace)
            if self.annotation.is_file_saved():
                pickle.dump(self.annotation.filename(),
                            open(CURRENT_ANNOTATION_FILENAME, "wb"))

            # set window title
            self.setWindowTitle('Video Annotation Tool' + (
                '*' if file_type == 'video' else self.annotation.filename()))

            # update
            self.update()

        except Annotation.VideoLoadVideoNotFound as e:
            message_box = QtWidgets.QMessageBox()
            message_box.setText(str(e))
            message_box.setInformativeText(
                "Would you like to navigate to the new location of the video file?"
            )
            message_box.setStandardButtons(QtWidgets.QMessageBox.Yes
                                           | QtWidgets.QMessageBox.No)
            message_box.setDefaultButton(QtWidgets.QMessageBox.Yes)
            ret = message_box.exec_()
            if ret == QtWidgets.QMessageBox.Yes:
                filename = self.provide_video_location()
                annotation_file = Annotation.Annotation.update_video_filename_in_annotation(
                    e.filename, filename)

                if self.annotation:
                    self.annotation.close()
                    del self.annotation
                self.annotation = None

                self.open_file('annotation', annotation_file)
                # self.annotation = Annotation.Annotation(annotation_file)
                # self.update()

        # file reading failed
        except (Annotation.AnnotationFileError,
                Annotation.VideoLoadError) as e:
            message_box = QtWidgets.QMessageBox()
            message_box.setText(str(e))
            message_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
            message_box.setDefaultButton(QtWidgets.QMessageBox.Ok)
            message_box.exec_()