# coding: utf-8
from PIL import Image
def pic_detect(search_file, template_file, step=5):
img_0 = Image.open(search_file)
img_1 = Image.open(template_file)
img_mem_0 = img_0.load()
img_mem_1 = img_1.load()
rgb0 = [0, 0, 0]
rgb1 = img_1.getpixel((1, 1))
size_pic = img_0.size
size_pic_tpl = img_1.size
for y in range(size_pic[1] - size_pic_tpl[1]):
for x in range(size_pic[0] - size_pic_tpl[0]):
rgb0 = img_mem_0[x, y]
br = False
if rgb0 == rgb1:
for i in range(0, size_pic_tpl[1] - 1, int(size_pic_tpl[1] / step)):
for e in range(0, size_pic_tpl[0] - 1, int(size_pic_tpl[0] / step)):
if img_mem_0[x + e, y + i] == img_mem_1[e + 1, i + 1]:
pass
else:
br = True
break
if br:
break
if br == False:
# Попиксельная сверка для 100% совпадения, в большинстве случаев это излишне
# for ii in range(size_pic_tpl[1]-1):
# for ee in range(size_pic_tpl[0]-1):
# if img_mem_0[x+ee,y+ii] == img_mem_1[ee+1,ii+1]:
return (x, y)
print (pic_detect('note_full.png', 'note_part.png'))