Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – incorrect colors when using opencv

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

OpenCV uses a BGR color format by default. Change your code to [0, 0, 255]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading