diff --git a/doc/manual_en_google_translated.docx b/doc/manual_en_google_translated.docx index f4575e1..b465670 100644 Binary files a/doc/manual_en_google_translated.docx and b/doc/manual_en_google_translated.docx differ diff --git a/doc/manual_en_google_translated.pdf b/doc/manual_en_google_translated.pdf index e858506..5278043 100644 Binary files a/doc/manual_en_google_translated.pdf and b/doc/manual_en_google_translated.pdf differ diff --git a/doc/manual_ru.pdf b/doc/manual_ru.pdf index 892b04d..400a044 100644 Binary files a/doc/manual_ru.pdf and b/doc/manual_ru.pdf differ diff --git a/doc/manual_ru_source.docx b/doc/manual_ru_source.docx index d9543a6..b6fc98d 100644 Binary files a/doc/manual_ru_source.docx and b/doc/manual_ru_source.docx differ diff --git a/interact/interact.py b/interact/interact.py index d9a5932..6034520 100644 --- a/interact/interact.py +++ b/interact/interact.py @@ -31,7 +31,11 @@ class InteractBase(object): self.mouse_events = {} self.key_events = {} self.pg_bar = None + self.focus_wnd_name = None + def is_support_windows(self): + return False + def is_colab(self): return False @@ -40,7 +44,10 @@ class InteractBase(object): def on_create_window (self, wnd_name): raise NotImplemented - + + def on_destroy_window (self, wnd_name): + raise NotImplemented + def on_show_image (self, wnd_name, img): raise NotImplemented @@ -66,17 +73,39 @@ class InteractBase(object): if wnd_name not in self.named_windows: #we will show window only on first show_image self.named_windows[wnd_name] = 0 + self.focus_wnd_name = wnd_name else: print("named_window: ", wnd_name, " already created.") def destroy_all_windows(self): - if len( self.named_windows ) != 0: - self.on_destroy_all_windows() + if len( self.named_windows ) != 0: + self.on_destroy_all_windows() self.named_windows = {} self.capture_mouse_windows = {} self.capture_keys_windows = {} self.mouse_events = {} self.key_events = {} - + self.focus_wnd_name = None + + def destroy_window(self, wnd_name): + if wnd_name in self.named_windows: + self.on_destroy_window(wnd_name) + self.named_windows.pop(wnd_name) + + if wnd_name == self.focus_wnd_name: + self.focus_wnd_name = list(self.named_windows.keys())[-1] if len( self.named_windows ) != 0 else None + + if wnd_name in self.capture_mouse_windows: + self.capture_mouse_windows.pop(wnd_name) + + if wnd_name in self.capture_keys_windows: + self.capture_keys_windows.pop(wnd_name) + + if wnd_name in self.mouse_events: + self.mouse_events.pop(wnd_name) + + if wnd_name in self.key_events: + self.key_events.pop(wnd_name) + def show_image(self, wnd_name, img): if wnd_name in self.named_windows: if self.named_windows[wnd_name] == 0: @@ -248,12 +277,18 @@ class InteractBase(object): class InteractDesktop(InteractBase): - + + def is_support_windows(self): + return True + def on_destroy_all_windows(self): cv2.destroyAllWindows() def on_create_window (self, wnd_name): cv2.namedWindow(wnd_name) + + def on_destroy_window (self, wnd_name): + cv2.destroyWindow(wnd_name) def on_show_image (self, wnd_name, img): cv2.imshow (wnd_name, img) @@ -305,14 +340,16 @@ class InteractDesktop(InteractBase): time.sleep(sleep_time) if has_capture_keys and ord_key != -1: - for wnd_name in self.capture_keys_windows: - self.add_key_event (wnd_name, ord_key, False, False, shift_pressed) + self.add_key_event ( self.focus_wnd_name, ord_key, False, False, shift_pressed) def on_wait_any_key(self): cv2.waitKey(0) class InteractColab(InteractBase): + def is_support_windows(self): + return False + def is_colab(self): return True @@ -323,6 +360,9 @@ class InteractColab(InteractBase): def on_create_window (self, wnd_name): pass #clear_output() + + def on_destroy_window (self, wnd_name): + pass def on_show_image (self, wnd_name, img): pass diff --git a/models/ModelBase.py b/models/ModelBase.py index 2c2dc69..379d305 100644 --- a/models/ModelBase.py +++ b/models/ModelBase.py @@ -85,6 +85,11 @@ class ModelBase(object): else: self.options['write_preview_history'] = self.options.get('write_preview_history', False) + if self.iter == 0 and self.options['write_preview_history'] and io.is_support_windows(): + choose_preview_history = io.input_bool("Choose image for the preview history? (y/n skip:%s) : " % (yn_str[False]) , False) + else: + choose_preview_history = False + if ask_target_iter: if (self.iter == 0 or ask_override): self.options['target_iter'] = max(0, io.input_int("Target iteration (skip:unlimited/default) : ", 0)) @@ -168,7 +173,35 @@ class ModelBase(object): raise ValueError('training data generator is not subclass of SampleGeneratorBase') if (self.sample_for_preview is None) or (self.iter == 0): - self.sample_for_preview = self.generate_next_sample() + + if self.iter == 0: + if choose_preview_history and io.is_support_windows(): + wnd_name = "[p] - next. [enter] - confirm." + io.named_window(wnd_name) + io.capture_keys(wnd_name) + choosed = False + while not choosed: + self.sample_for_preview = self.generate_next_sample() + preview = self.get_static_preview() + io.show_image( wnd_name, (preview*255).astype(np.uint8) ) + + while True: + key_events = io.get_key_events(wnd_name) + key, chr_key, ctrl_pressed, alt_pressed, shift_pressed = key_events[-1] if len(key_events) > 0 else (0,0,False,False,False) + if key == ord('\n') or key == ord('\r'): + choosed = True + break + elif key == ord('p'): + break + + try: + io.process_messages(0.1) + except KeyboardInterrupt: + choosed = True + + io.destroy_window(wnd_name) + else: + self.sample_for_preview = self.generate_next_sample() model_summary_text = []