使用opencv获取视频一半的帧

0 python opencv opencv3.0

有没有办法从opencv获取帧,但大约是视频的一半(例如,如果视频是10分钟,我想在5:00分钟保存一帧)。我已经在网上看到了一些东西,但每个人都只是一帧一帧地前进。感谢您的帮助

Ani*_*ich 5

我相信您正在寻找这样的东西:

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()
Run Code Online (Sandbox Code Playgroud)

你应该在变量 中得到半点框架frame