Forums

PIL Image error :-(

I am coding a (fake) exposure program, and came across this error:

=============== RESTART: /home/pi/Documents/Python/camera2.py ===============
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Exposing... Done
Processing... Done
Converting... Done
Saving...

Traceback (most recent call last):
File "/home/pi/Documents/Python/camera2.py", line 67, in <module>
finishedimg.putdata(outimage)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1617, in putdata
self.im.putdata(data, scale, offset)
SystemError: new style getargs format but argument is not a tuple

I can't get my head around this, I have googled it and can't find anything much related to this, so would like some help.

My code:

exposure = 3

print'Exposing...',
images = []
for i in xrange(exposure):
    images.append(getpic())
print'Done'

image = images[0]
outimage = [[0, 0, 0]]*len(image.getdata())

print'Processing...',
for image in images:
    for i in xrange(len(image.getdata())):
        pixel = image.getdata()[i]
        try:
            outimage[i] = [0, 0, 0, 0]
        except:
            print i
        for b in xrange(3):
            value = pixel[b]
            outimage[i][b] += value
            if outimage[i][b] > 255:
                outimage[i][b] = 255
print'Done'

print'Converting...',
outimagenew = []
for pixel in outimage:
    outimagenew.append(tuple(pixel))
outimagenew = tuple(outimagenew)
print'Done'

print'Saving...',
finishedimg = Image.new('RGB', (720, 1280))
finishedimg.putdata(outimage)
finishedimg.save('/home/pi/Documents/Python/Captures2/finished.jpg')
print'Done'

Thanks!

Sorry, fixed it. I edited outimage[i] = [0, 0, 0, 0] to read outimage[i] = [0, 0, 0], and finishedimg.putdata(outimage) to read finishedimg.putdata(outimagenew). My fault. You may now delete this post