視頻分幀在圖像處理中是一個非常常見的問題,在這裏博主希望能夠以簡潔的代碼給大家提供幫助。
視頻連續分幀
import cv2
cap = cv2.VideoCapture('person.mp4')
count = 1
while True:
success,image = cap.read()
if success:
cv2.imwrite("fenzhen/frame%d.jpg" %count,image)
if cv2.waitKey(10) == 27:
break
count += 1
else:
break
cap.release()
cv2.destroyAllWindows()
視頻每隔3幀取1幀
import cv2
cap = cv2.VideoCapture('person.mp4')
count = 1
while True:
success,image = cap.read()
if success:
if count%3==1:
cv2.imwrite("fenzhen1/frame%d.jpg" %count,image)
if cv2.waitKey(10) == 27:
break
count += 1
else:
break
cap.release()
cv2.destroyAllWindows()