Ejemplo n.º 1
0
    def init(self, frame, bbox):
        self.size = (frame.shape[1], frame.shape[0])
        # for update
        self.pos_generator = SampleGenerator('gaussian', self.size, opts['trans_pos'], opts['scale_pos'])
        self.neg_generator = SampleGenerator('uniform', self.size, opts['trans_neg'], opts['scale_neg'])

        # generate bounding box rect
        pos_rects = gen_bboxes(SampleGenerator('gaussian', self.size, opts['trans_pos'], opts['scale_pos']),
                               bbox, opts['n_pos_init'], opts['overlap_pos_init'])

        overlap_pos = opts['overlap_pos_init'].copy()
        while len(pos_rects) == 0 and overlap_pos[0] > 0.3:
            overlap_pos[0] -= 0.1
            pos_rects = gen_bboxes(SampleGenerator('gaussian', self.size, opts['trans_pos'], opts['scale_pos']),
                                   bbox, opts['n_pos_init'], overlap_pos)

        neg_rects = np.random.permutation(np.concatenate([
            gen_bboxes(SampleGenerator('uniform', self.size, opts['trans_neg_init'], opts['scale_neg_init']),
                       bbox, opts['n_neg_init'] // 2, opts['overlap_neg_init']),
            gen_bboxes(SampleGenerator('whole', self.size),
                       bbox, opts['n_neg_init'] // 2, opts['overlap_neg_init'])]))
        neg_rects = np.random.permutation(neg_rects)

        # Extract pos/neg features
        pos_feats = self.extract_feats(frame, pos_rects)
        neg_feats = self.extract_feats(frame, neg_rects)

        # generate corrsponding features of these rects
        self.pos_manager.insert(pos_feats, overlap_ratio(pos_rects, bbox))

        self.neg_manger.insert(neg_feats, overlap_ratio(neg_rects, bbox))

        self.frames += 1
Ejemplo n.º 2
0
    def __call__(self, bbox, n, overlap_range=None, scale_range=None):

        if overlap_range is None and scale_range is None:
            return self._gen_samples(bbox, n)

        else:
            samples = None
            remain = n
            factor = 2
            while remain > 0 and factor < 16:
                samples_ = self._gen_samples(bbox, remain * factor)

                idx = np.ones(len(samples_), dtype=bool)
                if overlap_range is not None:
                    r = overlap_ratio(samples_, bbox)
                    idx *= (r >= overlap_range[0]) * (r <= overlap_range[1])
                if scale_range is not None:
                    s = np.prod(samples_[:, 2:], axis=1) / np.prod(bbox[2:])
                    idx *= (s >= scale_range[0]) * (s <= scale_range[1])

                samples_ = samples_[idx, :]
                samples_ = samples_[:min(remain, len(samples_))]
                if samples is None:
                    samples = samples_
                else:
                    samples = np.concatenate([samples, samples_])
                remain = n - len(samples)
                factor = factor * 2

            return samples
Ejemplo n.º 3
0
    def add_features(self, frame, rect):
        # frame = np.asarray(frame)
        pos_rects = gen_bboxes(self.pos_generator, rect, opts['n_pos_update'], opts['overlap_pos_update'])  # 200

        overlap_pos = opts['overlap_pos_update'].copy()
        while len(pos_rects) == 0 and overlap_pos[0] > 0.3:
            overlap_pos[0] -= 0.1
            pos_rects = gen_bboxes(self.pos_generator, rect, opts['n_pos_update'], overlap_pos)

        neg_rects = np.random.permutation(np.concatenate([
            gen_bboxes(self.neg_generator, rect, opts['n_neg_update'] - opts['n_neg_update'] // 6, opts['overlap_neg_update']),
            gen_bboxes(SampleGenerator('whole', self.size),rect, opts['n_neg_update'] // 6, [0, 0])
        ]))

        # Extract pos/neg features
        pos_feats = self.extract_feats(frame, pos_rects)
        neg_feats = self.extract_feats(frame, neg_rects)

        self.pos_manager.insert(pos_feats, overlap_ratio(pos_rects, rect))
        self.neg_manger.insert(neg_feats, overlap_ratio(neg_rects, rect))

        self.frames += 1
Ejemplo n.º 4
0
    tracker.init()

    all_iou = []
    result_bb = []

    spf_total = time.time() - tic
    for i in range(1, len(img_list)):
        tic = time.time()
        try:
            frame = cv2.cvtColor(cv2.imread(img_list[i]), cv2.COLOR_BGR2RGB)
        except:
            break
        rect, bbreg_rect, score = tracker.update(frame=frame)
        result_bb.append(bbreg_rect)
        torch.cuda.empty_cache()
        iou = overlap_ratio(bbreg_rect, gt[i])[0]
        all_iou.append(iou)

        print("frame: {}/{}, score: {:.3f} iou: {:.3f}".format(
            i,
            len(img_list) - 1, score, iou.squeeze()))

        if opts['vis']:
            img = cv2.cvtColor(np.array(frame), cv2.COLOR_RGB2BGR)
            img = draw_img(img, bbreg_rect, gt[i], idx=i)
            cv2.imshow('tracker', img)
            cv2.waitKey(1)
            cv2.imwrite('../result/{}/{}.'.format('Bird1',
                                                  str(i).zfill(4)),
                        draw_img(img, bbreg_rect, gt[i], idx=i))