-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoccerGround.py
199 lines (165 loc) · 11.4 KB
/
SoccerGround.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import cv2 # pip install opencv-python
import numpy as np # pip install numpy
meter2Pixel = 100
#-----------------KidSize robot proportions---------------
fieldLength = 9 * meter2Pixel
fieldWidth = 6 * meter2Pixel
goalDepth = 0.6 * meter2Pixel
goalWidth = 2.6 * meter2Pixel
goalHeight = 1.2 * meter2Pixel
goalAreaLength = 1 * meter2Pixel
goalAreaWidth = 3 * meter2Pixel
penaltyMarkDistance = 1.5 * meter2Pixel
centerCircleDiameter = 1.5 * meter2Pixel
borderStripWidth = 1 * meter2Pixel
penaltyAreaLength = 2 * meter2Pixel
penaltyAreaWidth = 5 * meter2Pixel
windowWidth = fieldWidth + 2 * borderStripWidth
windowLength = fieldLength + 2 * borderStripWidth
penaltyRadius = int(0.075 * meter2Pixel)
robotSize = int(0.27 * meter2Pixel)
radius = int(1.5 / 2 * meter2Pixel)
'''
#-----------------Adult robot proportions---------------
fieldLength = 14 * meter2Pixel
fieldWidth = 9 * meter2Pixel
goalDepth = 0.6 * meter2Pixel
goalWidth = 2.6 * meter2Pixel
goalHeight = 1.8 * meter2Pixel
goalAreaLength = 1 * meter2Pixel
goalAreaWidth = 4 * meter2Pixel
penaltyMarkDistance = 2.1 * meter2Pixel
centerCircleDiameter = 3 * meter2Pixel
borderStripWidth = 1 * meter2Pixel
penaltyAreaLength = 3 * meter2Pixel
penaltyAreaWidth = 6 * meter2Pixel
windowWidth = fieldWidth + 2 * borderStripWidth
windowLength = fieldLength + 2 * borderStripWidth
penaltyRadius = int(0.075 * meter2Pixel)
robotSize = int(0.27 * meter2Pixel)
radius = int(1.5 / 2 * meter2Pixel)
'''
#-----------------Create a empty green Ground---------------
Ground = np.zeros((windowWidth, windowLength, 3), np.uint8)
Ground[:] = (0, 150, 0)
# Points corresponding to the quadrant of the Ground
pointA = (borderStripWidth, borderStripWidth)
pointB = (borderStripWidth + fieldLength, borderStripWidth)
pointC = (borderStripWidth + fieldLength, borderStripWidth + fieldWidth)
pointD = (borderStripWidth, borderStripWidth + fieldWidth)
cv2.line(Ground, pointA, pointD, (255, 255, 255), 2, 8, 0)
cv2.line(Ground, pointB, pointC, (255, 255, 255), 2, 8, 0)
cv2.line(Ground, pointC, pointD, (255, 255, 255), 2, 8, 0)
cv2.line(Ground, pointA, pointB, (255, 255, 255), 2, 8, 0)
#-----------------Middle Line---------------
pointMiddlelineA = (borderStripWidth + fieldLength//2, borderStripWidth)
pointMiddlelineB = (borderStripWidth + fieldLength//2, borderStripWidth + fieldWidth)
cv2.line(Ground, pointMiddlelineA, pointMiddlelineB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Length---------------
#----------------------Left Up----------------------
pointPenaltyAreaLengthLeftUpA = (borderStripWidth, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
pointPenaltyAreaLengthLeftUpB = (borderStripWidth + penaltyAreaLength, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaLengthLeftUpA, pointPenaltyAreaLengthLeftUpB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Length---------------
#----------------------Left Down--------------------
pointPenaltyAreaLengthDownA = (borderStripWidth, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
pointPenaltyAreaLengthDownB = (borderStripWidth + penaltyAreaLength, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaLengthDownA, pointPenaltyAreaLengthDownB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Length---------------
#----------------------Right Up---------------------
pointPenaltyAreaLengthRightUpA = (borderStripWidth + fieldLength, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
pointPenaltyAreaLengthRightUpB = (borderStripWidth + fieldLength - penaltyAreaLength, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaLengthRightUpA, pointPenaltyAreaLengthRightUpB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Length---------------
#----------------------Right Down-------------------
pointPenaltyAreaLengthRightDownA = (borderStripWidth + fieldLength, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
pointPenaltyAreaLengthRightDownB = (borderStripWidth + fieldLength - penaltyAreaLength, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaLengthRightDownA, pointPenaltyAreaLengthRightDownB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Width----------------
#------------------------Left-----------------------
pointPenaltyAreaWidthLeftA = (borderStripWidth + penaltyAreaLength, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
pointPenaltyAreaWidthLeftB = (borderStripWidth + penaltyAreaLength, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaWidthLeftA, pointPenaltyAreaWidthLeftB, (255, 255, 255), 2, 8, 0)
#-----------------Penalty Area Width----------------
#------------------------Right----------------------
pointPenaltyAreaWidthRightA = (borderStripWidth + fieldLength - penaltyAreaLength, borderStripWidth + (fieldWidth//2 - penaltyAreaWidth//2))
pointPenaltyAreaWidthRightB = (borderStripWidth + fieldLength - penaltyAreaLength, borderStripWidth + (fieldWidth//2 + penaltyAreaWidth//2))
cv2.line(Ground, pointPenaltyAreaWidthRightA, pointPenaltyAreaWidthRightB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Length------------------
#----------------------Left Up----------------------
pointGoalAreaLengthLeftUpA = (borderStripWidth, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
pointGoalAreaLengthLeftUpB = (borderStripWidth + goalAreaLength, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaLengthLeftUpA, pointGoalAreaLengthLeftUpB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Length------------------
#----------------------Left Down--------------------
pointGoalAreaLengthLeftDownA = (borderStripWidth, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
pointGoalAreaLengthLeftDownB = (borderStripWidth + goalAreaLength, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaLengthLeftDownA, pointGoalAreaLengthLeftDownB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Length------------------
#----------------------Right Up---------------------
pointGoalAreaLengthRightUpA = (borderStripWidth + fieldLength, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
pointGoalAreaLengthRightUpB = (borderStripWidth + fieldLength - goalAreaLength, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaLengthRightUpA, pointGoalAreaLengthRightUpB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Length------------------
#----------------------Right Down-------------------
pointGoalAreaLengthRightDownA = (borderStripWidth + fieldLength, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
pointGoalAreaLengthRightDownB = (borderStripWidth + fieldLength - goalAreaLength, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaLengthRightDownA, pointGoalAreaLengthRightDownB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Width-------------------
#------------------------Left-----------------------
pointGoalAreaWidthLeftA = (borderStripWidth + goalAreaLength, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
pointGoalAreaWidthLeftB = (borderStripWidth + goalAreaLength, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaWidthLeftA, pointGoalAreaWidthLeftB, (255, 255, 255), 2, 8, 0)
#-----------------Goal Area Width-------------------
#------------------------Right----------------------
pointGoalAreaWidthRightA = (borderStripWidth + fieldLength - goalAreaLength, borderStripWidth + (fieldWidth//2 - goalAreaWidth//2))
pointGoalAreaWidthRightB = (borderStripWidth + fieldLength -goalAreaLength, borderStripWidth + (fieldWidth//2 + goalAreaWidth//2))
cv2.line(Ground, pointGoalAreaWidthRightA, pointGoalAreaWidthRightB, (255, 255, 255), 2, 8, 0)
#-----------------Center Circle Diameter------------
CenterCircleDiameter = (borderStripWidth+fieldLength//2, borderStripWidth+fieldWidth//2)
cv2.circle(Ground, CenterCircleDiameter, radius, (255, 255, 255), 2, 8, 0)
#-----------------Start Match Circle-----------------
StartMatchCircle = (borderStripWidth+fieldLength//2, borderStripWidth+fieldWidth//2)
cv2.circle(Ground, StartMatchCircle, penaltyRadius, (255, 255, 255), -1, 8, 0)
#-----------------Penalty Mark Distance Left---------
PenaltyMarkDistanceLeft = (int(borderStripWidth + penaltyMarkDistance), (borderStripWidth + fieldWidth//2))
cv2.circle(Ground, PenaltyMarkDistanceLeft, penaltyRadius, (255, 255, 255), -1, 8, 0)
#-----------------Penalty Mark Distance Right--------
PenaltyMarkDistanceRight = (int(borderStripWidth + fieldLength - penaltyMarkDistance), (borderStripWidth + fieldWidth//2))
cv2.circle(Ground, PenaltyMarkDistanceRight, penaltyRadius, (255, 255, 255), -1, 8, 0)
#-----------------Goal Width Left--------------------
pointGoalWidthLeftA = (int(borderStripWidth - goalDepth), int(borderStripWidth + fieldWidth//2 - goalWidth//2))
pointGoalWidthLeftB = (int(borderStripWidth - goalDepth), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
cv2.line(Ground, pointGoalWidthLeftA, pointGoalWidthLeftB, (0, 255, 255), 2, 8, 0)
#-----------------Goal Depth Left UP-----------------
pointGoalDepthLeftUPA = (int(borderStripWidth - goalDepth),int(borderStripWidth + fieldWidth//2 - goalWidth//2))
pointGoalDepthLeftUPB = (int(borderStripWidth), int(borderStripWidth + fieldWidth//2 - goalWidth//2))
cv2.line(Ground, pointGoalDepthLeftUPA, pointGoalDepthLeftUPB, (0, 255, 255), 2, 8, 0)
#-----------------Goal Depth Left Down---------------
pointGoalDepthLeftDownA = (int(borderStripWidth - goalDepth), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
pointGoalDepthLeftDownB = (int(borderStripWidth), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
cv2.line(Ground, pointGoalDepthLeftDownA, pointGoalDepthLeftDownB, (0, 255, 255), 2, 8, 0)
#-----------------Goal Width Right-------------------
pointGoalWidthRightA = (int(borderStripWidth + fieldLength + goalDepth), int(borderStripWidth + fieldWidth//2 - goalWidth//2))
pointGoalWidthRightB = (int(borderStripWidth + fieldLength + goalDepth), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
cv2.line(Ground, pointGoalWidthRightA, pointGoalWidthRightB, (255, 255, 0), 2, 8, 0)
#-----------------Goal Depth Right UP----------------
GoalDepthRightUPA = (int(borderStripWidth + fieldLength + goalDepth), int(borderStripWidth + fieldWidth//2 - goalWidth//2))
GoalDepthRightUPB = (int(borderStripWidth + fieldLength), int(borderStripWidth + fieldWidth//2 - goalWidth//2))
cv2.line(Ground, GoalDepthRightUPA, GoalDepthRightUPB, (255, 255, 0), 2, 8, 0)
#-----------------Goal Depth Right Down--------------
GoalDepthRightDownA = (int(borderStripWidth + fieldLength + goalDepth), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
GoalDepthRightDownB = (int(borderStripWidth + fieldLength), int(borderStripWidth + fieldWidth//2 + goalWidth//2))
cv2.line(Ground, GoalDepthRightDownA, GoalDepthRightDownB, (255, 255, 0), 2, 8, 0)
'''
#----------------Robot--------------
robot = (borderStripWidth+fieldLength//2,borderStripWidth+fieldWidth//2)
cv2.circle(Ground, robot, robotSize, (255, 0, 255), 2, 8, 0)
#----------------Direction----------
pointDirectionA = (borderStripWidth + fieldLength//2,borderStripWidth + fieldWidth//2)
pointDirectionB = (borderStripWidth + fieldLength//2 - (2*robotSize), borderStripWidth + fieldWidth//2 -(2*robotSize))
cv2.line(Ground, pointDirectionA, pointDirectionB, (255, 0, 255), 2, 8, 0)
'''
cv2.imshow("SoccerGround", Ground)
cv2.waitKey(0)
cv2.destroyAllWindows()