bg_img = cv2.imread(bg_img)
match_img = cv2.imread(match_img)
graybg = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
graymat = cv2.cvtColor(match_img, cv2.COLOR_BGR2GRAY)
#输出两幅图的差值的绝对值,意为寻找两幅图的差异区域
result = cv2.absdiff(graybg, graymat)
ret, thresh = cv2.threshold(result, 35, 255, cv2.THRESH_BINARY_INV) #黑白二值反转:大于该阈值置0,为黑;大于该阈值置255,为白
for y in range(160):
count = []
for x in range(260):
if thresh[y][x] == 0:
count.append(x)
if len(count) >= 20:
return count[0] - 10