def find_float(img_name):
print 'Looking for float'
# todo: maybe make some universal float without background?
for x in range(0, 7):
template = cv2.imread('var/fishing_float_' + str(x) + '.png', 0)
img_rgb = cv2.imread(img_name)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
# print('got images')
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.6
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
if loc[0].any():
print 'Found ' + str(x) + ' float'
if dev:
cv2.imwrite('var/fishing_session_' + str(int(time.time())) + '_success.png', img_rgb)
return (loc[1][0] + w / 2) / 2, (loc[0][0] + h / 2) / 2
评论列表
文章目录