未验证 提交 042c8033 编写于 作者: Z Zeyu Chen 提交者: GitHub

Recognize video resolution automatically for mask_detection demo

support show detection result, support get video resolution automatically
...@@ -53,8 +53,8 @@ python infer.py --models_dir=/path/to/models --img_paths=/path/to/images --video ...@@ -53,8 +53,8 @@ python infer.py --models_dir=/path/to/models --img_paths=/path/to/images --video
| models_dir | Yes|上述导出的模型路径 | | models_dir | Yes|上述导出的模型路径 |
| img_paths |img_paths/video_path 二选一|需要预测的图片目录 | | img_paths |img_paths/video_path 二选一|需要预测的图片目录 |
| video_path |img_paths/video_path 二选一|需要预测的视频目录| | video_path |img_paths/video_path 二选一|需要预测的视频目录|
| video_size |No|预测视频分辨率大小(w,h) | | use_camera |No|是否打开摄像头进行预测,默认为False |
| use_camera |No|是否打开摄像头进行预测 | | open_imshow |No|是否对视频的检测结果实时绘图,默认为False |
| use_gpu |No|是否GPU,默认为False| | use_gpu |No|是否GPU,默认为False|
说明: 说明:
......
...@@ -45,14 +45,14 @@ def parse_args(): ...@@ -45,14 +45,14 @@ def parse_args():
type=str, type=str,
default='', default='',
help='path of video.') help='path of video.')
parser.add_argument('--video_size',
type=tuple,
default=(1920, 1080),
help='size of video.')
parser.add_argument('--use_camera', parser.add_argument('--use_camera',
type=bool, type=bool,
default=False, default=False,
help='switch detect video or camera, default:video.') help='switch detect video or camera, default:video.')
parser.add_argument('--open_imshow',
type=bool,
default=False,
help='visualize video detection results in real time.')
parser.add_argument('--use_gpu', parser.add_argument('--use_gpu',
type=bool, type=bool,
default=False, default=False,
...@@ -229,7 +229,6 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False): ...@@ -229,7 +229,6 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
capture = cv2.VideoCapture(0) capture = cv2.VideoCapture(0)
else: else:
capture = cv2.VideoCapture(args.video_path) capture = cv2.VideoCapture(args.video_path)
detector = FaceDetector(model_dir=args.models_dir + '/pyramidbox_lite/', detector = FaceDetector(model_dir=args.models_dir + '/pyramidbox_lite/',
mean=[104.0, 177.0, 123.0], mean=[104.0, 177.0, 123.0],
scale=[0.007843, 0.007843, 0.007843], scale=[0.007843, 0.007843, 0.007843],
...@@ -246,9 +245,11 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False): ...@@ -246,9 +245,11 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
if not isExists: if not isExists:
os.makedirs(path) os.makedirs(path)
fps = 30 fps = 30
width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'mp4v') fourcc = cv2.VideoWriter_fourcc(*'mp4v')
writer = cv2.VideoWriter(os.path.join(path, 'result.mp4'), fourcc, fps, writer = cv2.VideoWriter(os.path.join(path, 'result.mp4'), fourcc, fps,
args.video_size) (width, height))
import time import time
start_time = time.time() start_time = time.time()
index = 0 index = 0
...@@ -263,8 +264,12 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False): ...@@ -263,8 +264,12 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
end_pre = time.time() end_pre = time.time()
im = VisualizeResult(frame, det_out) im = VisualizeResult(frame, det_out)
writer.write(im) writer.write(im)
if args.open_imshow:
cv2.imshow('Mask Detection', im)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
end_time = time.time() end_time = time.time()
print("include read time:", (end_time - start_time) / index) print("Average prediction time per frame:", (end_time - start_time) / index)
writer.release() writer.release()
...@@ -273,5 +278,5 @@ if __name__ == "__main__": ...@@ -273,5 +278,5 @@ if __name__ == "__main__":
print(args.models_dir) print(args.models_dir)
if args.img_paths != '': if args.img_paths != '':
predict_images(args) predict_images(args)
elif args.video_path != '': elif args.video_path != '' or args.use_camera:
predict_video(args) predict_video(args)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册