import cv2
import numpy as np
image = cv2.imread('images1.png')
ss=[]
for x in range (0,260,1):
for y in range(0,190,1):
if image[y,x]==[0,0,0]:
image[y,x]=[0,255,162]
cv2.imshow("image",image)
cv2.waitKey(0)
Error:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
CodePudding user response:
you're trying to compare an array with another when you call img[y,x]==[0,0,0] you got a vector of 3 logicals (supose [True,True,True] or any other variation). You have to compress this to an unique logical: you can use .all() to that (black means that the cannel red ==0 , the blue==0 and green==0, so you need that the 3 vals to be True to enter the if)
so the solution will be to replace
if image[y,x]==[0,0,0]:
with
if (image[y,x]==[0,0,0]).all():
CodePudding user response:
If you want to do this fast, you don't want to do this with a loop – instead, use
into this: