Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

this is more a numpy, than an opencv problem.

your pixel , center_px = img[cx,cy] is a numpy array, and ORANGE is a plain tuple, let's simulate it:

>>> pixel = np.array([4,3,2],dtype=np.uint8)
>>> ORANGE = (0,127,255)
>>> pixel == ORANGE
array([False, False, False], dtype=bool)

as you can see, you get a whole array of True, False values, one for each channel.

the solution, as stated in the error msg, is to check if the comparison is False for all channels, like:

>>> (pixel == ORANGE).all()
False

so, your if-statement should be:

if ((center_px == ORANGE).all()):
        print "Orange"

this is more a numpy, than an opencv problem.

your pixel , center_px = img[cx,cy] is a numpy array, and ORANGE is a plain tuple, let's simulate it:

>>> pixel = np.array([4,3,2],dtype=np.uint8)
>>> ORANGE = (0,127,255)
>>> pixel == ORANGE
array([False, False, False], dtype=bool)

as you can see, you get a whole array of True, False values, one for each channel.

the solution, as stated in the error msg, is to check if the comparison is False True for all channels, like:

>>> (pixel == ORANGE).all()
False

so, your if-statement should be:

if ((center_px == ORANGE).all()):
        print "Orange"