Skip to content

Commit

Permalink
Updated marker code for 24-25 and fixed bugs from previous!
Browse files Browse the repository at this point in the history
  • Loading branch information
OldUser101 committed Oct 12, 2024
1 parent ec8c84e commit 5dd5796
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
4 changes: 2 additions & 2 deletions robot/apriltags3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import scipy.spatial.transform as transform

from robot.game_config import MARKER
from robot.game_config import MARKER, MARKER_TYPE


######################################################################
Expand Down Expand Up @@ -435,7 +435,7 @@ def detect(self, img, estimate_tag_pose=False, camera_params=None):
if camera_params is None:
raise ValueError(
"camera_params must be provided to detect if estimate_tag_pose is set to True")
tag_size = MARKER(tag.id).size
tag_size = MARKER.get_size(tag.id)

camera_fx, camera_fy, camera_cx, camera_cy = [
c for c in camera_params]
Expand Down
35 changes: 11 additions & 24 deletions robot/game_config/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
Byee!
- Holly (2023-2024)
Don't know what to say. - Nathan Gill (2024 - 2025)
No semi-colons please - Scott Wilson (2024 - 2025)
[Put your future messages here]
"""

Expand All @@ -24,10 +27,10 @@ class MARKER_TYPE(enum.Enum): # Keep something like this to determine if a marke

class BASE_MARKER: # Base marker class that POTATO_MARKER and ARENA_MARKER derive from.
team_marker_colors: dict = { # Colour definitions for each team defined in TEAMS
TEAM.RUBY: (255, 0, 0), # RED
TEAM.RUBY: (0, 0, 255), # RED
TEAM.JADE: (0, 255, 0), # GREEN
TEAM.TOPAZ: (255, 255, 0), # YELLOW
TEAM.DIAMOND: (0, 0, 255), # BLUE
TEAM.TOPAZ: (0, 255, 255), # YELLOW
TEAM.DIAMOND: (255, 0, 0), # BLUE
}

def __init__(
Expand All @@ -48,10 +51,10 @@ def __repr__(self) -> str:
@property
def bounding_box_color(self) -> tuple:
if self.type == MARKER_TYPE.ARENA: # If it is a wall
return tuple(reversed((125, 249, 225))) # Turquoise
elif self.owning_team==TEAM.ARENA: # If it is a Hot Potato (game object owned by ARENA)
return tuple(reversed((225, 249, 125))) # Turquoise
elif self.owning_team==TEAM.ARENA: # If it is a Sheep (game object owned by ARENA)
return tuple(reversed((255,255,255))) # White
else: # If it is a Jacket Potato (game object owned by a team.)
else: # If it is a Jewel (game object owned by a team.)
return tuple(reversed(self.team_marker_colors[self.owning_team])) # Picks the team colour from above

class ARENA_MARKER(BASE_MARKER): # Not much going on here. This represents a wall.
Expand Down Expand Up @@ -119,22 +122,6 @@ def by_id(id: int, team: typing.Union[TEAM, None] = None) -> BASE_MARKER: # team
elif id == 24 or id == 25 or id == 50:
owning_team = TEAM["T0"]
else:
owning_team = None

# ARENA_WALL_LOWER_ID = 40
# if id >= ARENA_WALL_LOWER_ID:
# return ARENA_MARKER(id)
#
# wrappingId = id % 20 # Make sure that the ID range wraps after 20 values.
# if wrappingId<4: # If it is a Jacket Potato (has a team)
# owning_team = TEAM[f"T{wrappingId}"] # Set to the corresponding TEAM enum.
# else: # If it is a Hot Potato (Has no team)
# owning_team = TEAM["ARENA"]

return TARGET_MARKER(id, owning_team)

## TESTING ##
raise Exception("AHHHHHH!")

#print(f"{MARKER.get_size(0)}, {MARKER.get_size(30)}")
#for i in range(0, 200):
# print(f"ID: {i}, {MARKER.by_id(i)}")
return TARGET_MARKER(id, owning_team)
6 changes: 3 additions & 3 deletions robot/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ def _draw_bounding_box(self, frame, detections):
"""
polygon_is_closed = True
for detection in detections:
marker_info = MARKER(detection.id, self.zone)
marker_info = MARKER.by_id(detection.id, self.zone)
marker_info_colour = marker_info.bounding_box_color
marker_code = detection.id

# The reverse is because OpenCV expects BGR but we use RGB
colour = reversed(marker_info_colour
colour = tuple(reversed(marker_info_colour
if marker_info_colour is not None
else DEFAULT_BOUNDING_BOX_COLOUR)
else DEFAULT_BOUNDING_BOX_COLOUR))

# need to have this EXACT integer_corners syntax due to opencv bug
# https://stackoverflow.com/questions/17241830/
Expand Down

0 comments on commit 5dd5796

Please sign in to comment.