简体   繁体   中英

Color a pixel in python opencv

I need to color a pixel in an image. I use opencv and python.
I tried img[x,y]=[255 255 255] to color a pixel(x,y) but it wont work :(

Is there is any mistake in this?
Can you suggest any method?

Thanks in advance.

img[x,y]=[255, 255, 255] is wrong because opencv img[a,b] is a matrics then you need to change x,y then you must use img[y,x]

actualy mistake in the order of x,y if you want to change color of point x,y use this >> img[y,x] = color

This works for me, just change it to load your own image:

import cv2

img = cv2.imread("C:\calibrate\chess\color001.jpg", cv2.CV_LOAD_IMAGE_COLOR);

## Make pixels row and column 300-400 black
img[300:400,300:400] = (0,0,0)

cv2.imshow('title',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

尝试使用255之间的逗号:

img[x,y]=[255, 255, 255]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM