From 7cf0b0a943eee4047fed266da9acfe6dcde39efd Mon Sep 17 00:00:00 2001 From: Lincoln-LM Date: Sat, 8 Jan 2022 11:33:23 -0700 Subject: [PATCH] tid/sid support to gui --- configs/config_munchlax.json | 19 +++++++----- src/player_blink_gui.py | 57 ++++++++++++++++++++++++++++++++++++ src/rngtool.py | 41 ++++++++++++++++++++------ 3 files changed, 101 insertions(+), 16 deletions(-) diff --git a/configs/config_munchlax.json b/configs/config_munchlax.json index d547da2..bf154a9 100644 --- a/configs/config_munchlax.json +++ b/configs/config_munchlax.json @@ -3,18 +3,23 @@ "WindowPrefix": "SysDVR-Client [PID ", "image": "./images/munchlax/eye.png", "view": [ - 470, - 430, - 50, - 60 + 487, + 446, + 32, + 44 ], - "thresh": 0.9, - "white_delay": 0, + "thresh": 0.85, + "white_delay": 0.0, "advance_delay": 0, "advance_delay_2": 0, "npc": 0, "pokemon_npc": 0, "timeline_npc": 0, - "crop": [0,0,0,0], + "crop": [ + 0, + 0, + 0, + 0 + ], "camera": 0 } \ No newline at end of file diff --git a/src/player_blink_gui.py b/src/player_blink_gui.py index e4abc7e..358e8b5 100644 --- a/src/player_blink_gui.py +++ b/src/player_blink_gui.py @@ -26,6 +26,7 @@ class Application(tk.Frame): self.previewing = False self.monitoring = False self.reidentifying = False + self.tidsiding = False self.timelining = False self.config_json = {} self.default_config = { @@ -99,6 +100,9 @@ class Application(tk.Frame): self.timeline_button = ttk.Button(self, text="Timeline", command=self.timeline) self.timeline_button.grid(column=3,row=4) + self.tidsid_button = ttk.Button(self, text="TID/SID", command=self.tidsid) + self.tidsid_button.grid(column=3,row=5) + x = y = w = h = 0 th = 0.9 @@ -286,6 +290,17 @@ class Application(tk.Frame): else: self.reidentify_button['text'] = "Reidentify" self.reidentifying = False + + def tidsid(self): + if not self.tidsiding: + self.tidsid_button['text'] = "Stop TID/SID" + self.tidsiding = True + self.tidsiding_thread=threading.Thread(target=self.tidsiding_work) + self.tidsiding_thread.daemon = True + self.tidsiding_thread.start() + else: + self.tidsid_button['text'] = "TID/SID" + self.tidsiding = False def monitoring_work(self): self.tracking = False @@ -381,6 +396,48 @@ class Application(tk.Frame): print(f"advances:{self.advances}, interval:{blink_int}") self.timelining = False + def tidsiding_work(self): + self.tracking = False + munchlax_intervals = rngtool.tracking_poke_blink(self.player_eye, *self.config_json["view"], MonitorWindow=self.config_json["MonitorWindow"], WindowPrefix=self.config_json["WindowPrefix"], crop=self.config_json["crop"], camera=self.config_json["camera"], tk_window=self, th=self.config_json["thresh"], size=64) + self.rng = rngtool.recovByMunchlax(munchlax_intervals) + state = self.rng.getState() + + self.tidsid_button['text'] = "TID/SID" + self.tidsiding = False + self.preview() + + s0 = f"{state[0]:08X}" + s1 = f"{state[1]:08X}" + s2 = f"{state[2]:08X}" + s3 = f"{state[3]:08X}" + + s01 = s0+s1 + s23 = s2+s3 + + print(s01,s23) + print(s0,s1,s2,s3) + self.s0_1_2_3.delete(1.0, tk.END) + self.s01_23.delete(1.0, tk.END) + + self.s0_1_2_3.insert(1.0,s0+"\n"+s1+"\n"+s2+"\n"+s3) + self.s01_23.insert(1.0,s01+"\n"+s23) + + waituntil = time.perf_counter() + ts = time.time() + + print([hex(x) for x in state],ts) + self.tracking = True + while self.tracking: + self.advances += 1 + interval = self.rng.rangefloat(3.0,12.0) + 0.285 + waituntil += interval + + print(f"advances:{self.advances}") + + next_time = waituntil - time.perf_counter() or 0 + time.sleep(next_time) + + def reidentifying_work(self): self.tracking = False state = [int(x,16) for x in self.s0_1_2_3.get(1.0,tk.END).split("\n")[:4]] diff --git a/src/rngtool.py b/src/rngtool.py index 6880b09..a714440 100644 --- a/src/rngtool.py +++ b/src/rngtool.py @@ -135,6 +135,7 @@ def tracking_blink(img, roi_x, roi_y, roi_w, roi_h, th = 0.9, size = 40, Monitor tk_window.progress['text'] = "0/0" frame_tk = None last_frame_tk = None + video.release() return (blinks, intervals, offset_time) def tracking_blink_manual(size = 40, reidentify = False)->Tuple[List[int],List[int],float]: @@ -179,7 +180,7 @@ def tracking_blink_manual(size = 40, reidentify = False)->Tuple[List[int],List[i return (blinks, intervals, offset_time) -def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindow = False, WindowPrefix = "SysDVR-Client [PID ", crop = None, camera = 0)->Tuple[List[int],List[int],float]: +def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 64, th = 0.85, MonitorWindow = False, WindowPrefix = "SysDVR-Client [PID ", crop = None, tk_window = None, camera = 0)->Tuple[List[int],List[int],float]: """measuring the type and interval of pokemon's blinks Returns: @@ -187,6 +188,7 @@ def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindo """ eye = img + last_frame_tk = None if MonitorWindow: from windowcapture import WindowCapture @@ -206,7 +208,6 @@ def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindo video.set(cv2.CAP_PROP_BUFFERSIZE,1) state = IDLE - intervals = [] prev_roi = None prev_time = time.perf_counter() @@ -215,6 +216,12 @@ def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindo # 瞬きの観測 while len(intervals)0.7: state = IDLE - cv2.imshow("view", frame) - keypress = cv2.waitKey(1) - if keypress == ord('q'): - cv2.destroyAllWindows() - exit() - cv2.destroyAllWindows() + if tk_window == None: + print("CV2") + cv2.imshow("view", frame) + keypress = cv2.waitKey(1) + if keypress == ord('q'): + cv2.destroyAllWindows() + exit() + else: + frame_tk = tk_window.cv_image_to_tk(frame) + tk_window.monitor_tk_buffer = last_frame_tk + tk_window.monitor_display_buffer['image'] = tk_window.monitor_tk_buffer + tk_window.monitor_tk = frame_tk + tk_window.monitor_display['image'] = tk_window.monitor_tk + last_frame_tk = frame_tk + if tk_window == None: + cv2.destroyAllWindows() + else: + tk_window.progress['text'] = "0/0" + frame_tk = None + last_frame_tk = None video.release() return intervals