コード例 #1
0
ファイル: end2end_test_caffe.py プロジェクト: wulongyuan/TPN
def show_tracks(vid_proto, track_proto):
    for frame in vid_proto['frames']:
        img = imread(frame_path_at(vid_proto, frame['frame']))
        boxes = [track_box_at_frame(tracklet, frame['frame']) \
                for tracklet in track_proto['tracks']]
        tracked = add_bbox(img, boxes, None, None, 2)
        cv2.imshow('tracks', tracked)
        if cv2.waitKey(0) == ord('q'):
            cv2.destroyAllWindows()
            sys.exit(0)
    cv2.destroyAllWindows()
コード例 #2
0
ファイル: tpn_train.py プロジェクト: wulongyuan/TPN
def show_track_res(track_res, vid_proto):
    cv2.namedWindow('tracks')
    for frame_res in track_res:
        if frame_res['frame'] == -1: break
        frame = frame_res['frame']
        img = imread(frame_path_at(vid_proto, frame))
        boxes = frame_res['roi'].tolist()
        tracked = add_bbox(img, boxes, None, None, 2)
        cv2.imshow('tracks', tracked)
        if cv2.waitKey(0) == ord('q'):
            cv2.destroyAllWindows()
            sys.exit(0)
    cv2.destroyAllWindows()
コード例 #3
0
    for frame in vid_proto['frames']:
        det_file = os.path.join(
            args.det_root, "{}.mat".format(os.path.splitext(frame['path'])[0]))
        det = sio.loadmat(det_file)
        frame_idx = frame['frame']
        img = imread(frame_path_at(vid_proto, frame_idx))
        boxes = det['boxes'][:, cls_index, :].astype('single')
        scores = det['zs'][:, cls_index].astype('single')
        if args.nms:
            keep = nms(np.hstack((boxes, scores[:, np.newaxis])), 0.3)
        else:
            keep = range(len(boxes))
        kept_boxes = [boxes[i, :] for i in keep]
        kept_scores = [scores[i] for i in keep]
        top_idx = np.argsort(np.asarray(kept_scores))[::-1]
        top_boxes = [kept_boxes[top_idx[i]] for i in \
            xrange(min(args.top_k, len(kept_boxes)))]
        top_scores = [kept_scores[top_idx[i]] for i in \
            xrange(min(args.top_k, len(kept_boxes)))]
        det_img = add_bbox(img, top_boxes, top_scores)
        cv2.imshow('detection', det_img)
        if cv2.waitKey(0) == ord('q'):
            cv2.destroyAllWindows()
            sys.exit(0)
        cv2.destroyAllWindows()
        if args.save_dir:
            imwrite(
                os.path.join(args.save_dir, "{:04d}.jpg".format(frame_idx)),
                det_img)
コード例 #4
0
ファイル: show_nms_tracks.py プロジェクト: wulongyuan/TPN
 show_track_ids = []
 cur_colors = []
 cur_classes = []
 for track_id, (class_id,
                track) in enumerate(zip(kept_class, kept_tracks)):
     if frame_id in track['frame']:
         boxes.append(track[args.box_key][track['frame'] == frame_id][
             0, class_id, :].tolist())
         scores.append(track[args.score_key][track['frame'] == frame_id]
                       [0, class_id].tolist())
         cur_colors.append(colors[track_id])
         cur_classes.append(imagenet_vdet_classes[class_id])
         show_track_ids.append(track_id)
 tracked = add_bbox(img,
                    boxes,
                    classes=cur_classes,
                    scores=scores,
                    line_width=10)
 if args.save_dir:
     imwrite(os.path.join(args.save_dir, "{:04d}.jpg".format(frame_id)),
             tracked)
     idx += 1
     if idx >= len(vid_proto['frames']):
         break
     continue
 cv2.imshow('tracks', tracked)
 key = cv2.waitKey(0)
 if key == ord('q'):
     cv2.destroyAllWindows()
     sys.exit(0)
 elif key == ord('a'):
コード例 #5
0
ファイル: show_tracking.py プロジェクト: wulongyuan/TPN
 if not args.save_dir:
     cv2.namedWindow('tracks')
 if args.sample_tracks:
     tracks = sample_tracks(track_proto['tracks'], args.num_tracks)
 elif args.annot_file:
     annot_proto = proto_load(args.annot_file)
     tracks = positive_tracks(track_proto['tracks'], annot_proto,
                              args.overlap, args.box_key)
 else:
     tracks = track_proto['tracks']
 random.shuffle(tracks)
 for frame in vid_proto['frames']:
     img = imread(frame_path_at(vid_proto, frame['frame']))
     boxes = [track_box_at_frame(tracklet, frame['frame'], args.box_key) \
             for tracklet in tracks]
     tracked = add_bbox(img, boxes, None, colors, 2)
     if args.save_dir:
         if not os.path.isdir(args.save_dir):
             try:
                 os.makedirs(args.save_dir)
             except:
                 pass
         imwrite(
             os.path.join(args.save_dir,
                          "{:04d}.jpg".format(frame['frame'])), tracked)
     else:
         cv2.imshow('tracks', tracked)
         if cv2.waitKey(0) == ord('q'):
             cv2.destroyAllWindows()
             sys.exit(0)
 if not args.save_dir:
コード例 #6
0
ファイル: show_gt.py プロジェクト: LiuFang816/SALSTM_py_data
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('vid_file')
    parser.add_argument('annot_file')
    parser.add_argument('--save_dir', default=None)
    args = parser.parse_args()

    vid_proto = proto_load(args.vid_file)
    annot_proto = proto_load(args.annot_file)

    colors = unique_colors(len(annot_proto['annotations']))

    for frame in vid_proto['frames']:
        img = imread(frame_path_at(vid_proto, frame['frame']))
        boxes = [track_box_at_frame(tracklet, frame['frame']) \
                for tracklet in [annot['track'] for annot in annot_proto['annotations']]]
        tracked = add_bbox(img, boxes, None, 10)
        if args.save_dir:
            if not os.path.isdir(args.save_dir):
                os.makedirs(args.save_dir)
            imwrite(
                os.path.join(args.save_dir,
                             "{:04d}.jpg".format(frame['frame'])), tracked)
        else:
            cv2.imshow('tracks', tracked)
            if cv2.waitKey(0) == ord('q'):
                cv2.destroyAllWindows()
                sys.exit(0)
            cv2.destroyAllWindows()
コード例 #7
0
ファイル: show_gt.py プロジェクト: BenJamesbabala/T-CNN
import cv2

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('vid_file')
    parser.add_argument('annot_file')
    parser.add_argument('--save_dir', default=None)
    args = parser.parse_args()

    vid_proto = proto_load(args.vid_file)
    annot_proto = proto_load(args.annot_file)

    colors = unique_colors(len(annot_proto['annotations']))

    for frame in vid_proto['frames']:
        img = imread(frame_path_at(vid_proto, frame['frame']))
        boxes = [track_box_at_frame(tracklet, frame['frame']) \
                for tracklet in [annot['track'] for annot in annot_proto['annotations']]]
        tracked = add_bbox(img, boxes, None, 10)
        if args.save_dir:
            if not os.path.isdir(args.save_dir):
                os.makedirs(args.save_dir)
            imwrite(os.path.join(args.save_dir, "{:04d}.jpg".format(frame['frame'])),
                    tracked)
        else:
            cv2.imshow('tracks', tracked)
            if cv2.waitKey(0) == ord('q'):
                cv2.destroyAllWindows()
                sys.exit(0)
            cv2.destroyAllWindows()