Commit 51b13a8a authored by Tom Pillot's avatar Tom Pillot
Browse files

Fix KeyError exception when trying to add points to a team that is not in the...

Fix KeyError exception when trying to add points to a team that is not in the list. Update webcam before trying to read it in the team chooser window.
parent 31d5ca88
......@@ -18,6 +18,10 @@ class Detector(apriltag.Detector):
def detect_from_cam(self):
cv2.namedWindow("Detection")
# Refresh cam before trying to detect tags, else it reads an old image
for i in range(5):
self.cam.read()
tag_id = None
while not tag_id:
ret, frame = self.cam.read()
......@@ -35,6 +39,7 @@ class Detector(apriltag.Detector):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
tag_id = self.detect(gray)
print(tag_id)
cv2.destroyAllWindows()
return tag_id
......
......@@ -128,15 +128,18 @@ class ScoreWindow(ScoreWindowUi):
def add_points(self, tag_id):
""" Add points to the team with the corresponding tag id """
team = self.teams[tag_id]
remaining_time = - self.time_edit.time().secsTo(qtc.QTime(0, 0, 0, 0))
if remaining_time > 0: # Teams can't win any points after the timer has ended
max_points = 1000
min_points = 100
points_added = int(min_points + (max_points - min_points) / self.initial_time * remaining_time)
if team.can_win_points:
team.add_points(points_added)
self.show_event(team, points_added)
try:
team = self.teams[tag_id]
remaining_time = - self.time_edit.time().secsTo(qtc.QTime(0, 0, 0, 0))
if remaining_time > 0: # Teams can't win any points after the timer has ended
max_points = 1000
min_points = 100
points_added = int(min_points + (max_points - min_points) / self.initial_time * remaining_time)
if team.can_win_points:
team.add_points(points_added)
self.show_event(team, points_added)
except KeyError: # If the webcam detects a tag that is not registered in the list
pass
def show_event(self, team, points_added):
message = team.name + " a gagné " + str(points_added) + " points."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment