7
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python OpenCVで動画をフレーム毎に画像保存

Last updated at Posted at 2020-03-29
import cv2
import os
 
def extractFrames(pathIn, pathOut):
    if not os.path.exists(pathOut):
        os.mkdir(pathOut)
 
    cap = cv2.VideoCapture(pathIn)
    count = 0
 
    while (cap.isOpened()):
 
        ret, frame = cap.read()
 
        if ret == True:
            cv2.imwrite(os.path.join(pathOut, "frame_{:06d}.jpg".format(count)), frame)
            count += 1
        else:
            break
 
    cap.release()
    cv2.destroyAllWindows()
 
def main():
    extractFrames('video.mp4', 'outputdir')
 
if __name__=="__main__":
    main()

7
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?