Skip to content
Snippets Groups Projects
Commit 66449a50 authored by simon wu's avatar simon wu Committed by Kai Chen
Browse files

Inference API support video (#995)

* Inference API support video

* Using mmcv.VideoReader to read video

* modify
parent 350fdd7a
No related branches found
No related tags found
No related merge requests found
......@@ -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)
```
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment