python opencv 把视频转为图片

it2026-04-15  1

 

import cv2 def getFrame(videoPath, svPath): cap = cv2.VideoCapture(videoPath) numFrame = 0 while True: if cap.grab(): flag, frame = cap.retrieve() if not flag: continue else: numFrame += 1 newPath = svPath + str(numFrame) + ".jpg" cv2.imencode('.jpg', frame)[1].tofile(newPath) if cv2.waitKey(10) == 27: break videoPath = './1.mp4' savePicturePath = './pic/' getFrame(videoPath,savePicturePath)

最新回复(0)