I'm trying to randomly generate colored pixels in a white frame using opencv but the pixels are generated with the wrong color. Is there any way to fix this problem? this is my code:
import random
import cv2
img = cv2.imread("anhnen.png")
i=1
while i <= 200:
i = i 1
x = random.randint(0,479)
y = random.randint(0,479)
img[x][y] = [255,0,0]
cv2.imwrite('anh2.png', img)
Here is the picture after running the code image2
CodePudding user response:
OpenCV uses a BGR color format by default. Change your code to [0, 0, 255]
