Turn frame stabilization setting into a delay

This commit is contained in:
AuroraWright
2025-10-09 09:34:01 +02:00
parent be8afa6d45
commit 1c83f8c184
2 changed files with 10 additions and 3 deletions

View File

@@ -48,8 +48,8 @@ parser.add_argument('-sd', '--screen_capture_delay_secs', type=float, default=ar
help='Delay (in seconds) between screenshots when reading with screen capture. -1 to disable periodic screenshots.')
parser.add_argument('-sw', '--screen_capture_only_active_windows', type=str2bool, nargs='?', const=True, default=argparse.SUPPRESS,
help="When reading with screen capture and screen_capture_area is a window name, only target the window while it's active.")
parser.add_argument('-sf', '--screen_capture_frame_stabilization', type=str2bool, nargs='?', const=True, default=argparse.SUPPRESS,
help="When reading with screen capture, try waiting until text is stable before processing it.")
parser.add_argument('-sf', '--screen_capture_frame_stabilization', type=float, default=argparse.SUPPRESS,
help="When reading with screen capture, delay to wait until text is stable before processing it. -1 waits for two OCR results to be the same. 0 to disable.")
parser.add_argument('-sc', '--screen_capture_combo', type=str, default=argparse.SUPPRESS,
help='When reading with screen capture, combo to wait on for taking a screenshot. If periodic screenshots are also enabled, any screenshot taken this way bypasses the filtering. Example value: "<ctrl>+<shift>+s". The list of keys can be found here: https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key')
parser.add_argument('-l', '--language', type=str, default=argparse.SUPPRESS,
@@ -86,7 +86,7 @@ class Config:
'screen_capture_area': '',
'screen_capture_delay_secs': -1,
'screen_capture_only_active_windows': True,
'screen_capture_frame_stabilization': True,
'screen_capture_frame_stabilization': -1,
'screen_capture_combo': '',
'screen_capture_old_macos_api': False,
'language': 'ja',

View File

@@ -310,6 +310,7 @@ class TextFiltering:
self.last_frame_text = None
self.stable_frame_text = None
self.processed_stable_frame = False
self.frame_stabilization_timestamp = 0
self.cj_regex = re.compile(r'[\u3041-\u3096\u30A1-\u30FA\u4E00-\u9FFF]')
self.regex = self.get_regex()
self.kana_variants = {
@@ -412,6 +413,8 @@ class TextFiltering:
if frames_match:
if self.processed_stable_frame:
return []
if time.time() - self.frame_stabilization_timestamp < self.frame_stabilization:
return []
changed_lines = self._find_changed_lines_impl(current_result, self.stable_frame_data)
self.processed_stable_frame = True
self.stable_frame_data = copy.deepcopy(current_result)
@@ -419,6 +422,7 @@ class TextFiltering:
else:
self.last_frame_data = copy.deepcopy(current_result)
self.processed_stable_frame = False
self.frame_stabilization_timestamp = time.time()
return []
def _find_changed_lines_impl(self, current_result, previous_result):
@@ -496,6 +500,8 @@ class TextFiltering:
if frames_match:
if self.processed_stable_frame:
return []
if time.time() - self.frame_stabilization_timestamp < self.frame_stabilization:
return []
changed_lines = self._find_changed_lines_text_impl(current_result, self.stable_frame_text, True)
self.processed_stable_frame = True
self.stable_frame_text = current_result
@@ -503,6 +509,7 @@ class TextFiltering:
else:
self.last_frame_text = current_result
self.processed_stable_frame = False
self.frame_stabilization_timestamp = time.time()
return []
def _find_changed_lines_text_impl(self, current_result, previous_stable_text, filtering):