mirror of
https://github.com/jjaldridge2009/Project_Xs.git
synced 2024-10-02 13:27:13 +02:00
tid/sid support to gui
This commit is contained in:
parent
e7f85ecebb
commit
7cf0b0a943
@ -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
|
||||
}
|
@ -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
|
||||
|
||||
@ -287,6 +291,17 @@ class Application(tk.Frame):
|
||||
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
|
||||
blinks, intervals, offset_time = rngtool.tracking_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"])
|
||||
@ -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]]
|
||||
|
@ -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)<size:
|
||||
if tk_window != None:
|
||||
if not tk_window.tidsiding:
|
||||
tk_window.progress['text'] = "0/0"
|
||||
tk_window.monitor_tk_buffer = None
|
||||
tk_window.monitor_tk = None
|
||||
exit()
|
||||
_, frame = video.read()
|
||||
if not MonitorWindow:
|
||||
f_size = frame.shape[::-1]
|
||||
@ -231,12 +238,14 @@ def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindo
|
||||
res = cv2.matchTemplate(roi,eye,cv2.TM_CCOEFF_NORMED)
|
||||
_, match, _, max_loc = cv2.minMaxLoc(res)
|
||||
|
||||
if 0.4<match<0.85:
|
||||
if 0.4<match<th:
|
||||
cv2.rectangle(frame,(roi_x,roi_y), (roi_x+roi_w,roi_y+roi_h), 255, 2)
|
||||
if state==IDLE:
|
||||
interval = (time_counter - prev_time)
|
||||
intervals.append(interval)
|
||||
print(f"Intervals {len(intervals)}/{size}")
|
||||
if tk_window != None:
|
||||
tk_window.progress['text'] = f"{len(intervals)}/{size}"
|
||||
state = SINGLE
|
||||
prev_time = time_counter
|
||||
elif state==SINGLE:
|
||||
@ -248,12 +257,26 @@ def tracking_poke_blink(img, roi_x, roi_y, roi_w, roi_h, size = 60, MonitorWindo
|
||||
if state!=IDLE and time_counter - prev_time>0.7:
|
||||
state = IDLE
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user