[英]Color a pixel in python opencv
I need to color a pixel in an image. 我需要为图像中的像素着色。 I use opencv and python.
我使用opencv和python。
I tried img[x,y]=[255 255 255]
to color a pixel(x,y)
but it wont work :( 我试过了
img[x,y]=[255 255 255]
给pixel(x,y)
上色pixel(x,y)
但是它不起作用:(
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] img[x,y]=[255, 255, 255]
是错误的,因为opencv img [a,b]是一个矩阵,则需要更改x,y,然后必须使用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
如果要更改点x,y的颜色,则实际上按x,y的顺序使用错误>>
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.