条形码扫描

利用机器学习套件的条形码扫描 API,您可以读取使用大多数标准条形码格式编码的数据。条形码扫描在设备上进行,不需要网络连接。
条形码是将现实世界中的信息传递到应用的一种便捷方式。具体而言,在使用二维码等 2D 格式时,您可以对结构化数据(例如联系信息或 Wi-Fi 网络凭据)进行编码。由于机器学习套件可以自动识别和解析此数据,因此当用户扫描条形码时,您的应用可以智能地做出响应。
对于不需要自定义界面的用户,我们建议您使用 Google 扫码器。扫码器 API 使用与标准条形码扫描 API 相同的推断模型,但只会返回最集中的条形码,从而提供更快、更一致的体验。Google 扫码器也更安全且无需权限,并且不需要与摄像头相关的实现或权限。
iOS
Android
Google 扫码器
主要功能
- 读取大多数标准格式
- 线性格式:Codabar、Code 39、Code 93、Code 128、EAN-8、EAN-13、ITF、UPC-A、UPC-E
- 2D 格式:Aztec、Data Matrix、PDF417、二维码
- 自动格式检测
- 一次扫描所有支持的条形码格式,而无需指定想要的格式,或者将检测器限制为仅扫描您感兴趣的格式,以提高扫描速度。
- 提取结构化数据
- 系统会自动解析使用某种受支持的 2D 格式存储的结构化数据。支持的信息类型包括网址、联系信息、日历活动、电子邮件地址、电话号码、短信提示、ISBN、Wi-Fi 连接信息、地理位置和 AAMVA 标准驱动程序信息。
- 适用于任何屏幕方向
- 无论条形码的方向如何(正置、倒置或侧置),系统都可以识别并扫描条形码。
- 在设备上运行
- 条形码扫描完全在设备上执行,不需要网络连接。
请注意,此 API 无法识别以下形式的条形码:
- 只包含一个字符的一维条形码
- ITF 格式的条形码少于 6 个字符,并且由于缺少校验和而已知该格式不稳定
- 使用 FNC2、FNC3 或 FNC4 编码的条形码
- 在 ECI 模式下生成的二维码
此 API 每次调用 API 时最多只能识别 10 个条形码。
示例结果
|
结果 |
角 |
(49,125)、(172,125)、(172,160)、(49,160) |
原始值 |
2404105001722 |
|
|
结果 |
角 |
(87,87) (612,87) (612,612) (87,612) |
原始值 |
WIFI:S:SB1Guest;P:12345;T:WEP;; |
Wi-Fi 信息 |
SSID |
SB1Guest |
密码 |
12345 |
类型 |
WEP |
|
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-05。
[null,null,["最后更新时间 (UTC):2024-09-05。"],[[["ML Kit's Barcode Scanning API reads data from most standard barcode formats, including linear and 2D formats, without needing an internet connection."],["It automatically detects and parses structured data like contact info, WiFi credentials, and more from supported 2D formats, enabling intelligent app responses."],["The API works offline, recognizing barcodes in any orientation, and the Google Code Scanner offers a faster, safer, and permissionless option for basic scanning needs."],["While it supports a wide range of formats and data types, the API has limitations regarding certain 1D barcodes, ITF formats, and QR codes with specific encodings, recognizing a maximum of 10 barcodes per call."]]],["ML Kit's barcode scanning API reads data from most standard barcode formats on the device without needing a network connection. It automatically detects and parses structured data from 2D formats like QR codes, recognizing information such as URLs, contact details, and WiFi credentials. The API supports various linear and 2D formats, works with any barcode orientation, and offers a Google code scanner option for a faster, safer, permission-less experience. It does not recognize some formats including some 1D and ITF barcodes.\n"]]