Skip to content

Commit 1e7b9b7

Browse files
authored
Update predict.py
1 parent 6074a5f commit 1e7b9b7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

predict.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@
7272
size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
7373
out = cv2.VideoWriter(video_save_path, fourcc, video_fps, size)
7474

75+
ref, frame = capture.read()
76+
if not ref:
77+
raise ValueError("未能正确读取摄像头(视频),请注意是否正确安装摄像头(是否正确填写视频路径)。")
78+
7579
fps = 0.0
7680
while(True):
7781
t1 = time.time()
7882
# 读取某一帧
79-
ref,frame=capture.read()
83+
ref, frame = capture.read()
84+
if not ref:
85+
break
8086
# 格式转变,BGRtoRGB
8187
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
8288
# 转变成Image
@@ -98,8 +104,12 @@
98104
if c==27:
99105
capture.release()
100106
break
107+
108+
print("Video Detection Done!")
101109
capture.release()
102-
out.release()
110+
if video_save_path!="":
111+
print("Save processed video to the path :" + video_save_path)
112+
out.release()
103113
cv2.destroyAllWindows()
104114

105115
elif mode == "fps":

0 commit comments

Comments
 (0)