0

I want to open multiple images in a loop. I have named the images number wise(1,2,3...) and want to open that image through code. This is what i tried

for i in range(1,10):
    img=cv2.imread('i.jpg')
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
  • try `img = cv2.imread(str(i)+'.jpg')` – Sociopath Feb 25 '19 at 09:36
  • you should use `str.format` [here](https://pyformat.info/) is a quick guide on how to do that. an instant answer would be `'{}.jpg'.format(i)` but you should really take a look at `.format` as its very useful – Nullman Feb 25 '19 at 09:38

1 Answers1

-1

You need the i to be a string. So casting to string will solve it.

like this:

import cv2
for i in range(1,10):
    img = cv2.imread(str(i)+'.jpg') 
MEdwin
  • 2,940
  • 1
  • 14
  • 27