Пример #1
0
    def openpose_detections(self,
                            camera,
                            start_frame=1,
                            stop_frame=float('Inf')):
        detections = h5py.File(self.path +
                               '/detections/openpose/camera%d.mat' %
                               camera)['detections']
        i0 = bisect(RowView(detections, 1), start_frame) - 1
        while detections[1, i0] == start_frame and i0 >= 0:
            i0 -= 1
        i0 += 1

        for ind in range(i0, detections.shape[1]):
            det = detections[:, ind]
            camera = int(det[0])
            frame = int(det[1])
            left, top, width, height = pose2bb(det[2:])
            left, top, right, bottom = map(
                lambda x: int(self.scale * x),
                [left, top, left + width, top + height])
            confidence = det[-1]
            if frame > stop_frame:
                break
            det = Detection(frame, left, top, right, bottom, confidence, ind)
            det.scene_name = camera
            yield det
Пример #2
0
    def detections(self, start_frame=1, stop_frame=np.inf):
        if self._detections is None:
            detections = defaultdict(list)
            part, seq = self.name.split('__')
            seq = os.path.join(self.dataset.base_path,
                               self.dataset.detections_dir, part, seq + '.txt')

            did = 0
            for l in open(seq, "r").readlines():
                frow = tuple(map(float, l.split(',')))
                row = tuple(map(int, frow))
                if row[7] in self.dataset.class_indexes:
                    det = Detection(row[0], row[2], row[3], row[2] + row[4],
                                    row[3] + row[5], frow[6], did)
                    if self.dataset.scale != 1.0:
                        det = det.scale(self.dataset.scale)
                    if not self.should_ignore(det):
                        det.cls = row[7]
                        det.scene_name = self.name
                        detections[det.frame].append(det)
                        did += 1
            for dets in detections.values():
                dets[:] = nms(dets)
            self._detections = detections
            self._last_frame = max(detections.keys())

        stop_frame = min(stop_frame, self._last_frame)
        for f in range(start_frame, stop_frame + 1):
            for det in self._detections[f]:
                yield det
Пример #3
0
 def ground_truth_detections(self, camera):
     gt = io.loadmat(self.path + '/ground_truth/trainval.mat')['trainData']
     gt = gt[gt[:, 2].argsort()]
     for cam, track_id, frame, left, top, width, height, worldX, worldY, feetX, feetyY in gt:
         if cam != camera:
             continue
         det = Detection(frame, left, top, left + width, top + height, None,
                         int(track_id))
         if self.scale != 1.0:
             det = det.scale(self.scale)
         yield det
Пример #4
0
 def ground_truth(self, scene, classes=None):
     if classes is None:
         class_indexes = self.class_indexes
     else:
         class_indexes = set([self.class_names.index(c) for c in classes])
     frames = defaultdict(list)
     fn = self._path(scene, 'annotations') + '.txt'
     for row in np.loadtxt(fn, delimiter=',', dtype=int):
         if row[7] in class_indexes:
             det = Detection(row[0], row[2], row[3], row[2] + row[4],
                             row[3] + row[5], None, row[1])
             det.cls = row[7]
             frames[det.frame].append(det)
     return frames
Пример #5
0
 def ground_truth(self, scene):
     frames = defaultdict(list)
     for row in np.loadtxt(self._path(scene, "gt/gt.txt"), delimiter=','):
         if row[0] < 1 or row[6] == 0 or row[7] != 1:
             continue
         det = Detection(int(row[0]), row[2], row[3], row[2] + row[4],
                         row[3] + row[5], None, int(row[1]))
         frames[det.frame].append(det)
     return frames
Пример #6
0
    def detections(self, start_frame=1, stop_frame=np.inf):
        if self._detections is None:
            detections = defaultdict(list)

            did = 0
            for row in np.loadtxt(self.dataset._path(self.name, "det/det.txt"),
                                  delimiter=','):
                if row[0] < 1 or row[6] == 0:
                    print(row[0], row[6], row[7])
                    continue
                det = Detection(int(row[0]), row[2], row[3], row[2] + row[4],
                                row[3] + row[5], row[6], did)
                det.scene_name = self.name
                detections[det.frame].append(det)
                did += 1
            for dets in detections.values():
                dets[:] = nms(dets)
            self._detections = detections
            self._last_frame = max(detections.keys())

        stop_frame = min(stop_frame, self._last_frame)
        for f in range(start_frame, stop_frame + 1):
            for det in self._detections[f]:
                yield det
Пример #7
0
    def test_detetcion(self):
        d1 = Detection(0, 10, 20, 100, 200, 0.9, 7)
        assert d1.cx == 55
        assert d1.cy == 110
        assert d1.area == 16200

        d2 = Detection(2, 20, 30, 110, 220, 0.9, 7)
        assert d1.iou(d2) == d2.iou(d1) == slow_iou(d1, d2)
        assert d1.iou(d1) == d2.iou(d2) == slow_iou(d1, d1) == slow_iou(
            d1, d1) == 1.0

        assert d1.ioa(d2) == 0.8395061728395061
        assert d2.ioa(d1) == 0.7953216374269005

        assert d1.distance_to(d2) == d2.distance_to(d1) == 18.027756377319946
        assert d1.interpolate(d2, 1) == (1, 15, 25, 105, 210, None, None)
        assert d1.predict(2, 3, 4) == (2, 16, 28, 106, 208, None, None)
        assert d1.scale(2) == (0, 20, 40, 200, 400, 0.9, 7)
        assert d1.move(2, 3) == (0, 12, 23, 102, 203, 0.9, 7)

        mask = np.zeros((500, 500))
        d1.update_mask(mask)
        d2.update_mask(mask)
        assert mask.sum() == 5023500
        assert mask[0, 0] == mask[5, 50] == mask[50, 5] == 0
        assert mask[20, 10] == 255
        assert mask[199, 99] == 255

        for _ in range(1000):
            d1 = random_detection()
            d2 = random_detection()
            assert d1.iou(d2) == d2.iou(d1) == slow_iou(d1, d2)
            assert d1.covers(d1.cx, d1.cy)
            assert d2.covers(d2.cx, d2.cy)

            mask = np.zeros((500, 500))
            d1.update_mask(mask)
            d2.update_mask(mask)
            assert mask[int(d1.cy), int(d1.cx)] == 255
            assert mask[int(d2.cy), int(d2.cx)] == 255
Пример #8
0
def random_detection():
    l = randrange(100)
    t = randrange(100)
    w = randrange(1, 100)
    h = randrange(1, 100)
    return Detection(0, l, t, l + w, t + h, 0.9, 7)