使用opencv获取视频一半的帧
Get Frame at half of video with opencv
有没有办法从 opencv 获取帧,但大约是视频的一半(例如,如果视频是 10 分钟,我想在 5:00 分钟保存一帧)。我已经在互联网上看到了一些东西,但每个人都只是一帧一帧地进行。感谢您的帮助
我相信您正在寻找这样的东西:
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
中得到半点框架。
有没有办法从 opencv 获取帧,但大约是视频的一半(例如,如果视频是 10 分钟,我想在 5:00 分钟保存一帧)。我已经在互联网上看到了一些东西,但每个人都只是一帧一帧地进行。感谢您的帮助
我相信您正在寻找这样的东西:
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
中得到半点框架。