[Tutor] Error in get pixel value in coordinate (x, y) using getPixel(x, y)

Alan Gauld alan.gauld at btinternet.com
Thu Aug 7 20:38:00 CEST 2014


On 07/08/14 12:49, Whees Northbee wrote:
> Please help me... I'm using python 2.7.6, numpy 1.8.1, opencv 2.4.9..
> I want to get pixel value in one number like 255 not each value like
> these R(190), G(23), B(45) from coordinate (x,y)...

What do you expect that number to look like? The pixels are represented 
by the 3 colours RGB. Are you wanting to just join the 3 bytes together 
to create an arbitrary number? Or do you think this number will mean 
something?

> I try these code
> m_samples[k][i][j]=getPixel(img,row,col)
>
> But get error:
> NameError: name 'getPixel' is not defined

So the getPixel function doesn't exist in your namespace.
Where do you think it comes from?

> If I change the format become:
> m_samples[k][i][j]=img.getPixel(row,col)
>
> Still error:
> AttributeError: 'numpy.ndarray' object has no attribute 'getpixel'

And its not a part of a numpy ndarray - what made you think it was?

Arte you just guessing? Or did you saee some code that
uses getPixel() somewhere?

> Please help me..

The tutor list is for those learning Python and its standard library. 
Numpy is not part of that, so your question is slightly off list. but 
your error looks so elementary that we may be able to help if you give 
us more information.

Also, please *always* send full error messages, not just the last line.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list