fix(utils): decode QR image via np.fromfile for non-ASCII paths
cv2.imread cannot open files under non-ASCII (e.g. Chinese) paths on Windows, so decode_qrcode_from_path() always returned None when the project lived under a directory like D:\视频全平台同步\, and the terminal QR re-print silently failed. Use np.fromfile + cv2.imdecode instead, which handles arbitrary paths.
This commit is contained in:
@@ -35,7 +35,13 @@ def remove_qrcode_file(qrcode_path: Path | None) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def decode_qrcode_from_path(qrcode_path: Path) -> str | None:
|
def decode_qrcode_from_path(qrcode_path: Path) -> str | None:
|
||||||
image = cv2.imread(str(qrcode_path))
|
# Windows 下 cv2.imread 不支持中文路径, 改用 np.fromfile + imdecode
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
try:
|
||||||
|
image = cv2.imdecode(np.fromfile(str(qrcode_path), dtype=np.uint8), cv2.IMREAD_COLOR)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
if image is None:
|
if image is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user