Python Forum

Full Version: Image Stacking Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good Morning,

I'm new Python so please bear with me.
I am using the np.vstack funtion from numpy to vertically stack some images on a raspberry pi.

There is a line in the code:
 
imgs_comb = np.vstack((np.asarray(i.resize(min_shape)) for i in imgs)) 
I am trying to break down the for loop so that I can put a small delay in between the stacking of each image:

for i in imgs:
     imgs_comb = np.vstack((np.asarray(i.resize(min_shape))))
     time.sleep(1)
The code falls over when I then try and save the overall image.

Thanks for your help in advance,
Rhys
Hello,
please post the full error traceback message in error tags, so we can get more details about the issue.
Here's the error:
Maximum supported image dimension is 65500 pixels
Traceback (most recent call last):
File "/home/pi/Documents/Rentokil CFC/Dev/Image Attach Vertical Stack.py", line 43, in <module>
imgs_comb.save('/home/pi/Documents/Rentokil CFC/Dev/trial.jpg')
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1728, in save
save_handler(self, fp, filename)
File "/usr/lib/python3/dist-packages/PIL/JpegImagePlugin.py", line 734, in _save
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
File "/usr/lib/python3/dist-packages/PIL/ImageFile.py", line 495, in _save
raise IOError("encoder error %d when writing image file" % s)
OSError: encoder error -2 when writing image file

So it's trying to say that image is too big.
Not sure why it works OK with the first line of code.
Is the way I'm breaking down the for loop creating another dimension maybe?

Rhys