Commit 5c028f72 authored by Tom Pillot's avatar Tom Pillot
Browse files

Add a window to choose a webcam

parent 04e86098
...@@ -3,11 +3,11 @@ import cv2 ...@@ -3,11 +3,11 @@ import cv2
class Detector(apriltag.Detector): class Detector(apriltag.Detector):
cam = cv2.VideoCapture(0) DECISION_MARGIN = 40
def __init__(self): def __init__(self, cam):
super().__init__() super().__init__()
self.DECISION_MARGIN = 40 self.cam = cam
def detect(self, img, return_image=False): def detect(self, img, return_image=False):
dets = super().detect(img) dets = super().detect(img)
...@@ -28,6 +28,7 @@ class Detector(apriltag.Detector): ...@@ -28,6 +28,7 @@ class Detector(apriltag.Detector):
if not ret: if not ret:
print("Failed to grab frame.") print("Failed to grab frame.")
break break
frame = cv2.resize(frame, (640, 480))
cv2.imshow("Detection", frame) cv2.imshow("Detection", frame)
......
...@@ -13,14 +13,14 @@ class ScoreWindow(ScoreWindowUi): ...@@ -13,14 +13,14 @@ class ScoreWindow(ScoreWindowUi):
PORT = 42563 PORT = 42563
MAX_START_SENT = 5 MAX_START_SENT = 5
def __init__(self, teams): def __init__(self, teams, cam):
super().__init__() super().__init__()
self.teams = teams self.teams = teams
self.initial_time = 0 self.initial_time = 0
self.time_is_red = False self.time_is_red = False
self.join_started = False self.join_started = False
self.detector = Detector() self.detector = Detector(cam)
self.socket = socket(AF_INET, SOCK_DGRAM) self.socket = socket(AF_INET, SOCK_DGRAM)
self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
...@@ -97,6 +97,7 @@ class ScoreWindow(ScoreWindowUi): ...@@ -97,6 +97,7 @@ class ScoreWindow(ScoreWindowUi):
ret, frame = self.detector.cam.read() ret, frame = self.detector.cam.read()
dets = self.detector.show_tags_on_image(frame) dets = self.detector.show_tags_on_image(frame)
if ret: if ret:
frame = cv2.resize(frame, (640, 480))
# Convert frame to QImage # Convert frame to QImage
cv2.cvtColor(frame, cv2.COLOR_RGB2BGR, frame) cv2.cvtColor(frame, cv2.COLOR_RGB2BGR, frame)
rows, cols, _ = frame.shape rows, cols, _ = frame.shape
......
...@@ -16,10 +16,10 @@ class TeamWindow(TeamWindowUi): ...@@ -16,10 +16,10 @@ class TeamWindow(TeamWindowUi):
96: "#FE005D", 97: "#FE002A", 98: "#474747", 99: "#8C8C8C", 100: "#643030", 101: "#9A6565", 102: "#BC9F9F" 96: "#FE005D", 97: "#FE002A", 98: "#474747", 99: "#8C8C8C", 100: "#643030", 101: "#9A6565", 102: "#BC9F9F"
} }
def __init__(self): def __init__(self, cam):
super().__init__() super().__init__()
self.detector = Detector() self.detector = Detector(cam)
self.teams = {} # The keys are the tag ids and the values are the teams self.teams = {} # The keys are the tag ids and the values are the teams
self.add_activities() self.add_activities()
......
...@@ -2,6 +2,7 @@ import sys ...@@ -2,6 +2,7 @@ import sys
from PyQt5 import QtWidgets as qtw from PyQt5 import QtWidgets as qtw
from game.team_chooser import TeamWindow from game.team_chooser import TeamWindow
from game.scoreboard import ScoreWindow from game.scoreboard import ScoreWindow
from game.webcam_chooser import WebcamWindow
class MainWindow(qtw.QWidget): class MainWindow(qtw.QWidget):
...@@ -9,20 +10,27 @@ class MainWindow(qtw.QWidget): ...@@ -9,20 +10,27 @@ class MainWindow(qtw.QWidget):
super().__init__() super().__init__()
self.stacked_layout = qtw.QStackedLayout() self.stacked_layout = qtw.QStackedLayout()
self.team_window = TeamWindow() self.webcam_window = WebcamWindow()
self.scoreboard_window = ScoreWindow(self.team_window.teams) self.stacked_layout.addWidget(self.webcam_window)
self.stacked_layout.addWidget(self.team_window) # We need to wait for the webcam to be chosen before creating the other windows
self.stacked_layout.addWidget(self.scoreboard_window) self.webcam_window.start_button.clicked.connect(self.show_team_window)
def show_team_window(self):
self.team_window = TeamWindow(self.webcam_window.cam)
self.scoreboard_window = ScoreWindow(self.team_window.teams, self.webcam_window.cam)
self.team_window.start_button.clicked.connect(self.start_activity) self.team_window.start_button.clicked.connect(self.start_activity)
self.stacked_layout.addWidget(self.team_window)
self.stacked_layout.addWidget(self.scoreboard_window)
self.stacked_layout.setCurrentIndex(1)
def start_activity(self): def start_activity(self):
if self.team_window.can_start_activity(): if self.team_window.can_start_activity():
self.scoreboard_window.add_teams() self.scoreboard_window.add_teams()
time = self.team_window.time_edit.time() time = self.team_window.time_edit.time()
self.scoreboard_window.start_scoreboard(time) self.scoreboard_window.start_scoreboard(time)
self.stacked_layout.setCurrentIndex(1) self.stacked_layout.setCurrentIndex(2)
self.scoreboard_window.showMaximized() self.scoreboard_window.showMaximized()
......
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