-2

I have a file where there are 600 images, I want to convert them at once to greyscale

images = [cv2.imread(file) for file in glob.glob("/Users/ad/Desktop/theimages/*.png")] 

images_grey=[]

for i in range [0,600]:
    images_grey.append (cv2.cvtColor(images[i], cv2.COLOR_BGR2GRAY) )

print(images_grey)

but I get

TypeError: 'type' object is not subscriptable
desertnaut
  • 46,107
  • 19
  • 109
  • 140
Starter
  • 9
  • 4
  • I'm guessing you have a **directory** with 600 images, rather than a file. Do you really need to read them all into memory at once and make 600x the demand on your RAM? Or would it be more sensible to read, process and save them one-at-a-time? Do you really need to read them in colour, taking 3x the necessary RAM and then make a greyscale for 4x the RAM demand? Wouldn't it be better to just read them in greyscale with `cv2.IMREAD_GRAYSCALE`? In total, you have made 2,400x the necessary demand on RAM. – Mark Setchell Sep 12 '20 at 20:18

1 Answers1

1

Your for loop should be

for i in range(0, 600):

instead of using [ brackets

mazore
  • 874
  • 3
  • 9