def track(self, img_files, box, visualize=False, use_confidences=False):
        frame_num = len(img_files)
        boxes = np.zeros((frame_num, 4))
        confs = np.zeros((frame_num))
        boxes[0] = box
        times = np.zeros(frame_num)

        for f, img_file in enumerate(img_files):
            image = Image.open(img_file)

            if not image.mode == 'RGB':
                image = image.convert('RGB')

            image = np.asarray(image)[..., ::-1]

            start_time = time.time()
            if f == 0:
                self.init(image, box)
            else:
                boxes[f, :] = self.track_img(image)['bbox']
                confs[f] = self.track_img(image)['best_score']
            times[f] = time.time() - start_time

            if visualize:
                show_frame(image, boxes[f, :])

        return boxes, times, confs
Exemple #2
0
    def track(self,
              img_files: List[str],
              box: np.ndarray,
              visualize: bool = False) -> Tuple[np.ndarray, np.ndarray]:
        """
        Method `track` for GOT-10k toolkit trackers (MIT licence).

        :param img_files: Image files.
        :param box: Initial boxes.
        :param visualize: Visualise tracking.
        """
        from got10k.utils.viz import show_frame
        from PIL import Image

        frame_num = len(img_files)
        boxes = np.zeros((frame_num, 4))
        boxes[0] = box
        times = np.zeros(frame_num)

        for i_f, img_file in enumerate(img_files):
            image = Image.open(img_file)
            if not image.mode == "RGB":
                image = image.convert("RGB")

            start_time = time.time()
            if i_f == 0:
                self.init(image, box)
            else:
                boxes[i_f, :] = self.update(image)
            times[i_f] = time.time() - start_time

            if visualize:
                show_frame(image, boxes[i_f, :])

        return boxes, times
Exemple #3
0
def example_loop_dataset():
    # setup dataset
    dataset = GOT10k(ROOT_DIR, subset='val')

    # loop over the complete dataset
    for s, (img_files, anno) in enumerate(dataset):
        seq_name = dataset.seq_names[s]
        print('Sequence:', seq_name)

        for f, img_file in enumerate(img_files):
            image = Image.open(img_file)
            box = anno[f, :]  # (left, top, width, height)
            show_frame(image, box, colors='w')
Exemple #4
0
    def show(self, tracker_names, seq_names=None, play_speed=1):
        if seq_names is None:
            seq_names = self.dataset.seq_names
        elif isinstance(seq_names, str):
            seq_names = [seq_names]
        assert isinstance(tracker_names, (list, tuple))
        assert isinstance(seq_names, (list, tuple))

        play_speed = int(round(play_speed))
        assert play_speed > 0
        self.dataset.return_meta = False

        for s, seq_name in enumerate(seq_names):
            print('[%d/%d] Showing results on %s...' %
                  (s + 1, len(seq_names), seq_name))

            # load all tracking results
            records = {}
            for name in tracker_names:
                record_file = os.path.join(self.result_dir, name, seq_name,
                                           '%s_001.txt' % seq_name)
                records[name] = np.loadtxt(record_file, delimiter=',')

            # loop over the sequence and display results
            img_files, anno = self.dataset[seq_name]
            for f, img_file in enumerate(img_files):
                if not f % play_speed == 0:
                    continue
                image = Image.open(img_file)
                boxes = [anno[f]
                         ] + [records[name][f] for name in tracker_names]
                show_frame(image,
                           boxes,
                           legends=['GroundTruth'] + tracker_names,
                           colors=[
                               'w', 'r', 'g', 'b', 'c', 'm', 'y', 'orange',
                               'purple', 'brown', 'pink'
                           ])