import aircv as ac import pyautogui
# imgsrc=原始图像,imgobj=待查找的图片 def matchImg(imgsrc, imgobj, confidencevalue=0.5): imsrc = ac.imread(imgsrc) imobj = ac.imread(imgobj)
#返回结果例子: # {'confidence': 0.5435812473297119, 'rectangle': ((394, 384), (394, 416), (450, 384), (450, 416)), 'result': (422.0, 400.0)} match_result = ac.find_template(imsrc, imobj,confidencevalue) 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)
缺啥装啥, pip install opencv-python 什么的~
|