修改二维码的显示尺寸

This commit is contained in:
Tian jianyong 2025-12-28 14:43:47 +08:00
parent 82683d380c
commit be9d9ca88d

View File

@ -160,7 +160,7 @@ class FaceRecognitionSystem:
self.screen_height = screen.height
self.logger.info(f"屏幕尺寸已缓存: {self.screen_width}x{self.screen_height}")
except Exception as e:
self.logger.debug(f"无法获取屏幕尺寸,使用默认尺寸: {e}")
self.logger.warning(f"无法获取屏幕尺寸,使用默认尺寸 1920x1080: {e}")
def _force_cleanup_ffmpeg(self):
"""强制清理所有FFmpeg相关资源 - 防止多进程推流"""
@ -689,17 +689,19 @@ class FaceRecognitionSystem:
self.logger.error(f"无法读取二维码图片: {self.qrcode_image_path}")
return False
# 获取二维码图片尺寸
qr_height, qr_width = qr_image.shape[:2]
# 使用屏幕缓存尺寸,如果获取失败则使用图片尺寸
canvas_width = self.screen_width if self.screen_width > 0 else qr_width
canvas_height = self.screen_height if self.screen_height > 0 else qr_height
# 创建二维码窗口
cv2.namedWindow(self.qrcode_window_name, cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL)
# 使用缓存的屏幕尺寸
canvas_width = self.screen_width
canvas_height = self.screen_height
x_pos = 0
y_pos = 0
qr_height, qr_width = qr_image.shape[:2]
rendered = self._build_qrcode_instruction_canvas(qr_image, (canvas_width, canvas_height))
if rendered is None:
# 回退到原二维码展示
@ -710,14 +712,13 @@ class FaceRecognitionSystem:
new_height = int(qr_height * scale)
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)