概述Shape Detection API 在支持的浏览器中提供条码、人脸与文本的检测能力,适用于扫码登录、相册整理与辅助功能。需在安全上下文使用并处理隐私与权限。示例:条码检测if ('BarcodeDetector' in window) { const det = new BarcodeDetector({ formats: ['qr_code','code_128'] }) const img = document.querySelector('img') const codes = await det.detect(img) } 示例:人脸检测(实验性)if ('FaceDetector' in window) { const fd = new FaceDetector({ fastMode: true }) const faces = await fd.detect(document.querySelector('img')) } 工程建议隐私与权限:明确用途与范围;避免上传原始图像到第三方。兼容与回退:不支持时回退到 WASM/ML 模型(如 ZXing/Face API);注意性能与精度。性能:对实时视频使用较低分辨率与裁剪;批量任务采用 Worker 并行。参考与验证MDN Shape Detection 文档:https://developer.mozilla.org/docs/Web/API/Barcode_Detection_APIChrome 平台文档:https://developer.chrome.com/docs/web-platform/shape-detection/

发表评论 取消回复