python 图片中查找子图片


import aircv as ac
import pyautogui

def matchImg(imgsrc, imgobj, confidencevalue=0.5): # imgsrc=原始图像,imgobj=待查找的图片
imsrc = ac.imread(imgsrc)
imobj = ac.imread(imgobj)

match_result = ac.find_template(imsrc, imobj,confidencevalue) # {'confidence': 0.5435812473297119, 'rectangle': ((394, 384), (394, 416), (450, 384), (450, 416)), 'result': (422.0, 400.0)}
if match_result is not None:
match_result['shape'] = (imsrc.shape[1], imsrc.shape[0]) # 0为高,1为宽

return match_result

imgsrc = "b.png"
imgobj = "a.png"
match_result = matchImg(imgsrc, imgobj)
print(match_result)

猜你喜欢

转载自www.cnblogs.com/niuniuc/p/12536706.html