视频分帧在图像处理中是一个非常常见的问题,在这里博主希望能够以简洁的代码给大家提供帮助。
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()
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()