import cv2
bj='1.png'
hk='2.png'
def getTargetSliderPointX(bj, hk):
bgImg = cv2.imread(bj)
# 变成BRG格式来OpenCV处理
pointImg = cv2.imread(hk)
# 获取图像的边缘,Canny(图,阈值,阈值)
bgEdge = cv2.Canny(bgImg, 100, 200)
tpEdge = cv2.Canny(pointImg, 100, 200)
bgPic = cv2.cvtColor(bgEdge, cv2.COLOR_GRAY2RGB) # 颜色空间转换函数,cvtColor(图,要变成的格式)
ptPic = cv2.cvtColor(tpEdge, cv2.COLOR_GRAY2RGB)
# 缺口匹配
res = cv2.matchTemplate(bgPic, ptPic, cv2.TM_CCOEFF_NORMED)
# 寻找最优匹配
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
# 读取背景图片
#bgImg = Image.open(bj)
#bgImgSize = bgImg.size
# 根据图片真实与表面大小的比例进行缩放
x = max_loc[0]
# 删除下载的文件
os.unlink(bj)
os.unlink(hk)
print(x)
return x
getTargetSliderPointX(bj, hk)
© 允许规范转载