python获取图片中某个像素的坐标
python获取图片中某个像素的坐标
模糊查询
from PIL import Image
def zhaose(pic,r1,g1,b1):
img = Image.open(pic)
pixels = img.load()
width, height = img.size
xy={};
xy['x']=0
xy['y']=0
for x in range(width):
for y in range(height):
r, g, b = pixels[x, y]
# in case your image has an alpha channel
# r, g, b, a = pixels[x, y]
if((r>=(r1-3) and r<=(r1+3)) and (g>=(g1-3) and g<=(g1+3)) and (b>=(b1-3) and b<=(b1+3))):
xy['x']=x
xy['y']=y
break;
return xy
myxy=zhaose('xiaoditu.jpg',221,204,153);
print(myxy)
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/