python从图片中找图 检查两个图片相对位置


import aircv as ac
def matcha(bb,aa):#从bb查找aa,如果有则返回其坐标位置
    yuan=ac.imread(bb)
    mubi=ac.imread(aa)
    result=ac.find_template(yuan,mubi,0.7)#0.7相似度
    if(result!=None):        
        return result['result'][0],result['result'][1]
        #return yuan.shape[1],yuan.shape[0]
    return None

aa="./xm1.png"
bb="./tmall4a.png"
dd=matcha(bb,aa)
print(dd)

 

import cv2
import aircv as ac
import pyautogui
import matplotlib.pyplot as plt
import numpy

# print circle_center_pos
def draw_circle(img, pos, circle_radius, color, line_width):
    cv2.circle(img, pos, circle_radius, color, line_width)
    cv2.imshow('objDetect', imsrc) 
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    imsrc = ac.imread('bg.jpg')
    imobj = ac.imread('aa1.png')

    # find the match position
    pos = ac.find_template(imsrc, imobj)

    circle_center_pos = pos['result']
    circle_radius = 50
    color = (0, 255, 0)
    line_width = 10


    print(pos['result'])
    x,y=pos['result']

    m=int(x)
    n=int(y)

    circle_center_pos = pos['result']
    circle_radius = 50
    color = (0, 255, 0)
    line_width = 10

    draw_circle(imsrc, (m,n), circle_radius, color, line_width)
    
    plt.imshow(imsrc)
    plt.axis('off')
    plt.show()

    cv2.imwrite("result.jpg", imsrc)
#    while True:
#         x,y = pyautogui.position() #返回鼠标的坐标
#         print(x,y)
    # draw circle
#    draw_circle(imsrc, circle_center_pos, circle_radius, color, line_width)

 

 

 

转:https://www.cnblogs.com/xkdn/p/14168985.html

转:https://blog.csdn.net/weixin_33595571/article/details/106727488

转:https://blog.csdn.net/weixin_33595571/article/details/106736393

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM