imageMatch source_code

import cv2
import numpy as np

print ('loading')

def showpiclocation(img, findimg): #定义定位函数
    #定位图片
    w = img.shape[1] #返回图片的宽度
    h = img.shape[0]
    fw = findimg.shape[1]
    fh = findimg.shape[0]
    print('---')
    print(w)
    print(h)
    print(fw)
    print(fh)
    findpt = None
    for now_h in range(0, h-fh):
        for now_w in range(0, w-fw):
            comp_tz = img[now_h: now_h+fh, now_w:now_w+fw,:] - findimg
            print(comp_tz)
            if np.sum(comp_tz) < 654715:
                findpt = now_w,now_h

        print ('.')

    if findpt != None:
        print('findpt:')
        #cv2.rectangle(img, findopt, (findopt[0]+fw, findopt[1]+fh), (0,0,255))
        cv2.rectangle(img, findpt, (findpt[0]+fw,findpt[1]+fh),(0,0,255))

    return img

#template = 'pictest.png'
#source_img = 'pictest1.png'
#fn2 = 'pictest2.png'
template = cv2.imread('template.jpg')
source_img = cv2.imread("1.jpg")
#print (source_img)
#print(template)

#myimg2 = cv2.imread(fn2)
myimg = showpiclocation(source_img, template)
#myimg = showpiclocation(myimg, myimg2)
cv2.namedWindow('img')
cv2.imshow('img', myimg)
cv2.waitKey()
cv2.destroyAllWindows()

import cv2
import aircv as ac

# 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('1.jpg')
    imobj = ac.imread('template.jpg')

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

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

    # draw circle
    draw_circle(imsrc, (a,b), int(circle_radius), color, int(line_width))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值