废话不多说直接上源码
1 #获取有缺口的图片 2 bigImg = Imgdict[\'bigImgName\'] 3 smallImg = Imgdict[\'smallImgName\'] 4 picture_big = self.get_HTML(bigImg) 5 bytes_stream = io.BytesIO(picture_big) 6 roiimg = Image.open(bytes_stream) 7 roiimg.save(\'./big.png\') 8 #获取缺口图片 9 picture_amsll = self.get_HTML(smallImg) 10 bytes_stream = io.BytesIO(picture_amsll) 11 roiimg = Image.open(bytes_stream) 12 roiimg.save(\'./small.png\') 13 14 #二值化图片并进行比对 15 target_rgb = cv2.imread(\'../../chengxu/big.png\', 0) 16 #匹配缺口位置,并获取移动距离 17 template_rgb = cv2.imread(\'../../chengxu/small.png\', 0) 18 res = cv2.matchTemplate(target_rgb, template_rgb, cv2.TM_CCOEFF_NORMED) 19 value = cv2.minMaxLoc(res) 20 Value = value[2][0] 21 Deviation = random.randint(0, 3) 22 if Deviation % 2 == 0: 23 Value_dev = Value - Deviation 24 else: 25 Value_dev = Value + Deviation