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中shapefile转换geojson的示例

shapefile转换geojson import shapefile import codecs from json import dumps # read the shapefi...

django将图片上传数据库后在前端显式的方法

1、使用ImageField先安装pillow模块 pip install pillow 2、在app的models中设置 class Image(models.Model):...

python cs架构实现简单文件传输

python cs架构实现简单文件传输

本文为大家分享了python cs架构实现简单文件的传输代码,供大家参考,具体内容如下 要实现简单文件的传输我们必须考虑这些问题: 1.什么是c/s架构? 顾名思义,就是客户端端/服务器...

Python基础教程之利用期物处理并发

前言 抨击线程的往往是系统程序员,他们考虑的使用场景对一般的应用程序员来说,也许一生都不会遇到……应用程序员遇到的使用场景,99% 的情况下只需知道如何派生一堆独立的线程,然后用队列收集...