Skip to content

Commit

Permalink
New feature
Browse files Browse the repository at this point in the history
-Added a function that optimizes the movement of the brick
  • Loading branch information
KroSheChKa committed Apr 9, 2023
1 parent f2af0a8 commit 92d9ba6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions FootBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def move(x,y):
win32api.SetCursorPos((x,y))

# Function that optimizes the movement of the brick
def recount(n):
#center_field = 978
x = round((n - 231) * 0.7) + 231
Expand All @@ -26,7 +27,7 @@ def recount(n):
field = {'left': 747,'top': 990,'width': 462,'height': 200}

# Read the image
ball_img = cv2.imread('Ball.png', 0)
ball_img = cv2.imread('Ball.png')

# Getting width and height of the image
w = ball_img.shape[1]
Expand All @@ -40,29 +41,31 @@ def recount(n):

# Grabbing screenshot
screenshot = numpy.array(mss_.grab(field))
screenshot_r = cv2.cvtColor(screenshot, cv2.COLOR_RGB2GRAY)

# Delete the unnecessary alpha channel
#screenshot_removed = screenshot_r[:,:,:3]
screenshot_removed = screenshot[:,:,:3]

# Getting confidence and location of the ball
ball = cv2.matchTemplate(screenshot_r, ball_img, cv2.TM_CCOEFF_NORMED)
ball = cv2.matchTemplate(screenshot_removed, ball_img, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(ball)

#print(f"Max Val: {max_val} Max Loc: {max_loc}")

#new_x = recount((max_loc[0] + w//2))
# Recalculating for X coord.
new_x = recount((max_loc[0] + w//2))

# Confidence threshold
if max_val > 0.25:

# Moving cursor right bellow the ball
#move((new_x + 747), 1161)
move((max_loc[0] + w//2 + 747), 1161)
move(new_x + 747, 1161)

# Putting a circle above the ball
#cv2.circle(screenshot_r, (max_loc[0] + w//2, max_loc[1]+ h//2), 20, (255,255,255), 4)
cv2.circle(screenshot, (max_loc[0] + w//2, max_loc[1]+ h//2), 20, (255,255,255), 4)

# Showing the area
#cv2.imshow('Football', screenshot_r)
#cv2.waitKey(1)
cv2.imshow('Football', screenshot)
cv2.waitKey(1)

else:

Expand Down

0 comments on commit 92d9ba6

Please sign in to comment.