-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFull_Screenshot.py
371 lines (290 loc) · 10.2 KB
/
Full_Screenshot.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# -*- coding: utf-8 -*-
"""ProTanki Crystal Prediction.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/13MFugR-YzQIVIC3_UdvyWEBiQQDFLDWm
"""
!sudo apt install tesseract-ocr
!pip install pytesseract
import pandas as pd
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
import requests
from PIL import Image, ImageOps
import pytesseract
from io import BytesIO
import numpy as np
def create_dataset(data):
X = data[:, 0].reshape(-1, 1)
y = data[:, 1].reshape(-1, 1)
return X, y
dataset1 = np.array([
[1.020408163, 1.525445846],
[1.049019608, 1.560103292],
[1.086956522, 1.606557377],
[1.148734177, 1.673073086],
[1.162790698, 1.688362652],
[1.166666667, 1.705882353],
[1.192771084, 1.720207945],
[1.25, 1.777794404],
[1.25, 1.778464254],
[1.283842795, 1.810702138],
[1.333333333, 1.862068966],
[1.363636364, 1.887345679],
[1.388888889, 1.906616257],
[1.388888889, 1.906961193],
[1.4, 1.9218107],
[1.416666667, 1.932327167],
[1.428571429, 1.943669528],
[1.45, 1.960015379],
[1.485148515, 1.988570148],
[1.5, 2.002361275]
])
X1, y1 = create_dataset(dataset1)
dataset2 = np.array([
[1.485148515, 1.988570148],
[1.5, 2.002361275],
[1.8, 2.214345992],
[1.851851852, 2.248992748],
[1.886792453, 2.268008232],
[1.930731707, 2.294513121],
[2.040816327, 2.356053013],
[2.25, 2.458695652],
[2.5, 2.594771242],
[2.729508197, 2.659179175],
[3, 2.750310559],
[3, 2.75708502],
[3.125, 2.787451533],
[3.333333333, 2.845689493],
[3.511363636, 2.891874702],
[4, 3.010186757],
[4.666666667, 3.118362124],
[5, 3.167769376],
[5, 3.168224299],
[5.479452055, 3.228808536],
[5.800947867, 3.264898919],
[5.941176471, 3.281713344],
[6, 3.287804878],
[6.301369863, 3.315228089],
[7.5, 3.411666667],
[7.5, 3.412280702],
[8, 3.443908323]
])
X2, y2 = create_dataset(dataset2)
dataset3 = np.array([
[8,3.443908323],
[8.333333333,3.462385899],
[8.5,3.474226804],
[9.336448598,3.516258583],
[10,3.55],
[10,3.551210428],
[11.11111111,3.586206897],
[11.11111111,3.59112426],
[12.33333333,3.6250295],
[14,3.666483456],
[14.27142857,3.672679505],
[15.71428571,3.704481793],
[16.66666667,3.720626632],
[21.35714286,3.776863961],
[22,3.782079165],
[29,3.834249804],
[30,3.83880597],
[33.33333333,3.854470426],
[34.44827586,3.858971552],
[37.5,3.871282417],
[50,3.902043932]
])
X3, y3 = create_dataset(dataset3)
poly_reg1 = PolynomialFeatures(degree=3)
X_poly1 = poly_reg1.fit_transform(X1)
poly_reg2 = PolynomialFeatures(degree=5)
X_poly2 = poly_reg2.fit_transform(X2)
poly_reg3 = PolynomialFeatures(degree=5)
X_poly3 = poly_reg3.fit_transform(X3)
pol_reg1 = LinearRegression()
pol_reg2 = LinearRegression()
pol_reg3 = LinearRegression()
pol_reg1.fit(X_poly1, y1)
pol_reg2.fit(X_poly2, y2)
pol_reg3.fit(X_poly3, y3)
xconfig = '--psm 6 --oem 3 -c tessedit_char_whitelist=0123456789'
url = input("Enter a URL: ")
response = requests.get(url)
from PIL import Image, ImageOps
import pytesseract
import cv2
from google.colab.patches import cv2_imshow
# Open the image
image = Image.open(BytesIO(response.content))
# Get the width and height of the image
width, height = image.size
# Define the region to be cropped (1500 pixels from the left, 1040 pixels from the top, 200 pixels from the right)
region = (1500, 1035, width - 150, height - 22)
# Crop the image to the specified region
cropped_image = image.crop(region)
# Save the cropped image
cropped_image.save('fund.png')
# Resize the cropped image
resized_image = cropped_image.resize((cropped_image.width * 8, cropped_image.height * 6))
# Convert the resized image to black and white
bw_image = ImageOps.invert(resized_image.convert('RGB')).convert('L')
# Save the black and white image
bw_image.save("fund_BW.png")
image = cv2.imread('fund_BW.png', 0)
thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
# Perform text extraction
results = pytesseract.image_to_data(thresh, lang='eng', output_type='dict', config='--psm 10')
# Find the word "Battle" in the results and get its coordinates
word_x, word_y, word_w, word_h = None, None, None, None
for idx, text in enumerate(results['text']):
if text == 'Battle':
word_x = results['left'][idx]
word_y = results['top'][idx]
word_w = results['width'][idx]
word_h = results['height'][idx]
break
if word_x is not None:
# Define the region of interest (ROI) around the word "Battle"
roi = (word_x + 530, word_y, word_w + 540, word_h)
# Crop the thresholded image to the ROI
cropped_word = thresh[word_y:word_y + word_h, word_x + 530:word_x + word_w + 540]
# Save the cropped word as a new image
cv2.imwrite('battle.png', cropped_word)
# Show the cropped word
cv2_imshow(cropped_word)
print("The word 'Battle' has been cropped and saved as 'battle.png'.")
else:
print("The word 'Battle' was not found in the image.")
# Use Tesseract to recognize text from the image
fund = pytesseract.image_to_string('battle.png', config=xconfig)
funds = list(map(int, fund.strip().split()))
funds
from PIL import Image, ImageOps
import pytesseract
import re
from google.colab.patches import cv2_imshow
# Open the image
image = Image.open(BytesIO(response.content))
# Get the width and height of the image
width, height = image.size
# Define the region to be cropped (1500 pixels from the left, 1027 pixels from the top, 200 pixels from the right)
region = (1770, 1030, width-10, height-15)
# Crop the image to the specified region
cropped_image = image.crop(region)
# Save the cropped image
cropped_image.save('flags.png')
# Resize the cropped image
resized_image = cropped_image.resize((cropped_image.width * 8, cropped_image.height * 6))
# Convert the resized image to black and white
bw_image = ImageOps.invert(resized_image.convert('RGB')).convert('L')
# Save the black and white image
bw_image.save("flags_BW.png")
image = cv2.imread('flags_BW.png', 0)
thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
# Use Tesseract to recognize text from the image
flag = pytesseract.image_to_string(thresh, config='--psm 9')
# Remove non-numeric characters from the recognized text
flags = re.findall(r'\d+', flag)
# Convert the recognized numbers to integers
flags = list(map(int, flags))
print(flag)
print(flags)
cv2_imshow(thresh)
from PIL import Image, ImageOps
import pytesseract
import re
from google.colab.patches import cv2_imshow
# Open the image
image = Image.open(BytesIO(response.content))
# Get the width and height of the image
width, height = image.size
# Define the region to be cropped (1500 pixels from the left, 1027 pixels from the top, 200 pixels from the right)
region = (920, 150, width - 950, height-98)
# Crop the image to the specified region
cropped_image = image.crop(region)
# Save the cropped image
cropped_image.save('full_score.png')
# Resize the cropped image
resized_image = cropped_image.resize((cropped_image.width * 3, cropped_image.height * 3))
# Convert the resized image to black and white
bw_image = ImageOps.invert(resized_image.convert('RGB')).convert('L')
# Save the black and white image
bw_image.save("full_score_BW.png")
image = cv2.imread('full_score_BW.png', 0)
thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
# Use Tesseract to recognize text from the image
score = pytesseract.image_to_string(thresh, config=xconfig)
scores = list(map(int, score.strip().split()))
if scores[0] < scores[1]:
# Remove the first number from the list
scores.pop(0)
original_list = scores
if original_list[0] < original_list[1]:
# Remove the first number from the list
original_list.pop(0)
# Split the list in the middle when previous number is smaller than the following number
for i in range(1, len(original_list)):
if original_list[i - 1] < original_list[i]:
left_list = original_list[:i]
right_list = original_list[i:]
break
for i in range(len(right_list)-1, 0, -1):
if right_list[i] >= right_list[i-1]: # Compare current element with previous element
right_list.pop(i) # Remove the current element if it's not smaller
print(scores)
print("Left list:", left_list)
print("Right list:", right_list)
# Display the thresh image
cv2_imshow(thresh)
print(funds)
print(flags)
print(left_list)
print(right_list)
WinningScore = []
LossingScore = []
if RedFlag>BlueFlag:
WinningFlag=RedFlag
LossingFlag=BlueFlag
if(Choosing == 'Hand' or Choosing == 'hand'):
WinningScore=RedTeamScore
LossingScore=BlueTeamScore
else:
WinningScore=scores[1]
LossingScore=scores[0]
else:
WinningFlag=BlueFlag
LossingFlag=RedFlag
if(Choosing == 'Hand' or Choosing == 'hand'):
WinningScore=BlueTeamScore
LossingScore=RedTeamScore
else:
WinningScore=scores[0]
LossingScore=scores[1]
if RedFlag == BlueFlag:
PredictionRatio = 1
elif LossingFlag == 0:
PredictionRatio = 4
else:
FlagRatio = WinningFlag / LossingFlag
if FlagRatio < 1.5:
PredictionRatio = pol_reg1.predict(poly_reg1.fit_transform([[FlagRatio]]))
elif FlagRatio > 8:
PredictionRatio = pol_reg3.predict(poly_reg3.fit_transform([[FlagRatio]]))
else:
PredictionRatio = pol_reg2.predict(poly_reg2.fit_transform([[FlagRatio]]))
LossingTeamCrystals = BattleFund * (1 / (PredictionRatio + 1))
WinningTeamCrystals = BattleFund - LossingTeamCrystals
WinningCrystal = WinningTeamCrystals / sum(WinningScore)
LossingCrystal = LossingTeamCrystals / sum(LossingScore)
WinningIndividualCrystals = np.round(np.multiply(WinningScore, WinningCrystal), 0)
LossingIndividualCrystals = np.round(np.multiply(LossingScore, LossingCrystal), 0)
if RedFlag > BlueFlag:
print('Red Team players will get: ', ', '.join(map(str, WinningIndividualCrystals)))
print('\n')
print('Blue Team players will get: ', ', '.join(map(str, LossingIndividualCrystals)))
else:
print('Red Team players will get: ', ', '.join(map(str, LossingIndividualCrystals)))
print('\n')
print('Blue Team players will get: ', ', '.join(map(str, WinningIndividualCrystals)))
import time
time.sleep(60000)