From 8af665dd60db94e8f0fa7a922aa384b0f7f11445 Mon Sep 17 00:00:00 2001 From: Lincoln-LM Date: Fri, 7 Jan 2022 10:05:59 -0700 Subject: [PATCH] live camera preview --- src/player_blink_gui.py | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/player_blink_gui.py b/src/player_blink_gui.py index 69171e7..5321df0 100644 --- a/src/player_blink_gui.py +++ b/src/player_blink_gui.py @@ -430,6 +430,7 @@ class Application(tk.Frame): def previewing_work(self): last_frame_tk = None + last_camera = self.config_json["camera"] if self.config_json["MonitorWindow"]: from windowcapture import WindowCapture @@ -451,29 +452,42 @@ class Application(tk.Frame): while self.previewing: + if self.config_json["camera"] != last_camera: + video = cv2.VideoCapture(self.config_json["camera"],backend) + video.set(cv2.CAP_PROP_FRAME_WIDTH,1920) + video.set(cv2.CAP_PROP_FRAME_HEIGHT,1080) + video.set(cv2.CAP_PROP_BUFFERSIZE,1) + print(f"camera {self.config_json['camera']}") + last_camera = self.config_json["camera"] + eye = self.player_eye w, h = eye.shape[::-1] roi_x, roi_y, roi_w, roi_h = self.config_json["view"] _, frame = video.read() - if not self.config_json["MonitorWindow"]: - frame = cv2.resize(frame,(960,540)) - roi = cv2.cvtColor(frame[roi_y:roi_y+roi_h,roi_x:roi_x+roi_w],cv2.COLOR_RGB2GRAY) - res = cv2.matchTemplate(roi,eye,cv2.TM_CCOEFF_NORMED) - _, match, _, max_loc = cv2.minMaxLoc(res) + if frame is not None: + if not self.config_json["MonitorWindow"]: + size = frame.shape[::-1] + _, fw, fh = size + if fw >= 1920: + frame = cv2.resize(frame,(960,round(fh/fw*960))) - cv2.rectangle(frame,(roi_x,roi_y), (roi_x+roi_w,roi_y+roi_h), (0,0,255), 2) - if 0.01