Note that I have read answers to questions of the same issue but no one is like mine.
I loaded a picture in OpenCV and displayed it. Everything is fine.
Now I want to set black pixels to blue, so I run this:
for i in range(image.shape[0]):
for j in range(image.shape[1]):
if image[i,j,0]==0 and image[i,j,1]==0 and image[i,j,2]==0:
image[i,j,0]=255
I got this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Nota Bene:
The notations
image[i,j,0],image[i,j,1]andimage[i,j,2]underline the value of the channel of a pixel (BGR= Blue Green Red) so it is not an array as this error message says. So strange if Python does not understand itself.When I run
print image[i,j,x], withx=0,1,2 I get normal behavior for random values ofiandj. That is, I get the values of those 3 channels correctly.