From c70ca9d35cb71ced955abf0f29575cc2b2bc9ffe Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Thu, 18 Dec 2025 17:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- face_rec.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/face_rec.py b/face_rec.py index 61f3b10..99e5ea5 100644 --- a/face_rec.py +++ b/face_rec.py @@ -699,17 +699,16 @@ class FaceRecognitionSystem: try: import screeninfo screen = screeninfo.get_monitors()[0] - # 添加额外边距确保完全覆盖屏幕 - canvas_width = int(screen.width + 40) - canvas_height = int(screen.height + 40) - x_pos = -20 # 负偏移量居中 - y_pos = -20 + canvas_width = int(screen.width) + canvas_height = int(screen.height) + x_pos = 0 + y_pos = 0 except Exception as e: self.logger.warning(f"无法获取屏幕信息,使用默认尺寸: {e}") - canvas_width = max(qr_width * 2, 1960) - canvas_height = max(qr_height, 1120) - x_pos = -20 - y_pos = -20 + canvas_width = max(qr_width * 2, 1920) + canvas_height = max(qr_height, 1080) + x_pos = 0 + y_pos = 0 rendered = self._build_qrcode_instruction_canvas(qr_image, (canvas_width, canvas_height)) if rendered is None: @@ -719,8 +718,17 @@ class FaceRecognitionSystem: scale = min(scale_width, scale_height) new_width = int(qr_width * scale) new_height = int(qr_height * scale) - rendered = cv2.resize(qr_image, (new_width, new_height), interpolation=cv2.INTER_LINEAR) - canvas_width, canvas_height = new_width, new_height + resized_qr = cv2.resize(qr_image, (new_width, new_height), interpolation=cv2.INTER_LINEAR) + + # 创建黑色背景画布,完全填充屏幕 + rendered = np.zeros((canvas_height, canvas_width, 3), dtype=np.uint8) + + # 计算居中位置 + x_offset = (canvas_width - new_width) // 2 + y_offset = (canvas_height - new_height) // 2 + + # 将二维码放在中央 + rendered[y_offset:y_offset+new_height, x_offset:x_offset+new_width] = resized_qr cv2.resizeWindow(self.qrcode_window_name, canvas_width, canvas_height) cv2.moveWindow(self.qrcode_window_name, x_pos, y_pos)