python 读取视频,处理后,实时计算帧数fps的方法

yipeiwu_com6年前Python基础

实时计算每秒的帧数

cap = cv2.VideoCapture("DJI_0008.MOV")
#cap = cv2.VideoCapture(0)
 
# Define the codec and create VideoWriter object
#fourcc = cv2.cv.FOURCC(*'XVID')
fourcc = cv2.VideoWriter_fourcc(*'XVID') 
out = cv2.VideoWriter('output1.avi', fourcc, 20, (1920, 1080))
 
num=0
 
while cap.isOpened():
  # get a frame
  rval, frame = cap.read()
  # save a frame
  if rval==True:
   # frame = cv2.flip(frame,0)
   	# Start time
    start = time.time()
    rclasses, rscores, rbboxes=process_image(frame) #换成自己调用的函数
    # End time
    end = time.time()
  	# Time elapsed
    seconds = end - start
    print( "Time taken : {0} seconds".format(seconds))
  	# Calculate frames per second
    fps = 1 / seconds;
    print( "Estimated frames per second : {0}".format(fps));
    #bboxes_draw_on_img(frame,rclasses,rscores,rbboxes)
    #print(rclasses)
    out.write(frame)
    num=num+1
    print(num)
    #fps = cap.get(cv2.CAP_PROP_FPS)
    #print("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps)) 
  else:
    break
  # show a frame
  cv2.imshow("capture", frame)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break
cap.release()
out.release()
cv2.destroyAllWindows()

以上这篇python 读取视频,处理后,实时计算帧数fps的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python反射的用法实例分析

本文实例讲述了Python反射的用法。分享给大家供大家参考,具体如下: 在做程序开发中,我们常常会遇到这样的需求:需要执行对象里的某个方法,或需要调用对象中的某个变量,但是由于种种原因我...

python 读取目录下csv文件并绘制曲线v111的方法

实例如下: # -*- coding: utf-8 -*- """ Spyder Editor This temporary script file is located here:...

初步介绍Python中的pydoc模块和distutils模块

pydoc Ka-Ping Yee 曾创建了一个相当著名的模块,名叫 pydoc (比较而言: pydoc 可以做到 perldoc 所能做的任何事,并且做得更好、更漂亮:-)。对于 P...

python求解数组中两个字符串的最小距离

题目: 给定一个数组 strs,其中的数据都是字符串,给定两个字符串 str1,str2。如果这两个字符串都在 strs数组中,就返回它们之间的最小距离;如果其中任何一个不在里面,则返...

通过Python实现自动填写调查问卷

通过Python实现自动填写调查问卷

0X00 前言 快开学了,看到空间里面各种求填写调查问卷的,我才想起来貌似我也还没做。对于这种无意义的问卷,我是不怎么感冒的,所以我打算使用”特技”来完成,也就是python,顺便重新复...