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, findpt, (findpt[0]+fw,findpt[1]+fh),(0,0,255))
return img
template = cv2.imread('template.jpg')
source_img = cv2.imread("1.jpg")
myimg = showpiclocation(source_img, template)
cv2.namedWindow('img')
cv2.imshow('img', myimg)
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
import aircv as ac
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')
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(imsrc, (a,b), int(circle_radius), color, int(line_width))