diff --git a/demo/demo.mp4 b/demo/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6c06d15d941c640e15785e0416818181313d83b7 Binary files /dev/null and b/demo/demo.mp4 differ diff --git a/demo/video_demo.py b/demo/video_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..661130b42c56f64707c4c79749f10e488be02ef0 --- /dev/null +++ b/demo/video_demo.py @@ -0,0 +1,60 @@ +import argparse + +import cv2 +import mmcv + +from mmdet.apis import inference_detector, init_detector + + +def parse_args(): + parser = argparse.ArgumentParser(description='MMDetection video demo') + parser.add_argument('video', help='Video file') + parser.add_argument('config', help='Config file') + parser.add_argument('checkpoint', help='Checkpoint file') + parser.add_argument( + '--device', default='cuda:0', help='Device used for inference') + parser.add_argument( + '--score-thr', type=float, default=0.3, help='Bbox score threshold') + parser.add_argument('--out', type=str, help='Output video file') + parser.add_argument('--show', action='store_true', help='Show video') + parser.add_argument( + '--wait-time', + type=float, + default=1, + help='The interval of show (s), 0 is block') + args = parser.parse_args() + return args + + +def main(): + args = parse_args() + assert args.out or args.show, \ + ('Please specify at least one operation (save/show the ' + 'video) with the argument "--out" or "--show"') + + model = init_detector(args.config, args.checkpoint, device=args.device) + + video_reader = mmcv.VideoReader(args.video) + video_writer = None + if args.out: + fourcc = cv2.VideoWriter_fourcc(*'mp4v') + video_writer = cv2.VideoWriter( + args.out, fourcc, video_reader.fps, + (video_reader.width, video_reader.height)) + + for frame in mmcv.track_iter_progress(video_reader): + result = inference_detector(model, frame) + frame = model.show_result(frame, result, score_thr=args.score_thr) + if args.show: + cv2.namedWindow('video', 0) + mmcv.imshow(frame, 'video', args.wait_time) + if args.out: + video_writer.write(frame) + + if video_writer: + video_writer.release() + cv2.destroyAllWindows() + + +if __name__ == '__main__': + main() diff --git a/docs/1_exist_data_model.md b/docs/1_exist_data_model.md index 0b06126fede68943c8bd7fb58b032f8b6de98a27..4a3ab999c1aa1fd7db42e1dcfcf8f348e0f11067 100644 --- a/docs/1_exist_data_model.md +++ b/docs/1_exist_data_model.md @@ -91,7 +91,7 @@ asyncio.run(main()) ### Demos -We also provide two demo scripts, implemented with high-level APIs and supporting functionality codes. +We also provide three demo scripts, implemented with high-level APIs and supporting functionality codes. Source codes are available [here](https://github.com/open-mmlab/mmdetection/tree/master/demo). #### Image demo @@ -111,7 +111,7 @@ Examples: ```shell python demo/image_demo.py demo/demo.jpg \ - configs/faster_rcnn_r50_fpn_1x_coco.py \ + configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ --device cpu ``` @@ -133,10 +133,35 @@ Examples: ```shell python demo/webcam_demo.py \ - configs/faster_rcnn_r50_fpn_1x_coco.py \ + configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth ``` +#### Video demo + +This script performs inference on a video. + +```shell +python demo/video_demo.py \ + ${VIDEO_FILE} \ + ${CONFIG_FILE} \ + ${CHECKPOINT_FILE} \ + [--device ${GPU_ID}] \ + [--score-thr ${SCORE_THR}] \ + [--out ${OUT_FILE}] \ + [--show] \ + [--wait-time ${WAIT_TIME}] +``` + +Examples: + +```shell +python demo/video_demo.py demo/demo.mp4 \ + configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \ + checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ + --out result.mp4 +``` + ## Test existing models on standard datasets To evaluate a model's accuracy, one usually tests the model on some standard datasets.