Example #1
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)
Example #2
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)