-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDRS_System.py
More file actions
248 lines (185 loc) · 8.9 KB
/
DRS_System.py
File metadata and controls
248 lines (185 loc) · 8.9 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import tkinter
import cv2
import PIL.Image, PIL.ImageTk
from functools import partial
import threading
import time
import imutils
a=input("Enter football or cricket: ")
if a=="cricket":
stream=cv2.VideoCapture("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\clip.mp4")
flag=True
def play(speed):
global flag
# print(f"you clicked on play with speed {speed}")
# play the video in reverse
frame1=stream.get(cv2.CAP_PROP_POS_FRAMES)
stream.set(cv2.CAP_PROP_POS_FRAMES,frame1+speed)
grabbed, frame=stream.read()
if not grabbed:
exit()
frame=imutils.resize(frame,width=1280,height=720)
frame=PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image=frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
if flag:
canvas.create_text(129,25, fill="brown", font="Times 25 bold",text="Decision Pending")
flag=not flag
# Width and Height of our main screen
def out():
thread=threading.Thread(target=pending,args=("out",))
thread.daemon=1
thread.start()
# print("Player is out")
def notout():
thread = threading.Thread(target=pending, args=("notout",))
thread.daemon = 1
thread.start()
# print("Player is not out")
def pending(decision):
# 1 Display decision pending image
frame=cv2.cvtColor(cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\pending.png"), cv2.COLOR_BGR2RGB)
frame=imutils.resize(frame,width=1280,height=720) # for resizing frame
frame=PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image=frame
canvas.create_image(0,-40,image=frame,anchor=tkinter.NW)
# 2 wait for a second
time.sleep(1)
# 3 display sponsor image
frame = cv2.cvtColor(
cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\sponsor.png"),
cv2.COLOR_BGR2RGB)
frame = imutils.resize(frame, width=1280, height=720) # for resizing frame
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
# 4 wait 1.5 second
time.sleep(1.5)
# 5 display out/notout image
if decision=="out":
decisionImg="C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\out.png"
else:
decisionImg = "C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\notout.png"
frame = cv2.cvtColor(cv2.imread(decisionImg),cv2.COLOR_BGR2RGB)
frame = imutils.resize(frame, width=1280, height=720) # for resizing frame
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
SET_WIDTH=1920
SET_HEIGHT=500
#tkinter gui starts here
window=tkinter.Tk()
window.title("Digital Review System by Ansh Dholakia")
cv_img= cv2.cvtColor(cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\DRS\\stadium.png"),cv2.COLOR_BGR2RGB)
canvas=tkinter.Canvas(window,width=SET_WIDTH,height=SET_HEIGHT)
photo=PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(cv_img))
image_on_canvas=canvas.create_image(0,-40, anchor=tkinter.NW,image=photo)
canvas.pack()
# buttons to control playback
btn=tkinter.Button(window,text="<< Previous (Fast)", width=150, command=partial(play,-25))
btn.pack()
btn=tkinter.Button(window,text="<< Previous (Slow)", width=150, command=partial(play,-2))
btn.pack()
btn=tkinter.Button(window,text="Next (Fast) >>", width=150, command=partial(play,25))
btn.pack()
btn=tkinter.Button(window,text="Next (Slow) >>", width=150, command=partial(play,2))
btn.pack()
btn=tkinter.Button(window,text="Out", width=150, command=out)
btn.pack()
btn=tkinter.Button(window,text="Not Out", width=150, command=notout)
btn.pack()
window.mainloop()
elif a=="football":
stream = cv2.VideoCapture("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\clip.mp4")
flag = True
def play(speed):
global flag
# print(f"you clicked on play with speed {speed}")
# play the video in reverse
frame1 = stream.get(cv2.CAP_PROP_POS_FRAMES)
stream.set(cv2.CAP_PROP_POS_FRAMES, frame1 + speed)
grabbed, frame = stream.read()
if not grabbed:
exit()
frame = imutils.resize(frame, width=1280, height=720)
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
if flag:
canvas.create_text(129, 25, fill="brown", font="Times 25 bold", text="Decision Pending")
flag = not flag
# Width and Height of our main screen
def goal():
thread = threading.Thread(target=pending, args=("goal",))
thread.daemon = 1
thread.start()
# print("Goal given")
def nogoal():
thread = threading.Thread(target=pending, args=("nogoal",))
thread.daemon = 1
thread.start()
# print("Goal not given")
def foul():
thread = threading.Thread(target=pending, args=("foul",))
thread.daemon = 1
thread.start()
# print("Fouled")
def pending(decision):
# 1 Display decision pending image
frame = cv2.cvtColor(cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\pending.png"),cv2.COLOR_BGR2RGB)
frame = imutils.resize(frame, width=1280, height=720) # for resizing frame
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
# 2 wait for a second
time.sleep(1)
# 3 display sponsor image
frame = cv2.cvtColor(cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\sponsor.png"),cv2.COLOR_BGR2RGB)
frame = imutils.resize(frame, width=1280, height=720) # for resizing frame
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
# 4 wait 1.5 second
time.sleep(1.5)
# 5 display goal/nogoal image
if decision == "goal":
decisionImg = "C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\goal.png"
elif decision=="nogoal":
decisionImg = "C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\nogoal.png"
else:
decisionImg = "C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\foul.png"
frame = cv2.cvtColor(cv2.imread(decisionImg), cv2.COLOR_BGR2RGB)
frame = imutils.resize(frame, width=1280, height=720) # for resizing frame
frame = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
canvas.image = frame
canvas.create_image(0, -40, image=frame, anchor=tkinter.NW)
SET_WIDTH = 1920
SET_HEIGHT = 470
# tkinter gui starts here
window = tkinter.Tk()
window.title("Virtual Assistant Referee by Ansh Dholakia")
cv_img = cv2.cvtColor(
cv2.imread("C:\\Users\\Ansh\\PycharmProjects\\First Project File\\VAR_Sytem_Project\\VAR\\stadium.png"),
cv2.COLOR_BGR2RGB)
canvas = tkinter.Canvas(window, width=SET_WIDTH, height=SET_HEIGHT)
photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(cv_img))
image_on_canvas = canvas.create_image(0, -100, anchor=tkinter.NW, image=photo)
canvas.pack()
# buttons to control playback
btn = tkinter.Button(window, text="<< Previous (Fast)", width=150, command=partial(play, -25))
btn.pack()
btn = tkinter.Button(window, text="<< Previous (Slow)", width=150, command=partial(play, -2))
btn.pack()
btn = tkinter.Button(window, text="Next (Fast) >>", width=150, command=partial(play, 25))
btn.pack()
btn = tkinter.Button(window, text="Next (Slow) >>", width=150, command=partial(play, 2))
btn.pack()
btn = tkinter.Button(window, text="Goal", width=150, command=goal)
btn.pack()
btn = tkinter.Button(window, text="Not a goal", width=150, command=nogoal)
btn.pack()
btn = tkinter.Button(window, text="Foul", width=150, command=foul)
btn.pack()
window.mainloop()
else:
print("Enter a valid sport!")