def _get_pic(self, img1, pic_name, delta_color, sim, method): img2 = pic_name if method <= 5: # 只匹配指定的颜色图像,参数mask表示参与匹配的像素矩阵 if delta_color and isinstance(delta_color, str): lower, upper = color_to_range(delta_color, 1.0) lower, upper = lower_upper21(lower, upper) mask = cv2.inRange(img2, tuple(lower), tuple(upper)) elif delta_color and (isinstance(delta_color, list) or isinstance(delta_color, tuple)): lower, upper = delta_color # lower, upper = lower_upper21(lower, upper) img2_hsv = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV) mask = cv2.inRange(img2_hsv, tuple(lower), tuple(upper)) else: mask = None result = cv2.matchTemplate(img1, img2, method, mask=mask) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) yloc, xloc = np.where(result >= sim) height, width = img2.shape[:2] return result, min_val, max_val, min_loc, max_loc, yloc, xloc, height, width 解析代码
时间: 2023-06-02 21:08:27 浏览: 87
这段代码的作用是获取图片,具体参数包括img1、pic_name、delta_color、sim和method。其中img1表示图片1,pic_name表示图片名称,delta_color表示颜色差异,sim表示相似度,method表示方法。代码中使用if语句判断method的值是否小于或等于5。
阅读全文