예제 #1
0
def play(mot_folder, image_folder):
    sequence_name = [
        os.path.basename(s) for s in glob.glob(os.path.join(image_folder, "*"))
    ]
    for s in sequence_name:
        print("{} :================".format(s))
        s_image_folder = os.path.join(image_folder, s)
        s_mot_file = os.path.join(mot_folder, s + ".txt")
        if not os.path.exists(s_mot_file):
            print("cannot find {}".format(s_mot_file))
            continue

        data = pd.read_csv(s_mot_file, header=None)
        data_group = data.groupby(by=[0])

        frame_index_list = sorted(data_group.groups.keys())
        for frame_index in frame_index_list:
            print(frame_index)
            value = data.iloc[data_group.groups[frame_index], :].values

            ids = value[:, [1]].astype(int).squeeze(1)
            bboxes = value[:, [2, 3, 4, 5]]
            conf = value[:, [6]].squeeze(1)

            image_path = os.path.join(s_image_folder,
                                      "img{0:05}.jpg".format(frame_index))
            image = cv2.imread(image_path)
            if image is None:
                print("cannot find {}".format(image_path))

            bboxes[:, [2, 3]] += bboxes[:, [0, 1]]

            if image is None:
                continue
            bboxes[:, [0, 2]] = np.clip(bboxes[:, [0, 2]],
                                        a_min=0,
                                        a_max=image.shape[1])
            bboxes[:, [1, 3]] = np.clip(bboxes[:, [1, 3]],
                                        a_min=0,
                                        a_max=image.shape[0])
            bboxes_valid = (bboxes[:, [2, 3]] -
                            bboxes[:, [0, 1]] == 0).sum(axis=1) == 0
            bboxes = bboxes[bboxes_valid, :]

            colors = [DrawBoxes.get_random_color(i) for i in ids[bboxes_valid]]
            texts = ["{}".format(round(c, 2)) for c in conf]

            DrawBoxes.cv_draw_mult_boxes(image,
                                         bboxes,
                                         colors=colors,
                                         texts=texts)

            cv2.imshow("result", image)
            cv2.waitKey(-1)
예제 #2
0
파일: test_ua.py 프로젝트: shijieS/DMMN
def test():
    net.eval()

    data_loader = data.DataLoader(dataset=dataset,
                                  batch_size=1,
                                  num_workers=1,
                                  shuffle=True,
                                  collate_fn=collate_fn,
                                  pin_memory=False)

    batch_iterator = iter(data_loader)
    for index in range(len(data_loader)):
        frames_1, target_1, times_1 = next(batch_iterator)
        # if index % 32 != 0:
        #     continue

        if frames_1 is None:
            continue

        if args.cuda:
            frames_1 = Variable(frames_1.cuda())
            with torch.no_grad():
                target_1 = [[Variable(target[j].cuda()) for j in range(4)]
                            for target in target_1]
                times_1 = Variable(times_1.cuda())
        else:
            pass

        output_params, output_p_c, output_p_e, output_boxes = net(
            frames_1, times_1)
        batch_boxes = []
        batch_num = output_params.shape[0]
        class_num = output_params.size(1)
        result = []
        for b in range(batch_num):
            boxes = []

            for c in range(1, class_num):
                mask = output_p_c[b, c, :] > 0
                result += [[
                    output_params[b, c, mask, :].data,
                    output_p_c[b, c, mask].data, output_p_e[b, c, :,
                                                            mask].data,
                    output_boxes[b, c, :, mask, :].data, c
                ]]

        # draw something on the image
        for r in result:
            all_motion_parameters = r[0]
            all_p_c = r[1]
            all_p_e = r[2]
            all_bboxes_ = r[3]
            all_c = r[4]

            # draw boxes
            for i in range(frames_1.shape[2]):
                frame = TypeConverter.image_tensor_2_cv_gpu(frames_1[0, :,
                                                                     i, :, :])
                all_bboxes = TypeConverter.tensor_2_numpy_gpu(all_bboxes_)
                frame = cv2.resize(frame, (1920, 960))
                h, w, c = frame.shape
                all_bboxes[:, :, [0, 2]] *= w
                all_bboxes[:, :, [1, 3]] *= h

                colors = []
                texts = []
                for c, e in zip(all_p_c, all_p_e[i, :]):
                    if e > 0.5:
                        colors += [(0, 0, 255)]
                        texts += ["{:.2}, {:.2}".format(c, e)]
                    else:
                        colors += [(255, 255, 255)]
                        texts += ["NO-"]

                DrawBoxes.cv_draw_mult_boxes_with_track(
                    frame, all_bboxes, i, colors, texts)

                if cfg['debug_save_image']:
                    if not os.path.exists(cfg["image_save_folder"]):
                        os.makedirs(cfg["image_save_folder"])
                    cv2.imshow("result", frame)
                    cv2.waitKey(10)
                    cv2.imwrite(
                        os.path.join(
                            cfg["image_save_folder"],
                            "{}-{}-{}.png".format(index, result.index(r), i)),
                        frame)
예제 #3
0
        if self.transform is not None:
            out = self.transform(out)

        return out


if __name__ == "__main__":
    from draw_utils.DrawBoxes import DrawBoxes

    dataset = MOT17TrainDataset()
    for index in range(0, len(dataset), 32):
        frame_indexes, track_ids, bboxes, frames, times = dataset[index]

        if frame_indexes is None:
            continue

        for i, frame in enumerate(frames):
            h, w, _ = frame.shape
            label_map = {v: k for k, v in config["label_map"].items()}

            texts = [label_map[c] for c in bboxes[i, :, -1].astype(int)]
            DrawBoxes.cv_draw_mult_boxes_with_track(
                frame,
                bboxes[:, :, :4] * np.array([w, h, w, h]),
                i,
                texts=texts,
                exists=bboxes[:, :, -2].astype(int))
            cv2.imshow("result", frame)
            cv2.waitKey(25)
예제 #4
0
        return out


if __name__ == "__main__":
    from draw_utils.DrawBoxes import DrawBoxes

    dataset = AmotTrainDataset()
    # dataset.get_mean_pixel()
    for index in range(544, len(dataset), 32):
        frame_indexes, track_ids, bboxes, frames, times = dataset[index]

        if frame_indexes is None:
            continue

        for i, frame in enumerate(frames):
            h, w, _ = frame.shape
            label_map = {v: k for k, v in config["label_map"].items()}

            texts = ['' if c==0 else label_map[c] for c in bboxes[i, :, -1].astype(int)]
            colors = []
            for t in track_ids:
                colors += [DrawBoxes.get_random_color(t)]
            DrawBoxes.cv_draw_mult_boxes_with_track(frame,
                                                    bboxes[:, :, :4]*np.array([w, h, w, h]),
                                                    i,
                                                    colors=colors,
                                                    texts=texts,
                                                    exists=bboxes[:, :, -2].astype(int))
            cv2.imshow("result", frame)
            cv2.waitKey(25)
예제 #5
0
 def draw(self, frames, track_id):
     # print(self.category)
     DrawBoxes.draw_node_result(frames, self.boxes, self.p_c, self.p_e,
                                Config.category_map[self.category], track_id)
     return frames