GameSentenceMiner 2.6.5__py3-none-any.whl → 2.7.0__py3-none-any.whl
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/anki.py +2 -2
- GameSentenceMiner/configuration.py +3 -1
- GameSentenceMiner/gametext.py +28 -14
- GameSentenceMiner/gsm.py +8 -4
- GameSentenceMiner/obs.py +41 -8
- GameSentenceMiner/ocr/__init__.py +0 -0
- GameSentenceMiner/ocr/ocrconfig.py +130 -0
- GameSentenceMiner/ocr/owocr_area_selector.py +275 -0
- GameSentenceMiner/ocr/owocr_helper.py +306 -0
- GameSentenceMiner/owocr/owocr/__init__.py +1 -0
- GameSentenceMiner/owocr/owocr/__main__.py +8 -0
- GameSentenceMiner/owocr/owocr/config.py +134 -0
- GameSentenceMiner/owocr/owocr/lens_betterproto.py +1238 -0
- GameSentenceMiner/owocr/owocr/ocr.py +975 -0
- GameSentenceMiner/owocr/owocr/run.py +1096 -0
- GameSentenceMiner/owocr/owocr/screen_coordinate_picker.py +100 -0
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/METADATA +2 -2
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/RECORD +22 -11
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/WHEEL +0 -0
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/entry_points.txt +0 -0
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/licenses/LICENSE +0 -0
- {gamesentenceminer-2.6.5.dist-info → gamesentenceminer-2.7.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
import os
|
2
|
+
import configparser
|
3
|
+
import argparse
|
4
|
+
import textwrap
|
5
|
+
import urllib.request
|
6
|
+
|
7
|
+
parser = argparse.ArgumentParser(prog='owocr', description=textwrap.dedent('''\
|
8
|
+
Runs OCR in the background.
|
9
|
+
It can read images copied to the system clipboard or placed in a directory, images sent via a websocket or a Unix domain socket, or directly capture a screen (or a portion of it) or a window.
|
10
|
+
Recognized texts can be either saved to system clipboard, appended to a text file or sent via a websocket.
|
11
|
+
'''))
|
12
|
+
|
13
|
+
parser.add_argument('-r', '--read_from', type=str, default=argparse.SUPPRESS,
|
14
|
+
help='Specifies where to read input images from. Can be either "clipboard", "websocket", "unixsocket" (on macOS/Linux), "screencapture", or a path to a directory.')
|
15
|
+
parser.add_argument('-w', '--write_to', type=str, default=argparse.SUPPRESS,
|
16
|
+
help='Specifies where to save recognized texts to. Can be either "clipboard", "websocket", or a path to a text file.')
|
17
|
+
parser.add_argument('-e', '--engine', type=str, default=argparse.SUPPRESS,
|
18
|
+
help='OCR engine to use. Available: "mangaocr", "glens", "glensweb", "bing", "gvision", "avision", "alivetext", "azure", "winrtocr", "oneocr", "easyocr", "rapidocr", "ocrspace".')
|
19
|
+
parser.add_argument('-p', '--pause_at_startup', action='store_true', default=argparse.SUPPRESS,
|
20
|
+
help='Pause at startup.')
|
21
|
+
parser.add_argument('-i', '--ignore_flag', action='store_true', default=argparse.SUPPRESS,
|
22
|
+
help='Process flagged clipboard images (images that are copied to the clipboard with the *ocr_ignore* string).')
|
23
|
+
parser.add_argument('-d', '--delete_images', action='store_true', default=argparse.SUPPRESS,
|
24
|
+
help='Delete image files after processing when reading from a directory.')
|
25
|
+
parser.add_argument('-n', '--notifications', action='store_true', default=argparse.SUPPRESS,
|
26
|
+
help='Show an operating system notification with the detected text.')
|
27
|
+
parser.add_argument('-a', '--auto_pause', type=float, default=argparse.SUPPRESS,
|
28
|
+
help='Automatically pause the program after the specified amount of seconds since the last successful text recognition. Will be ignored when reading with screen capture. 0 to disable.')
|
29
|
+
parser.add_argument('-cp', '--combo_pause', type=str, default=argparse.SUPPRESS,
|
30
|
+
help='Specifies a combo to wait on for pausing the program. As an example: "<ctrl>+<shift>+p". The list of keys can be found here: https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key')
|
31
|
+
parser.add_argument('-cs', '--combo_engine_switch', type=str, default=argparse.SUPPRESS,
|
32
|
+
help='Specifies a combo to wait on for switching the OCR engine. As an example: "<ctrl>+<shift>+a". To be used with combo_pause. The list of keys can be found here: https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key')
|
33
|
+
parser.add_argument('-sa', '--screen_capture_area', type=str, default=argparse.SUPPRESS,
|
34
|
+
help='Specifies area to target when reading with screen capture. Can be either empty (automatic selector), a set of coordinates (x,y,width,height), "screen_N" (captures a whole screen, where N is the screen number starting from 1) or a window name (the first matching window title will be used).')
|
35
|
+
parser.add_argument('-sd', '--screen_capture_delay_secs', type=float, default=argparse.SUPPRESS,
|
36
|
+
help='Specifies the delay (in seconds) between screenshots when reading with screen capture.')
|
37
|
+
parser.add_argument('-sw', '--screen_capture_only_active_windows', action='store_true', default=argparse.SUPPRESS,
|
38
|
+
help="When reading with screen capture and screen_capture_area is a window name, specifies whether to only target the window while it's active.")
|
39
|
+
parser.add_argument('-sc', '--screen_capture_combo', type=str, default=argparse.SUPPRESS,
|
40
|
+
help='When reading with screen capture, specifies a combo to wait on for taking a screenshot instead of using the delay. As an example: "<ctrl>+<shift>+s". The list of keys can be found here: https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key')
|
41
|
+
|
42
|
+
class Config:
|
43
|
+
has_config = False
|
44
|
+
downloaded_config = False
|
45
|
+
config_path = os.path.join(os.path.expanduser('~'),'.config','owocr_config.ini')
|
46
|
+
__general_config = {}
|
47
|
+
__engine_config = {}
|
48
|
+
__default_config = {
|
49
|
+
'read_from': 'clipboard',
|
50
|
+
'write_to': 'clipboard',
|
51
|
+
'engine': '',
|
52
|
+
'pause_at_startup': False,
|
53
|
+
'auto_pause' : 0,
|
54
|
+
'ignore_flag': False,
|
55
|
+
'delete_images': False,
|
56
|
+
'engines': [],
|
57
|
+
'logger_format': '<green>{time:HH:mm:ss.SSS}</green> | <level>{message}</level>',
|
58
|
+
'engine_color': 'cyan',
|
59
|
+
'delay_secs': 0.5,
|
60
|
+
'websocket_port': 7331,
|
61
|
+
'notifications': False,
|
62
|
+
'combo_pause': '',
|
63
|
+
'combo_engine_switch': '',
|
64
|
+
'screen_capture_area': '',
|
65
|
+
'screen_capture_delay_secs': 3,
|
66
|
+
'screen_capture_only_active_windows': True,
|
67
|
+
'screen_capture_combo': ''
|
68
|
+
}
|
69
|
+
|
70
|
+
def __parse(self, value):
|
71
|
+
value = value.strip()
|
72
|
+
if value.lower() == 'false':
|
73
|
+
return False
|
74
|
+
if value.lower() == 'true':
|
75
|
+
return True
|
76
|
+
try:
|
77
|
+
int(value)
|
78
|
+
return int(value)
|
79
|
+
except ValueError:
|
80
|
+
pass
|
81
|
+
try:
|
82
|
+
float(value)
|
83
|
+
return float(value)
|
84
|
+
except ValueError:
|
85
|
+
pass
|
86
|
+
return value
|
87
|
+
|
88
|
+
def __init__(self, parse_args=True):
|
89
|
+
if parse_args:
|
90
|
+
args = parser.parse_args()
|
91
|
+
self.__provided_cli_args = vars(args)
|
92
|
+
else:
|
93
|
+
self.__provided_cli_args = {}
|
94
|
+
config = configparser.ConfigParser()
|
95
|
+
res = config.read(self.config_path)
|
96
|
+
|
97
|
+
if len(res) == 0:
|
98
|
+
try:
|
99
|
+
config_folder = os.path.join(os.path.expanduser('~'),'.config')
|
100
|
+
if not os.path.isdir(config_folder):
|
101
|
+
os.makedirs(config_folder)
|
102
|
+
urllib.request.urlretrieve('https://github.com/AuroraWright/owocr/raw/master/owocr_config.ini', self.config_path)
|
103
|
+
self.downloaded_config = True
|
104
|
+
finally:
|
105
|
+
return
|
106
|
+
|
107
|
+
self.has_config = True
|
108
|
+
for key in config:
|
109
|
+
if key == 'general':
|
110
|
+
for sub_key in config[key]:
|
111
|
+
self.__general_config[sub_key.lower()] = self.__parse(config[key][sub_key])
|
112
|
+
elif key != 'DEFAULT':
|
113
|
+
self.__engine_config[key.lower()] = {}
|
114
|
+
for sub_key in config[key]:
|
115
|
+
self.__engine_config[key.lower()][sub_key.lower()] = self.__parse(config[key][sub_key])
|
116
|
+
|
117
|
+
def get_general(self, value):
|
118
|
+
if self.__provided_cli_args.get(value, None) is not None:
|
119
|
+
return self.__provided_cli_args[value]
|
120
|
+
try:
|
121
|
+
return self.__general_config[value]
|
122
|
+
except KeyError:
|
123
|
+
if value in self.__default_config:
|
124
|
+
return self.__default_config[value]
|
125
|
+
else:
|
126
|
+
return None
|
127
|
+
|
128
|
+
def get_engine(self, value):
|
129
|
+
try:
|
130
|
+
return self.__engine_config[value]
|
131
|
+
except KeyError:
|
132
|
+
return None
|
133
|
+
|
134
|
+
config = Config(False)
|