Converting multi-dimensional array to a tuple in python -


i getting frame data web cam in form of rgb values.

import numpy np     frame = get_video() print np.shape(frame) 

the output (480, 640, 3). want construct image these values. so, want use

im = image.new("rgb", (480, 640),frame) 

but, here third argument takes tuple. error

systemerror: new style getargs format argument not tuple 

so, question best way convert frame data tuple, can construct image.

i assuming here importing class image pil.

the documentation image.new(), accessed console command image.new? is:

in [3]: image.new?
type: function
base class:
string form:
namespace: interactive
file: /usr/lib/python2.7/dist-packages/pil/image.py
definition: image.new(mode, size, color=0)
docstring: create new image

the third parameter rgb color, such (255,255,255), fill hole image. can't initialize individual pixels function.

i assuming frame 3d array. output suggests, it's 480 lines , 640 rows of rgb tuples.

i don't know if there simpler way this, set pixel values putpixel() function, like:

im = image.new( "rgb", (480, 640), (0, 0, 0) ) #initialize 480:640 black image in range(480):     j in range(640):         im.putpixel( (i, j), tuple(frame[i][j]) ) 

always check docstring via console, saves lot of time. recommend using ipython console.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -