def _read_annos()

in utils_cv/tracking/dataset.py [0:0]


    def _read_annos(self) -> None:
        """ Parses all Pascal VOC formatted annotation files to extract all
        possible labels. """
        # All annotation files are assumed to be in the anno_dir directory,
        # and images in the im_dir directory
        self.im_filenames = sorted(os.listdir(self.root / self.im_dir))
        im_paths = [
            os.path.join(self.root / self.im_dir, s) for s in self.im_filenames
        ]
        anno_filenames = [
            os.path.splitext(s)[0] + ".xml" for s in self.im_filenames
        ]

        # Read all annotations
        self.im_paths = []
        self.anno_paths = []
        self.anno_bboxes = []
        for anno_idx, anno_filename in enumerate(anno_filenames):
            anno_path = self.root / self.anno_dir / str(anno_filename)

            # Parse annotation file
            anno_bboxes, _, _ = parse_pascal_voc_anno(anno_path)

            # Store annotation info
            self.im_paths.append(im_paths[anno_idx])
            self.anno_paths.append(anno_path)
            self.anno_bboxes.append(anno_bboxes)
        assert len(self.im_paths) == len(self.anno_paths)

        # Get list of all labels
        labels = []
        for anno_bboxes in self.anno_bboxes:
            for anno_bbox in anno_bboxes:
                if anno_bbox.label_name is not None:
                    labels.append(anno_bbox.label_name)
        self.labels = list(set(labels))

        # Set for each bounding box label name also what its integer representation is
        for anno_bboxes in self.anno_bboxes:
            for anno_bbox in anno_bboxes:
                if anno_bbox.label_name is None:
                    # background rectangle is assigned id 0 by design
                    anno_bbox.label_idx = 0
                else:
                    label = self.labels.index(anno_bbox.label_name) + 1
                    anno_bbox.label_idx = label

        # Get image sizes. Note that Image.open() only loads the image header,
        # not the full images and is hence fast.
        self.im_sizes = np.array([Image.open(p).size for p in self.im_paths])