【问题标题】:cv2 video not showing using imshow, while being processedcv2 视频在处理时未使用 imshow 显示
【发布时间】:2021-03-23 20:21:46
【问题描述】:

有一个视频,正在处理中。该过程可以在控制台中看到为帧处理 1/1000、2/1000 等。输出视频已经完成,但是如果我想在运行期间查看结果,则会出现灰屏 - 无响应 (screenshot of program running )。

加载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)  

【问题讨论】:

  • 我不明白..你使用了while函数吗?并把一个 ret,frame = input_movie.read() 放进去?

标签: python cv2


【解决方案1】:

看看你在这里有什么;我不确定你是否理解如何在 opencv-python 中处理视频。

input_movie = cv2.VideoCapture(r"test.mp4")

此处将打开 test.mp4 视频(您可能已经理解)。 但是现在,您需要告诉 opencv 使用 while 函数读取该视频的每一帧并读取 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

更多信息在这里https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

【讨论】:

  • 好的,谢谢,使用 " if cv2.waitKey(1) & 0xFF == ord('q'): # by press 'q' you quit the process break" 有帮助!跨度>
猜你喜欢
  • 2020-10-18
  • 2020-11-01
  • 1970-01-01
  • 2013-06-09
  • 2019-06-07
  • 2021-07-17
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多