gpt4 book ai didi

python-2.7 - 视频Python的帧率

转载 作者:行者123 更新时间:2023-11-28 21:41:27 25 4
gpt4 key购买 nike

代码:

    import cv2
import numpy as np
import sys
import webcolors
import time

cam=cv2.VideoCapture('video2.avi')
_, fo = cam.read()
framei = cv2.cvtColor(fo, cv2.COLOR_BGR2GRAY)
bg_avg = np.float32(framei)
video_width = int(cam.get(3))
video_height = int(cam.get(4))
fr = int(cam.get(5))
print("frame rate of stored video:::",fr)

while(cam.isOpened):
f,img=cam.read()
start_fps=time.time()
.
.
.
k = cv2.waitKey(20)
if(k == 27):
break
endtime_fps=time.time()
diff_fps=endtime_fps-start_fps
print("Frame rate::",1/diff_fps)

每次迭代都会打印不同的帧率,例如:31.249936670193268、76.92300920661702、142.85290010558222、166.67212398172063、200.00495922941204、38.461 50460330851 ... 等一些值被重复了几次。现在存储视频的帧速率值为 25。那么读取它的实际帧速率是多少?

最佳答案

您可以使用以下代码获取 FPS(每秒帧数):

import cv2
cam = cv2.VideoCapture('video2.avi')
fps = cam.get(cv2.CAP_PROP_FPS)

关于python-2.7 - 视频Python的帧率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com