【发布时间】:2021-09-23 15:06:13
【问题描述】:
有没有办法从opencv中获取帧,但大约是视频的一半(例如,如果视频是10分钟,我想在5:00分钟保存一帧)。我已经在互联网上看到了一些东西,但每个人都只是逐帧进行。谢谢你的帮助
【问题讨论】:
标签: python opencv opencv3.0 opencv-python
有没有办法从opencv中获取帧,但大约是视频的一半(例如,如果视频是10分钟,我想在5:00分钟保存一帧)。我已经在互联网上看到了一些东西,但每个人都只是逐帧进行。谢谢你的帮助
【问题讨论】:
标签: python opencv opencv3.0 opencv-python
我相信您正在寻找这样的东西:
import cv2
# Read the Video (Change the filename as per your file)
cap = cv2.VideoCapture("video.mp4")
# Get the total number of frames
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
half_point = length//2 # Approximately half if number of frames are odd
# Set the reader to the given frame number (half_point)
cap.set(cv2.CAP_PROP_POS_FRAMES, half_point)
# Read the frame
ret, frame = cap.read()
# Release the file pointer
cap.release()
你应该得到变量frame中的半点帧。
【讨论】: