适配二维码画面

This commit is contained in:
Tian jianyong 2025-12-18 17:05:43 +08:00
parent 65042a7bc8
commit c70ca9d35c

View File

@ -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)