First time here? Check out the FAQ!

Ask Your Question
1

How to save multiple images in a "for" loop?

asked Sep 2 '16

littletom gravatar image

updated Sep 30 '18

I need to save a lot of pictures in a "for" loop.I use python,imported opencv3.0.0 library already.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Sep 2 '16

supertramp-sid gravatar image

updated Sep 9 '16

Assuming that you want to save files from a video recording, you can do this :

import cv2

vid = cv2.VideoCapture("video.mp4")
d = 0
ret, frame = vid.read()

while ret:
    ret, frame = vid.read()
    filename = "images/file_%d.jpg"%d
    cv2.imwrite(filename, frame)
    d+=1
Preview: (hide)

Comments

2

Although I've figured it out,thank you.

littletom gravatar imagelittletom (Sep 2 '16)edit

Question Tools

1 follower

Stats

Asked: Sep 2 '16

Seen: 19,576 times

Last updated: Sep 09 '16