forked from adwaitkelkar/Football-Highlights-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_dataframe.py
70 lines (58 loc) · 2.06 KB
/
get_dataframe.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
import cv2
import pandas as pd
from paddleocr import PaddleOCR
def get_dataframe(match_path):
dataframe = {
"Timestamp":[],
"Team1":[],
"Team2":[],
"Score1": [],
"Score2":[]
}
cap = cv2.VideoCapture(match_path)
i = 0
frame_skip = 200
frame_count = 0
ocr = PaddleOCR(use_angle_cls=True, lang='en')
while cap.isOpened():
timestamp = cap.get(cv2.CAP_PROP_POS_MSEC)
timestamp = timestamp//1000
ret, frame = cap.read()
if not ret:
break
if i > frame_skip -1:
frame_count += 1
cropped_frame = frame[40:65,110:313]
try:
result = ocr.ocr(cropped_frame, cls=True, det=False)
except Exception as e:
print("Error during OCR:", e)
continue
for line in result:
for text, conf in line:
if conf > 0.90:
main_text = text.strip()
break
else:
continue
if main_text[:3] != ' ':
team1 = main_text[:3]
dataframe['Team1'].append(team1)
if main_text[4:5] != ' ':
score2 = main_text[4:5]
dataframe['Score2'].append(score2)
if main_text[5:] != ' ':
team2 = main_text[5:]
dataframe['Team2'].append(team2)
if main_text[3] != ' ':
score1 = main_text[3:4]
dataframe['Score1'].append(score1)
dataframe['Timestamp'].append(timestamp)
i =0
print('------GENERATING DATA FRAME------')
continue
i +=1
df_final = pd.DataFrame.from_dict(dataframe)
cap.release()
cv2.destroyAllWindows()
return df_final.to_csv('file1.csv',index=False)