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)

 

posted @ 2022-08-16 00:01  newmiracle宇宙  阅读(1334)  评论(0编辑  收藏  举报