基本信息
源码名称:python图片识别--找图
源码大小:1.29KB
文件格式:.py
开发语言:Python
更新时间:2020-03-29
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

找出子图片在原图中的坐标


# -*- coding: UTF-8 -*- import cv2 import os import time def get_pay_keyboard_number_location(impath, target, screenw, screenh, val): print("start find pic") start = time.time()
    img_src = cv2.imread(impath)
    template = cv2.imread(target) if (img_src is not None) and (template is not None): # 获取小图片的高和宽  imgtmh = template.shape[0]
        imgtmw = template.shape[1] # 获取大图片的高和宽  img_srch = img_src.shape[0]
        img_srcw = img_src.shape[1] # 匹配图片  res = cv2.matchTemplate(img_src, template, cv2.TM_CCOEFF_NORMED) # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标  min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) if max_val >= val: # 计算手机中的坐标  position = [int(screenw / img_srcw * (max_loc[0]   imgtmw / 2)), int(screenh / img_srch * (max_loc[1]   imgtmh / 2))] print(position) def main():
    src_img=r"C:\Picture\basa.jpg"  find_pic=r"C:\Picture\child.png"  screenw=600  screenh=360  val=0.7  get_pay_keyboard_number_location(src_img, find_pic, screenw, screenh, val) if __name__=='__main__':
    main()