Ejemplo n.º 1
0
    def __init__(self,
                 filename=None,
                 labels={},
                 images=[],
                 correspondences=None,
                 spatial_reference_system=None,
                 metadata={},
                 image_metadata_template={}):
        self.filename = None  #filename with path of the project json
        self.labels = {key: Label(**value) for key, value in labels.items()}
        if not 'Empty' in self.labels:
            self.labels['Empty'] = Label(id='Empty',
                                         name='Empty',
                                         description=None,
                                         fill=[127, 127, 127],
                                         border=[200, 200, 200],
                                         visible=True)

        self.images = list(map(lambda img: Image(**img),
                               images))  #list of annotated images

        # dict of tables (DataFrame) of correspondences betweeen a source and a target image
        self.correspondences = {}
        if correspondences is not None:
            for key in correspondences.keys():
                source = correspondences[key]['source']
                target = correspondences[key]['target']
                self.correspondences[key] = Correspondences(
                    self.getImageFromId(source), self.getImageFromId(target))
                self.correspondences[key].fillTable(
                    correspondences[key]['correspondences'])

        self.spatial_reference_system = spatial_reference_system  #if None we assume coordinates in pixels (but Y is up or down?!)
        self.metadata = metadata  # project metadata => keyword -> value
        self.image_metadata_template = image_metadata_template  # description of metadata keywords expected in images
Ejemplo n.º 2
0
    def getImagePairCorrespondences(self, img_source_idx, img_target_idx):
        """
        Given two image indices returns the current correspondences table or create a new one.
        Note that the correspondences between the image A and the image B are not the same of
        the image B and A.
        """
        key = self.images[img_source_idx].id + "-" + self.images[
            img_target_idx].id

        if self.correspondences is None:
            # create a new correspondences table
            self.correspondences = {}
            self.correspondences[key] = Correspondences(
                self.images[img_source_idx], self.images[img_target_idx])
        elif not key in self.correspondences:
            # create a new correspondences table
            self.correspondences[key] = Correspondences(
                self.images[img_source_idx], self.images[img_target_idx])

        return self.correspondences[key]