有没有办法从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()
Run Code Online (Sandbox Code Playgroud)
你应该在变量 中得到半点框架frame。
| 归档时间: |
|
| 查看次数: |
805 次 |
| 最近记录: |