Web 环境移除: - 删除 Web 相关文件:src/app.py, heartbeat.py - 用 requirements-desktop.txt 替换 requirements.txt - 更新 README.md:移除 Web 界面、部署方案等章节 - 更新技术栈说明:Streamlit → PyQt6 - 添加 usb_bundle/ 到 .gitignore Desktop 应用改进: - 重构 OCRService:使用独立 Python 线程替代 QThread - 添加主线程预加载 paddleocr 模块,修复 macOS 上卡死问题 - 新增离线 OCR 初始化模块(src/ocr_offline.py) - 新增模型准备脚本(scripts/prepare_models.py) - 新增摄像头诊断工具(scripts/camera_probe.py) 功能定位: - Desktop 应用(src/desktop.py):实时摄像头拍照识别 - CLI 批处理(src/main.py):批量处理目录中的图片 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
68 lines
1.7 KiB
Python
Executable File
68 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
摄像头探测脚本(用于排查 macOS/iPhone 连续互通相机无画面问题)
|
|
|
|
用法:
|
|
source .venv/bin/activate
|
|
python scripts/camera_probe.py
|
|
|
|
输出:
|
|
- 列出 0~9 号摄像头是否可打开、是否可读到有效帧、帧尺寸与亮度均值
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
|
|
def open_cap(cv2, cam_id: int):
|
|
if sys.platform == "darwin" and hasattr(cv2, "CAP_AVFOUNDATION"):
|
|
return cv2.VideoCapture(cam_id, cv2.CAP_AVFOUNDATION)
|
|
return cv2.VideoCapture(cam_id)
|
|
|
|
|
|
def main() -> int:
|
|
import cv2 # pylint: disable=import-error
|
|
|
|
print(f"平台: {sys.platform}")
|
|
print(f"OpenCV: {cv2.__version__}")
|
|
print("")
|
|
|
|
found_any = False
|
|
for cam_id in range(10):
|
|
cap = open_cap(cv2, cam_id)
|
|
opened = cap.isOpened()
|
|
ok = False
|
|
shape = None
|
|
mean = None
|
|
if opened:
|
|
for _ in range(30):
|
|
ret, frame = cap.read()
|
|
if ret and frame is not None and frame.size > 0:
|
|
ok = True
|
|
shape = frame.shape
|
|
mean = float(frame.mean())
|
|
break
|
|
cap.release()
|
|
|
|
if opened:
|
|
found_any = True
|
|
status = "OK" if ok else ("打开但无画面" if opened else "无法打开")
|
|
print(f"摄像头 {cam_id}: {status}", end="")
|
|
if ok:
|
|
print(f" | shape={shape} | mean={mean:.1f}")
|
|
else:
|
|
print("")
|
|
|
|
if not found_any:
|
|
print("\n未检测到可打开的摄像头。")
|
|
else:
|
|
print("\n如果出现“打开但无画面”,优先检查 macOS 相机权限。")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|
|
|