Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tom Pillot
Thymio Game
Commits
5c028f72
Commit
5c028f72
authored
Jul 03, 2020
by
Tom Pillot
Browse files
Add a window to choose a webcam
parent
04e86098
Changes
4
Show whitespace changes
Inline
Side-by-side
game/detector.py
View file @
5c028f72
...
...
@@ -3,11 +3,11 @@ import cv2
class
Detector
(
apriltag
.
Detector
):
cam
=
cv2
.
VideoCapture
(
0
)
DECISION_MARGIN
=
40
def
__init__
(
self
):
def
__init__
(
self
,
cam
):
super
().
__init__
()
self
.
DECISION_MARGIN
=
40
self
.
cam
=
cam
def
detect
(
self
,
img
,
return_image
=
False
):
dets
=
super
().
detect
(
img
)
...
...
@@ -28,6 +28,7 @@ class Detector(apriltag.Detector):
if
not
ret
:
print
(
"Failed to grab frame."
)
break
frame
=
cv2
.
resize
(
frame
,
(
640
,
480
))
cv2
.
imshow
(
"Detection"
,
frame
)
...
...
game/scoreboard.py
View file @
5c028f72
...
...
@@ -13,14 +13,14 @@ class ScoreWindow(ScoreWindowUi):
PORT
=
42563
MAX_START_SENT
=
5
def
__init__
(
self
,
teams
):
def
__init__
(
self
,
teams
,
cam
):
super
().
__init__
()
self
.
teams
=
teams
self
.
initial_time
=
0
self
.
time_is_red
=
False
self
.
join_started
=
False
self
.
detector
=
Detector
()
self
.
detector
=
Detector
(
cam
)
self
.
socket
=
socket
(
AF_INET
,
SOCK_DGRAM
)
self
.
socket
.
setsockopt
(
SOL_SOCKET
,
SO_REUSEADDR
,
1
)
...
...
@@ -97,6 +97,7 @@ class ScoreWindow(ScoreWindowUi):
ret
,
frame
=
self
.
detector
.
cam
.
read
()
dets
=
self
.
detector
.
show_tags_on_image
(
frame
)
if
ret
:
frame
=
cv2
.
resize
(
frame
,
(
640
,
480
))
# Convert frame to QImage
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_RGB2BGR
,
frame
)
rows
,
cols
,
_
=
frame
.
shape
...
...
game/team_chooser.py
View file @
5c028f72
...
...
@@ -16,10 +16,10 @@ class TeamWindow(TeamWindowUi):
96
:
"#FE005D"
,
97
:
"#FE002A"
,
98
:
"#474747"
,
99
:
"#8C8C8C"
,
100
:
"#643030"
,
101
:
"#9A6565"
,
102
:
"#BC9F9F"
}
def
__init__
(
self
):
def
__init__
(
self
,
cam
):
super
().
__init__
()
self
.
detector
=
Detector
()
self
.
detector
=
Detector
(
cam
)
self
.
teams
=
{}
# The keys are the tag ids and the values are the teams
self
.
add_activities
()
...
...
main.py
View file @
5c028f72
...
...
@@ -2,6 +2,7 @@ import sys
from
PyQt5
import
QtWidgets
as
qtw
from
game.team_chooser
import
TeamWindow
from
game.scoreboard
import
ScoreWindow
from
game.webcam_chooser
import
WebcamWindow
class
MainWindow
(
qtw
.
QWidget
):
...
...
@@ -9,20 +10,27 @@ class MainWindow(qtw.QWidget):
super
().
__init__
()
self
.
stacked_layout
=
qtw
.
QStackedLayout
()
self
.
te
am_window
=
Te
amWindow
()
self
.
s
coreboard_window
=
ScoreWindow
(
self
.
te
am_window
.
teams
)
self
.
webc
am_window
=
Webc
amWindow
()
self
.
s
tacked_layout
.
addWidget
(
self
.
webc
am_window
)
self
.
stacked_layout
.
addWidget
(
self
.
team_
window
)
self
.
stacked_layout
.
addWidget
(
self
.
scoreboard
_window
)
# We need to wait for the webcam to be chosen before creating the other
window
s
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
.
stacked_layout
.
addWidget
(
self
.
team_window
)
self
.
stacked_layout
.
addWidget
(
self
.
scoreboard_window
)
self
.
stacked_layout
.
setCurrentIndex
(
1
)
def
start_activity
(
self
):
if
self
.
team_window
.
can_start_activity
():
self
.
scoreboard_window
.
add_teams
()
time
=
self
.
team_window
.
time_edit
.
time
()
self
.
scoreboard_window
.
start_scoreboard
(
time
)
self
.
stacked_layout
.
setCurrentIndex
(
1
)
self
.
stacked_layout
.
setCurrentIndex
(
2
)
self
.
scoreboard_window
.
showMaximized
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment