1. 程式人生 > >python opencv提取關鍵幀

python opencv提取關鍵幀

import cv2

cap = cv2.VideoCapture('/home/lw/3661.mp4')

fps = cap.get(cv2.CAP_PROP_FPS)  # 獲取幀速
print fps
fWidth = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
print fWidth

fHeight = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
print fHeight

fNums = cap.get(cv2.CAP_PROP_FRAME_COUNT)

success,frame = cap.read()
i = 0
while success :    
    success,arr = cv2.imencode('.jpg', frame)
    a = arr.tostring()
    fp = open('/home/lw/aa/test'+str(i)+'.jpg', 'wb')
    fp.write(a)
    fp.close()
    i = i + 1
    success,frame = cap.read()
cap.release()