[英]cv2 video not showing using imshow, while being processed
有一个视频,正在处理中。 该过程可以在控制台中看到为帧处理 1/1000、2/1000 等。output 视频已经完成,但是如果我想在运行过程中查看结果,有一个灰屏 - 没有响应(程序截图运行)。
加载movi的代码:
input_movie = cv2.VideoCapture(r"test.mp4")
length = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
output_movie = cv2.VideoWriter('myoutput_01.avi', fourcc, 29.97, (480, 360))
在运行期间显示视频的代码:
cv2.imshow('Video', frame)
怎么看过程?
更新
我使用了 while 循环,我只是不想包含太多代码。 但这里是:
while True:
ret, frame = input_movie.read()
frame_number += 1
if not ret:
break
cv2.imshow('Video', frame)
rgb_frame = frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame)
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
看看你在这里有什么; 我不确定您是否了解如何在 opencv-python 中处理视频。
input_movie = cv2.VideoCapture(r"test.mp4")
这里将打开 test.mp4 视频(也许你明白)。 但是现在,您需要告诉 opencv 使用一段时间 function 读取该视频的每一帧并读取input_movie
一般来说,我们是这样做的:
input_movie = cv2.VideoCapture(r"test.mp4")
while (input_movie.isOpened()):
ret, frame = input_movie.read() # here we extract the frame
cv2.imshow('Video',frame) # here we display it
if cv2.waitKey(1) & 0xFF == ord('q'): # by press 'q' you quit the process
break
input_movie.release() # remove input_movie from memory
cv2.destroyAllWindows() # destroy all opencv windows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.