Ask Your Question
1

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

asked 2016-09-02 00:39:11 -0600

littletom gravatar image

updated 2018-09-30 05:19:38 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-09-02 01:28:23 -0600

supertramp-sid gravatar image

updated 2016-09-09 08:30:53 -0600

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
edit flag offensive delete link more

Comments

2

Although I've figured it out,thank you.

littletom gravatar imagelittletom ( 2016-09-02 01:30:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-02 00:39:11 -0600

Seen: 19,406 times

Last updated: Sep 09 '16