From 66449a507e4b8755d4915d351e64a73136bd04b2 Mon Sep 17 00:00:00 2001 From: simon wu <wswday@sina.com> Date: Mon, 15 Jul 2019 19:31:40 +0800 Subject: [PATCH] Inference API support video (#995) * Inference API support video * Using mmcv.VideoReader to read video * modify --- GETTING_STARTED.md | 7 +++++++ mmdet/apis/inference.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 04b2d3a..9e9c6f0 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -63,6 +63,7 @@ Here is an example of building the model and test given images. ```python from mmdet.apis import init_detector, inference_detector, show_result +import mmcv config_file = 'configs/faster_rcnn_r50_fpn_1x.py' checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth' @@ -79,6 +80,12 @@ show_result(img, result, model.CLASSES) imgs = ['test1.jpg', 'test2.jpg'] for i, result in enumerate(inference_detector(model, imgs)): show_result(imgs[i], result, model.CLASSES, out_file='result_{}.jpg'.format(i)) + +# test a video and show the results +video = mmcv.VideoReader('video.mp4') +for frame in video: + result = inference_detector(model, frame) + show_result(frame, result, model.CLASSES, wait_time=1) ``` diff --git a/mmdet/apis/inference.py b/mmdet/apis/inference.py index c8c37ed..2d41e31 100644 --- a/mmdet/apis/inference.py +++ b/mmdet/apis/inference.py @@ -100,7 +100,12 @@ def _inference_generator(model, imgs, img_transform, device): # TODO: merge this method with the one in BaseDetector -def show_result(img, result, class_names, score_thr=0.3, out_file=None): +def show_result(img, + result, + class_names, + score_thr=0.3, + wait_time=0, + out_file=None): """Visualize the detection results on the image. Args: @@ -109,6 +114,7 @@ def show_result(img, result, class_names, score_thr=0.3, out_file=None): (bbox, segm) or just bbox. class_names (list[str] or tuple[str]): A list of class names. score_thr (float): The threshold to visualize the bboxes and masks. + wait_time (int): Value of waitKey param. out_file (str, optional): If specified, the visualization result will be written to the out file instead of shown in a window. """ @@ -140,4 +146,5 @@ def show_result(img, result, class_names, score_thr=0.3, out_file=None): class_names=class_names, score_thr=score_thr, show=out_file is None, + wait_time=wait_time, out_file=out_file) -- GitLab