コード例 #1
0
    def parseFromFile(self, filename):
        """
        Overwritten to read Okapi::Annotation files.
        """
        container = okapy.AnnotationContainer()
        container.ReadFromFile(filename)

        annotations = []
        for f in container.files():
            fileitem = self.convertAnnotationPropertiesMapToDict(
                f.properties())
            fileitem[config.METADATA_LABELCLASS_TOKEN] = fileitem['type']
            del fileitem['type']
            if f.isImage():
                fileitem['annotations'] = []
                for annotation in f.annotations():
                    ann = self.convertAnnotationPropertiesMapToDict(
                        annotation.properties())
                    fileitem['annotations'].append(ann)
            elif f.isVideo():
                fileitem['frames'] = []
                for frame in f.frames():
                    frameitem = self.convertAnnotationPropertiesMapToDict(
                        frame.properties())
                    frameitem['annotations'] = []
                    for annotation in frame.annotations():
                        ann = self.convertAnnotationPropertiesMapToDict(
                            annotation.properties())
                        frameitem['annotations'].append(ann)
                    fileitem['frames'].append(frameitem)
            annotations.append(fileitem)

        return annotations
コード例 #2
0
    def serializeToFile(self, fname, annotations, customImgDir=''):
        """
        Overwritten to write Okapi::Annotation files.
        """
        container = okapy.AnnotationContainer()

        for f in annotations:
            fileitem = okapy.AnnotationFileItem()
            if f.has_key(config.METADATA_LABELCLASS_TOKEN):
                f['type'] = f[config.METADATA_LABELCLASS_TOKEN]
                del f[config.METADATA_LABELCLASS_TOKEN]
            fileitem = self.convertDictToAnnotationPropertiesMap(fileitem, f)
            if fileitem.isImage():
                if f.has_key('annotations'):
                    for annotation in f['annotations']:
                        annoitem = okapy.AnnotationItem()
                        annoitem = self.convertDictToAnnotationPropertiesMap(
                            annoitem, annotation)
                        fileitem.annotations().push_back(annoitem)
            elif fileitem.isVideo():
                if f.has_key('frames'):
                    for frame in f['frames']:
                        frameitem = okapy.AnnotationFrameItem()
                        frameitem = self.convertDictToAnnotationPropertiesMap(
                            frameitem, frame)
                        if frame.has_key('annotations'):
                            for annotation in frame['annotations']:
                                annoitem = okapy.AnnotationItem()
                                annoitem = self.convertDictToAnnotationPropertiesMap(
                                    annoitem, annotation)
                                frameitem.annotations().push_back(annoitem)
                        fileitem.frames().push_back(frameitem)
            container.files().push_back(fileitem)

        container.WriteToFile(fname)
コード例 #3
0
    def serializeToFile(self, fname, annotations):
        """
        Overwritten to write Okapi::Annotation files.
        """
        container = okapy.AnnotationContainer()

        for f in annotations:
            fileitem = okapy.AnnotationFileItem()
            if f.has_key('class'):
                f['type'] = f['class']
                del f['class']
            fileitem = self.convertDictToAnnotationPropertiesMap(fileitem, f)
            if fileitem.isImage():
                if f.has_key('annotations'):
                    for annotation in f['annotations']:
                        annoitem = okapy.AnnotationItem()
                        annoitem = self.convertDictToAnnotationPropertiesMap(annoitem, annotation)
                        fileitem.annotations().push_back(annoitem)
            elif fileitem.isVideo():
                if f.has_key('frames'):
                    for frame in f['frames']:
                        frameitem = okapy.AnnotationFrameItem()
                        frameitem = self.convertDictToAnnotationPropertiesMap(frameitem, frame)
                        if frame.has_key('annotations'):
                            for annotation in frame['annotations']:
                                annoitem = okapy.AnnotationItem()
                                annoitem = self.convertDictToAnnotationPropertiesMap(annoitem, annotation)
                                frameitem.annotations().push_back(annoitem)
                        fileitem.frames().push_back(frameitem)
            container.files().push_back(fileitem)

        # TODO make all image filenames relative to the label file
        container.WriteToFile(fname)