diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 04b2d3a04658c7d02cf0d765c67a76da76074d45..9e9c6f0c3b1a471a942595d98f5dd4987ff97f50 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 c8c37edcd1f9e00f23a0d32bbd2a0f4c367de041..2d41e317458edfb8e5f91d9fbe03f235bc3e578c 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)