From 7185bcec9057a093dd2363d99f8c4451f9e05b6a Mon Sep 17 00:00:00 2001 From: Rui-R <53163198+Rui-R@users.noreply.github.com> Date: Mon, 25 Jan 2021 10:41:33 +0800 Subject: [PATCH] Update MBNetModel.py change demo_video_MBNet for robust video detection. --- keras_MBNet/model/MBNetModel.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/keras_MBNet/model/MBNetModel.py b/keras_MBNet/model/MBNetModel.py index b8b9a23..241e503 100644 --- a/keras_MBNet/model/MBNetModel.py +++ b/keras_MBNet/model/MBNetModel.py @@ -230,19 +230,24 @@ def demo_video_MBNet(self, opt, test_file, lwir_test_file, weight_path): print('loaded lwir video from :' + lwir_test_file) vid = cv2.VideoCapture(test_file) - lwir_vid = cv2.VideoCapture(lwir_test_file) + fps = vid.get(cv2.CAP_PROP_FPS) + frame_all = vid.get(cv2.CAP_PROP_FRAME_COUNT) + print("[INFO] 视频FPS: {}".format(fps)) + print("[INFO] 视频总帧数: {}".format(frame_all)) + print("[INFO] 视频时长: {}s".format(frame_all/fps)) + frame_width = int(vid.get(3)) frame_height = int(vid.get(4)) - out_vid = cv2.VideoWriter('output_vid.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, + out_vid = cv2.VideoWriter('./output_videos/output_visible.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, (frame_width, frame_height)) - out_lwir_vid = cv2.VideoWriter('output_lwir_vid.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, + out_lwir_vid = cv2.VideoWriter('./output_videos/output_lwir.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, (frame_width, frame_height)) idx = 0 - - while True: + + while idx < frame_all: #防止越界 ret , frame = vid.read() lwir_ret, lwir_frame = lwir_vid.read() @@ -262,6 +267,7 @@ def demo_video_MBNet(self, opt, test_file, lwir_test_file, weight_path): out_vid.write(frame) out_lwir_vid.write(lwir_frame) + idx += 1 vid.release() lwir_vid.release()