Hi OpenCV or Numpy Gurus,
I've been searching to an answer to this, but I'm surprised to not find it here or elsewhere...
I have a black image, and I want to replace a list of pixels (quite a large list) with a certain value. In the future, the "certain value" will be a list of values, but for the moment, let's keep it simple.
Simplifying even further, I just use a 2-d array of single numbers below, instead of RGB values...
So, this fairly inefficient approach works for this sort of thing:
a = np.zeros((5, 5,1))
for i in np.asarray( ([2,3],[3,4]) ):
a[i[0], i[1]] = 20
I was hoping there was a way to use np.put
on a two dimensional array, where I don't rely on a python loop.
Now I had the suggestion that I could use
a[ ([2,3],[3,4]) = 20
However I notice when I use this approach in my real OpenCV problem it does not work. This very inefficient approach does:
coords_list = ([3,5],[55,60],[25,90])
black_image =np.zeros((480,640,3))
for i in coords_list:
black_image[i[1],i[0]] = [255,255,255]
I expect this is a simple question to many out there.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…