GameSentenceMiner 2.12.2__tar.gz → 2.12.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/config_gui.py +25 -1
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/gametext.py +1 -1
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/obs.py +71 -1
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/ocr.py +28 -31
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/run.py +25 -64
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/configuration.py +1 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/downloader/oneocr_dl.py +9 -8
- gamesentenceminer-2.12.4/GameSentenceMiner/wip/get_overlay_coords.py +519 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/PKG-INFO +3 -1
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/PKG-INFO +3 -1
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/README.md +2 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/pyproject.toml +1 -1
- gamesentenceminer-2.12.2/GameSentenceMiner/wip/get_overlay_coords.py +0 -244
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ai/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ai/ai_prompting.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/anki.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon128.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon256.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon32.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon512.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/icon64.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/assets/pickaxe.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/gsm.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/gsm_ocr_config.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/ocrconfig.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/owocr_area_selector.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/owocr_helper.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/ocr/ss_picker.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/__main__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/config.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/lens_betterproto.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/owocr/owocr/screen_coordinate_picker.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/audio_offset_selector.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/communication/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/communication/send.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/communication/websocket.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/downloader/Untitled_json.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/downloader/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/downloader/download_tools.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/electron_config.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/ffmpeg.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/gsm_utils.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/model.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/notification.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/package.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/ss_selector.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/text_log.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/window_transparency.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/vad.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/service.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/apple-touch-icon.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/favicon-96x96.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/favicon.ico +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/favicon.svg +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/site.webmanifest +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/style.css +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/web-app-manifest-192x192.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/static/web-app-manifest-512x512.png +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/templates/__init__.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/templates/index.html +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/templates/text_replacements.html +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/templates/utility.html +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/web/texthooking_page.py +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/SOURCES.txt +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/dependency_links.txt +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/entry_points.txt +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/requires.txt +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner.egg-info/top_level.txt +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/LICENSE +0 -0
- {gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/setup.cfg +0 -0
@@ -139,6 +139,16 @@ class ConfigApp:
|
|
139
139
|
self.ai_tab = None
|
140
140
|
self.advanced_tab = None
|
141
141
|
self.wip_tab = None
|
142
|
+
self.monitors = []
|
143
|
+
|
144
|
+
try:
|
145
|
+
import mss as mss
|
146
|
+
self.monitors = [f"Monitor {i}: width: {monitor['width']}, height: {monitor['height']}" for i, monitor in enumerate(mss.mss().monitors[1:], start=1)]
|
147
|
+
print(self.monitors)
|
148
|
+
if len(self.monitors) == 0:
|
149
|
+
self.monitors = [1]
|
150
|
+
except ImportError:
|
151
|
+
self.monitors = []
|
142
152
|
|
143
153
|
self.create_tabs()
|
144
154
|
|
@@ -375,7 +385,8 @@ class ConfigApp:
|
|
375
385
|
),
|
376
386
|
wip=WIP(
|
377
387
|
overlay_websocket_port=int(self.overlay_websocket_port.get()),
|
378
|
-
overlay_websocket_send=self.overlay_websocket_send.get()
|
388
|
+
overlay_websocket_send=self.overlay_websocket_send.get(),
|
389
|
+
monitor_to_capture=self.monitor_to_capture.current()
|
379
390
|
)
|
380
391
|
)
|
381
392
|
|
@@ -1743,6 +1754,19 @@ class ConfigApp:
|
|
1743
1754
|
row=self.current_row, column=1, sticky='W', pady=2)
|
1744
1755
|
self.current_row += 1
|
1745
1756
|
|
1757
|
+
HoverInfoLabelWidget(wip_frame, text="Monitor to Capture:",
|
1758
|
+
tooltip="Select the monitor to capture (1-based index).",
|
1759
|
+
row=self.current_row, column=0)
|
1760
|
+
self.monitor_to_capture = ttk.Combobox(wip_frame, values=self.monitors, state="readonly")
|
1761
|
+
|
1762
|
+
# set index of monitor to capture, not the string
|
1763
|
+
if self.monitors:
|
1764
|
+
self.monitor_to_capture.current(self.settings.wip.monitor_to_capture)
|
1765
|
+
else:
|
1766
|
+
self.monitor_to_capture.set("OwOCR Not Detected")
|
1767
|
+
self.monitor_to_capture.grid(row=self.current_row, column=1, sticky='EW', pady=2)
|
1768
|
+
self.current_row += 1
|
1769
|
+
|
1746
1770
|
self.add_reset_button(wip_frame, "wip", self.current_row, 0, self.create_wip_tab)
|
1747
1771
|
|
1748
1772
|
for col in range(2):
|
@@ -137,7 +137,7 @@ async def find_box_for_sentence(sentence):
|
|
137
137
|
boxes = []
|
138
138
|
logger.info(f"Finding Box for Sentence: {sentence}")
|
139
139
|
boxes, font_size = await get_overlay_coords.find_box_for_sentence(sentence)
|
140
|
-
logger.info(f"Found Boxes: {boxes}, Font Size: {font_size}")
|
140
|
+
# logger.info(f"Found Boxes: {boxes}, Font Size: {font_size}")
|
141
141
|
# if boxes:
|
142
142
|
# x1, y1, x2, y2 = box
|
143
143
|
# boxes.append({'sentence': sentence, 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2, 'fontSize': font_size})
|
@@ -383,7 +383,38 @@ def get_screenshot_base64(compression=75, width=None, height=None):
|
|
383
383
|
except Exception as e:
|
384
384
|
logger.error(f"Error getting screenshot: {e}")
|
385
385
|
return None
|
386
|
+
|
387
|
+
|
388
|
+
def get_screenshot_PIL(source_name=None, compression=75, img_format='png', width=None, height=None, retry=3):
|
389
|
+
import io
|
390
|
+
import base64
|
391
|
+
from PIL import Image
|
392
|
+
if not source_name:
|
393
|
+
source_name = get_active_source().get('sourceName', None)
|
394
|
+
if not source_name:
|
395
|
+
logger.error("No active source found in the current scene.")
|
396
|
+
return None
|
397
|
+
while True:
|
398
|
+
response = client.get_source_screenshot(name=source_name, img_format=img_format, quality=compression, width=width, height=height)
|
399
|
+
try:
|
400
|
+
response.image_data = response.image_data.split(',', 1)[-1] # Remove data:image/png;base64, prefix if present
|
401
|
+
except AttributeError:
|
402
|
+
retry -= 1
|
403
|
+
if retry <= 0:
|
404
|
+
logger.error(f"Error getting screenshot: {response}")
|
405
|
+
return None
|
406
|
+
continue
|
407
|
+
if response and response.image_data:
|
408
|
+
image_data = response.image_data.split(',', 1)[-1] # Remove data:image/png;base64, prefix if present
|
409
|
+
image_data = base64.b64decode(image_data)
|
410
|
+
img = Image.open(io.BytesIO(image_data)).convert("RGBA")
|
411
|
+
# if width and height:
|
412
|
+
# img = img.resize((width, height), Image.Resampling.LANCZOS)
|
413
|
+
return img
|
414
|
+
return None
|
386
415
|
|
416
|
+
|
417
|
+
|
387
418
|
|
388
419
|
def update_current_game():
|
389
420
|
gsm_state.current_game = get_current_scene()
|
@@ -433,8 +464,47 @@ def main():
|
|
433
464
|
disconnect_from_obs()
|
434
465
|
|
435
466
|
if __name__ == '__main__':
|
467
|
+
from mss import mss
|
436
468
|
logging.basicConfig(level=logging.INFO)
|
437
469
|
# main()
|
438
470
|
connect_to_obs_sync()
|
439
|
-
|
471
|
+
# i = 100
|
472
|
+
# for i in range(1, 100):
|
473
|
+
# print(f"Getting screenshot {i}")
|
474
|
+
# start = time.time()
|
475
|
+
# # get_screenshot(compression=95)
|
476
|
+
# # get_screenshot_base64(compression=95, width=1280, height=720)
|
477
|
+
|
478
|
+
# img = get_screenshot_PIL(compression=i, img_format='jpg', width=1280, height=720)
|
479
|
+
# end = time.time()
|
480
|
+
# print(f"Time taken to get screenshot with compression {i}: {end - start} seconds")
|
481
|
+
|
482
|
+
# for i in range(1, 100):
|
483
|
+
# print(f"Getting screenshot {i}")
|
484
|
+
# start = time.time()
|
485
|
+
# # get_screenshot(compression=95)
|
486
|
+
# # get_screenshot_base64(compression=95, width=1280, height=720)
|
487
|
+
|
488
|
+
# img = get_screenshot_PIL(compression=i, img_format='jpg', width=2560, height=1440)
|
489
|
+
# end = time.time()
|
490
|
+
# print(f"Time taken to get screenshot full sized jpg with compression {i}: {end - start} seconds")
|
491
|
+
|
492
|
+
# png_img = get_screenshot_PIL(compression=75, img_format='png', width=1280, height=720)
|
493
|
+
|
494
|
+
# jpg_img = get_screenshot_PIL(compression=100, img_format='jpg', width=2560, height=1440)
|
495
|
+
|
496
|
+
# png_img.show()
|
497
|
+
# jpg_img.show()
|
498
|
+
|
499
|
+
# start = time.time()
|
500
|
+
# with mss() as sct:
|
501
|
+
# monitor = sct.monitors[1]
|
502
|
+
# sct_img = sct.grab(monitor)
|
503
|
+
# img = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
|
504
|
+
# img.show()
|
505
|
+
# end = time.time()
|
506
|
+
# print(f"Time taken to get screenshot with mss: {end - start} seconds")
|
507
|
+
|
508
|
+
|
509
|
+
# print(get_screenshot_base64(compression=75, width=1280, height=720))
|
440
510
|
|
@@ -436,7 +436,7 @@ class GoogleLens:
|
|
436
436
|
# res += '\n'
|
437
437
|
|
438
438
|
if return_coords:
|
439
|
-
x = (True, res,
|
439
|
+
x = (True, res, response_dict)
|
440
440
|
else:
|
441
441
|
x = (True, res)
|
442
442
|
|
@@ -887,7 +887,28 @@ class OneOCR:
|
|
887
887
|
except:
|
888
888
|
logger.warning('Error reading URL from config, OneOCR will not work!')
|
889
889
|
|
890
|
-
def
|
890
|
+
def get_regex(self, lang):
|
891
|
+
if lang == "ja":
|
892
|
+
self.regex = re.compile(r'[\u3041-\u3096\u30A1-\u30FA\u4E00-\u9FFF]')
|
893
|
+
elif lang == "zh":
|
894
|
+
self.regex = re.compile(r'[\u4E00-\u9FFF]')
|
895
|
+
elif lang == "ko":
|
896
|
+
self.regex = re.compile(r'[\uAC00-\uD7AF]')
|
897
|
+
elif lang == "ar":
|
898
|
+
self.regex = re.compile(r'[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]')
|
899
|
+
elif lang == "ru":
|
900
|
+
self.regex = re.compile(r'[\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F\u1C80-\u1C8F]')
|
901
|
+
elif lang == "el":
|
902
|
+
self.regex = re.compile(r'[\u0370-\u03FF\u1F00-\u1FFF]')
|
903
|
+
elif lang == "he":
|
904
|
+
self.regex = re.compile(r'[\u0590-\u05FF\uFB1D-\uFB4F]')
|
905
|
+
elif lang == "th":
|
906
|
+
self.regex = re.compile(r'[\u0E00-\u0E7F]')
|
907
|
+
else:
|
908
|
+
self.regex = re.compile(
|
909
|
+
r'[a-zA-Z\u00C0-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u1D00-\u1D7F\u1D80-\u1DBF\u1E00-\u1EFF\u2C60-\u2C7F\uA720-\uA7FF\uAB30-\uAB6F]')
|
910
|
+
|
911
|
+
def __call__(self, img, furigana_filter_sensitivity=0, return_coords=False):
|
891
912
|
lang = get_ocr_language()
|
892
913
|
if lang != self.initial_lang:
|
893
914
|
self.initial_lang = lang
|
@@ -911,6 +932,10 @@ class OneOCR:
|
|
911
932
|
json.dump(ocr_resp, f, indent=4, ensure_ascii=False)
|
912
933
|
# print(json.dumps(ocr_resp))
|
913
934
|
filtered_lines = [line for line in ocr_resp['lines'] if self.regex.search(line['text'])]
|
935
|
+
x_coords = [line['bounding_rect'][f'x{i}'] for line in filtered_lines for i in range(1, 5)]
|
936
|
+
y_coords = [line['bounding_rect'][f'y{i}'] for line in filtered_lines for i in range(1, 5)]
|
937
|
+
if x_coords and y_coords:
|
938
|
+
crop_coords = (min(x_coords) - 5, min(y_coords) - 5, max(x_coords) + 5, max(y_coords) + 5)
|
914
939
|
# logger.info(filtered_lines)
|
915
940
|
res = ''
|
916
941
|
skipped = []
|
@@ -964,30 +989,6 @@ class OneOCR:
|
|
964
989
|
# else:
|
965
990
|
# continue
|
966
991
|
# res += '\n'
|
967
|
-
elif sentence_to_check:
|
968
|
-
lines_to_build_area = []
|
969
|
-
widths = []
|
970
|
-
heights = []
|
971
|
-
for line in ocr_resp['lines']:
|
972
|
-
print(line['text'])
|
973
|
-
if sentence_to_check in line['text'] or line['text'] in sentence_to_check or rapidfuzz.fuzz.partial_ratio(sentence_to_check, line['text']) > 50:
|
974
|
-
lines_to_build_area.append(line)
|
975
|
-
res += line['text']
|
976
|
-
for word in line['words']:
|
977
|
-
widths.append(word['bounding_rect']['x2'] - word['bounding_rect']['x1'])
|
978
|
-
heights.append(word['bounding_rect']['y3'] - word['bounding_rect']['y1'])
|
979
|
-
|
980
|
-
x_coords = [line['bounding_rect'][f'x{i}'] for line in lines_to_build_area for i in
|
981
|
-
range(1, 5)]
|
982
|
-
y_coords = [line['bounding_rect'][f'y{i}'] for line in lines_to_build_area for i in
|
983
|
-
range(1, 5)]
|
984
|
-
if widths:
|
985
|
-
avg_width = sum(widths) / len(widths)
|
986
|
-
if heights:
|
987
|
-
avg_height = sum(heights) / len(heights)
|
988
|
-
if x_coords and y_coords:
|
989
|
-
crop_coords = (
|
990
|
-
min(x_coords) - 5, min(y_coords) - 5, max(x_coords) + 5, max(y_coords) + 5)
|
991
992
|
elif return_coords:
|
992
993
|
for line in filtered_lines:
|
993
994
|
for word in line['words']:
|
@@ -998,10 +999,6 @@ class OneOCR:
|
|
998
999
|
boxes.append(box)
|
999
1000
|
res = ocr_resp['text']
|
1000
1001
|
else:
|
1001
|
-
x_coords = [line['bounding_rect'][f'x{i}'] for line in filtered_lines for i in range(1, 5)]
|
1002
|
-
y_coords = [line['bounding_rect'][f'y{i}'] for line in filtered_lines for i in range(1, 5)]
|
1003
|
-
if x_coords and y_coords:
|
1004
|
-
crop_coords = (min(x_coords) - 5, min(y_coords) - 5, max(x_coords) + 5, max(y_coords) + 5)
|
1005
1002
|
res = ocr_resp['text']
|
1006
1003
|
|
1007
1004
|
except RuntimeError as e:
|
@@ -1019,7 +1016,7 @@ class OneOCR:
|
|
1019
1016
|
|
1020
1017
|
res = res.json()['text']
|
1021
1018
|
if return_coords:
|
1022
|
-
x = (True, res,
|
1019
|
+
x = (True, res, filtered_lines)
|
1023
1020
|
else:
|
1024
1021
|
x = (True, res, crop_coords)
|
1025
1022
|
if is_path:
|
@@ -44,7 +44,6 @@ import queue
|
|
44
44
|
from datetime import datetime
|
45
45
|
from PIL import Image, ImageDraw, UnidentifiedImageError
|
46
46
|
from loguru import logger
|
47
|
-
from pynput import keyboard
|
48
47
|
from desktop_notifier import DesktopNotifierSync
|
49
48
|
import psutil
|
50
49
|
|
@@ -384,6 +383,7 @@ class TextFiltering:
|
|
384
383
|
block_filtered = self.latin_extended_regex.findall(block)
|
385
384
|
else:
|
386
385
|
block_filtered = self.latin_extended_regex.findall(block)
|
386
|
+
|
387
387
|
if block_filtered:
|
388
388
|
orig_text_filtered.append(''.join(block_filtered))
|
389
389
|
else:
|
@@ -547,39 +547,6 @@ class ScreenshotThread(threading.Thread):
|
|
547
547
|
else:
|
548
548
|
raise ValueError('Window capture is only currently supported on Windows and macOS')
|
549
549
|
|
550
|
-
def __del__(self):
|
551
|
-
if self.macos_window_tracker_instance:
|
552
|
-
self.macos_window_tracker_instance.join()
|
553
|
-
elif self.windows_window_tracker_instance:
|
554
|
-
self.windows_window_tracker_instance.join()
|
555
|
-
|
556
|
-
def setup_persistent_windows_window_tracker(self):
|
557
|
-
global window_open
|
558
|
-
window_open = False
|
559
|
-
def setup_tracker():
|
560
|
-
global window_open
|
561
|
-
self.window_handle, window_title = self.get_windows_window_handle(self.screen_capture_window)
|
562
|
-
|
563
|
-
if not self.window_handle:
|
564
|
-
# print(f"Window '{screen_capture_window}' not found.")
|
565
|
-
return
|
566
|
-
|
567
|
-
set_dpi_awareness()
|
568
|
-
window_open = True
|
569
|
-
self.windows_window_tracker_instance = threading.Thread(target=self.windows_window_tracker)
|
570
|
-
self.windows_window_tracker_instance.start()
|
571
|
-
logger.opt(ansi=True).info(f'Selected window: {window_title}')
|
572
|
-
|
573
|
-
while not terminated:
|
574
|
-
if not window_open:
|
575
|
-
try:
|
576
|
-
setup_tracker()
|
577
|
-
except ValueError as e:
|
578
|
-
logger.error(f"Error setting up persistent windows window tracker: {e}")
|
579
|
-
break
|
580
|
-
time.sleep(5)
|
581
|
-
|
582
|
-
|
583
550
|
def get_windows_window_handle(self, window_title):
|
584
551
|
def callback(hwnd, window_title_part):
|
585
552
|
window_title = win32gui.GetWindowText(hwnd)
|
@@ -602,7 +569,7 @@ class ScreenshotThread(threading.Thread):
|
|
602
569
|
|
603
570
|
def windows_window_tracker(self):
|
604
571
|
found = True
|
605
|
-
while not terminated
|
572
|
+
while not terminated:
|
606
573
|
found = win32gui.IsWindow(self.window_handle)
|
607
574
|
if not found:
|
608
575
|
break
|
@@ -872,18 +839,9 @@ class OBSScreenshotThread(threading.Thread):
|
|
872
839
|
image_queue.put((result, True))
|
873
840
|
|
874
841
|
def connect_obs(self):
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
host=get_config().obs.host,
|
879
|
-
port=get_config().obs.port,
|
880
|
-
password=get_config().obs.password,
|
881
|
-
timeout=10
|
882
|
-
)
|
883
|
-
logger.info("Connected to OBS WebSocket.")
|
884
|
-
except Exception as e:
|
885
|
-
logger.error(f"Failed to connect to OBS: {e}")
|
886
|
-
self.obs_client = None
|
842
|
+
import GameSentenceMiner.obs as obs
|
843
|
+
obs.connect_to_obs_sync()
|
844
|
+
|
887
845
|
|
888
846
|
def run(self):
|
889
847
|
global last_image
|
@@ -895,7 +853,7 @@ class OBSScreenshotThread(threading.Thread):
|
|
895
853
|
def init_config(source=None, scene=None):
|
896
854
|
obs.update_current_game()
|
897
855
|
self.current_source = source if source else obs.get_active_source()
|
898
|
-
self.current_source_name = self.current_source.get(
|
856
|
+
self.current_source_name = self.current_source.get("sourceName") or None
|
899
857
|
self.current_scene = scene if scene else obs.get_current_game()
|
900
858
|
self.ocr_config = get_scene_ocr_config()
|
901
859
|
self.ocr_config.scale_to_custom_size(self.width, self.height)
|
@@ -927,20 +885,20 @@ class OBSScreenshotThread(threading.Thread):
|
|
927
885
|
if not self.ocr_config:
|
928
886
|
time.sleep(1)
|
929
887
|
continue
|
888
|
+
|
889
|
+
if not self.current_source_name:
|
890
|
+
obs.update_current_game()
|
891
|
+
self.current_source = obs.get_active_source()
|
892
|
+
self.current_source_name = self.current_source.get("sourceName") or None
|
930
893
|
|
931
894
|
try:
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
height=self.height,
|
938
|
-
)
|
895
|
+
if not self.current_source_name:
|
896
|
+
logger.error("No active source found in the current scene.")
|
897
|
+
time.sleep(1)
|
898
|
+
continue
|
899
|
+
img = obs.get_screenshot_PIL(source_name=self.current_source_name, width=self.width, height=self.height, img_format='jpg', compression=90)
|
939
900
|
|
940
|
-
if
|
941
|
-
image_data = base64.b64decode(response.image_data.split(",")[1])
|
942
|
-
img = Image.open(io.BytesIO(image_data)).convert("RGBA")
|
943
|
-
|
901
|
+
if img is not None:
|
944
902
|
if not img.getbbox():
|
945
903
|
logger.info("OBS Not Capturing anything, sleeping.")
|
946
904
|
time.sleep(1)
|
@@ -1118,11 +1076,10 @@ def signal_handler(sig, frame):
|
|
1118
1076
|
|
1119
1077
|
|
1120
1078
|
def on_window_closed(alive):
|
1121
|
-
global terminated
|
1079
|
+
global terminated
|
1122
1080
|
if not (alive or terminated):
|
1123
1081
|
logger.info('Window closed or error occurred, terminated!')
|
1124
|
-
|
1125
|
-
# terminated = True
|
1082
|
+
terminated = True
|
1126
1083
|
|
1127
1084
|
|
1128
1085
|
def on_screenshot_combo():
|
@@ -1464,8 +1421,12 @@ def run(read_from=None,
|
|
1464
1421
|
read_from_readable.append(f'directory {read_from_path}')
|
1465
1422
|
|
1466
1423
|
if len(key_combos) > 0:
|
1467
|
-
|
1468
|
-
|
1424
|
+
try:
|
1425
|
+
from pynput import keyboard
|
1426
|
+
key_combo_listener = keyboard.GlobalHotKeys(key_combos)
|
1427
|
+
key_combo_listener.start()
|
1428
|
+
except ImportError:
|
1429
|
+
pass
|
1469
1430
|
|
1470
1431
|
if write_to in ('clipboard', 'websocket', 'callback'):
|
1471
1432
|
write_to_readable = write_to
|
{gamesentenceminer-2.12.2 → gamesentenceminer-2.12.4}/GameSentenceMiner/util/downloader/oneocr_dl.py
RENAMED
@@ -239,11 +239,12 @@ class Downloader:
|
|
239
239
|
# Example usage:
|
240
240
|
if __name__ == "__main__":
|
241
241
|
downloader = Downloader()
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
242
|
+
downloader.download_and_extract()
|
243
|
+
# if downloader.download_and_extract():
|
244
|
+
# print("SnippingTool files are ready.")
|
245
|
+
# print("Press Ctrl+C or X on window to exit.")
|
246
|
+
# # input()
|
247
|
+
# else:
|
248
|
+
# # print("Failed to download and extract SnippingTool files. You may need to follow instructions at https://github.com/AuroraWright/oneocr")
|
249
|
+
# print("Press Ctrl+C or X on window to exit.")
|
250
|
+
# input()
|