Keep making same mistake.
Horizontal lines is always result. Trying to display random points.
import cv2 as cv, numpy as np, random
blank = np.ones((300,300), np.uint8) * 255
X, Y = [], []
for i in np.arange(1,300,1):
X.append(random.randrange(1,300))
for i in np.arange(1,300,1):
Y.append(random.randrange(1,300))
XY = np.column_stack((np.asarray(X),np.asarray(Y)))
# change values of Vertex index to black.
blank[XY] = 1
cv.imshow('', blank)
cv.waitKey(0)
cv.destroyAllWindows()
Random array of pixels is intended.
CodePudding user response:
Everything is okay in your code, just require some change which is that we have to pass X, Y
instead of XY
.
blank[X, Y] = 1
So basically index operater []
requires a tuple so we can create our own using XY
.
# tuple(XY.transpose())
blank[tuple(XY.transpose())] = 1
import cv2 as cv, numpy as np, random
blank = np.ones((300,300), np.uint8) * 255
X, Y = [], []
for i in np.arange(1,300,1):
X.append(random.randrange(1,300))
for i in np.arange(1,300,1):
Y.append(random.randrange(1,300))
# XY = np.column_stack((np.asarray(X),np.asarray(Y)))
# change values of Vertex index to black.
blank[X, Y] = 1
cv.imshow('', blank)
cv.waitKey(0)
cv.destroyAllWindows()
OUTPUT: