Started classifying on-screen objects with unified "analyse_frame" function

Rocks, lives, and missiles are identified by their rectangles from cv2.matchTemplate.
Clusters from SIFT are checked against these detected rectangles.
The remaining objects (like the rotated ship) are classified as "mysteries". These will be target for further analysis (like ship angle determination), or we can just shoot at them :)
This commit is contained in:
John McCardle 2021-12-23 13:57:50 -05:00
commit 5499aa5e49
2 changed files with 90 additions and 15 deletions

View file

@ -7,3 +7,13 @@ def squared_distance(vec1, vec2):
def rect_radius_squared(w, h):
"""Returns the radius^2 of the circle inscribed in a rectangle of w * h"""
return (w/2)**2 + (h/2)**2
def point_in_rect(pt, rect):
"""Returns True if the (x,y) point is within the ((x,y),(w,h)) rectangle."""
px, py = pt
tl, wh = rect
rx, ry = tl
rw, rh = wh
rx2 = rx + rw
ry2 = ry + rh
return all([px >= rx, py >= ry, px <= rx2, py <= ry2])