You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
505B

  1. import cv2
  2. if __name__ == "__main__":
  3. # 先把图片灰度处理。
  4. img = cv2.imread('image/AI6.jpg')
  5. img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  6. template = cv2.imread('image/AI.jpg')
  7. template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
  8. h, w = template.shape[:2]
  9. # 匹配
  10. result = cv2.matchTemplate(img_gray, template_gray, cv2.TM_CCOEFF_NORMED)
  11. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
  12. print(min_val, max_val, min_loc, max_loc)