Cameron F.
Cameron F.

Reputation: 213

Saving Images in a For Loop with Different Names Without Using a User Function (sckit - Python)

I am looking to save a set of processed images into a folder within my directory. There have been similar questions (e.g., Save images in loop with different names), however they either use user defined functions or rely on the images being part of a video that they decompose frame-by-frame and then save.

Using another question, I was looking to accomplish something similar (OpenCV - Saving images to a particular folder of choice), but within a loop structure

import cv2
import os

path = 'D:\Results'

for i in range(len(images))
     cv2.imwrite(os.path.join(path, 'waka.tif'), )
     cv2.waitKey(0)

But am unsure of what to put in place of the waka title the previous questioner gave the image.

Upvotes: 0

Views: 3731

Answers (2)

Alefunxo
Alefunxo

Reputation: 58

you can put 'waka_{}.tif'.format(i) this will save one image every time it goes through the loop and you will then have waka_1.tif, waka_2.tif, etc.

Upvotes: 2

mee
mee

Reputation: 708

you can try this:

import cv2
import os

path = 'D:\Results'

for i in range(len(images))
     cv2.imwrite(os.path.join(path, 'waka_'+str(i)+'.tif'), )
     cv2.waitKey(0)

Upvotes: 1

Related Questions