--- title: "Using Vision's Snapshot feature with an External OCR Service" slug: "using-visions-snapshot-feature-with-an-external-ocr-service" updated: 2025-01-08T12:24:25Z published: 2025-01-08T12:24:25Z canonical: "support.tulip.co/using-visions-snapshot-feature-with-an-external-ocr-service" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.tulip.co/llms.txt > Use this file to discover all available pages before exploring further. # 将 Vision 的快照功能与外部 OCR 服务结合使用 ## 将 Vision 的快照功能与外部 OCR 服务结合使用 *捕捉图像并发送至外部计算机视觉服务 API* NOTE While you can accomplish this with Vision - another alternative is to use CoPilot. Read more about CoPilot and OCR [here](https://support.tulip.co/docs/extract-text). ## 概述 Vision 的快照功能可与 Tulip Connectors 和外部 OCR 服务结合使用。本文将指导您如何快速建立一个强大的 OCR(光学字符识别)管道,从视觉相机拍摄的快照中检测文本。利用这一功能,您将能够扫描文档、读取打印标签上的文本,甚至是物品上压印或蚀刻的文本。 下文将介绍如何使用 Google Vision OCR 来实现这一功能。Google Vision OCR 功能能够在非常苛刻的图像条件下读取文本。 ### 本文将介绍以下步骤 1. 设置 Tulip Vision 和谷歌云视觉 API 2. 如何创建连接到 GCV API 的郁金香连接器 3. 构建一个应用程序来拍摄快照,并与 OCR 连接器功能通信 ## 先决条件 ### 设置快照和摄像头配置 请确保您已成功设置了 Vision 摄像头配置,并熟悉 Vision 的快照功能。有关详细信息,请参阅:[使用 Vision 快照功能](https://support.tulip.co/docs/using-visions-snapshot-feature) **启用 Google Cloud Vision API 和 Google Cloud Platform 项目** 创建一个 GCP 项目,并按照本文所述说明启用 Vision API[:https://cloud.google.com/vision/docs/ocr。](https://cloud.google.com/vision/docs/ocr) **在谷歌云平台上创建用于身份验证的 API 密钥** 按照[https://cloud.google.com/docs/authentication/api-keys](https://cloud.google.com/docs/authentication/api-keys)文章中的说明,为你的 GCP 项目创建一个 API 密钥。您可以限制此 API 密钥的使用,并设置适当的权限。请咨询你的网络管理员,帮助你进行配置。 ## 为谷歌 OCR 创建郁金香连接器功能 如下图所示,您创建的连接器和连接器功能将根据 Vision API 预期的请求类型进行配置: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350109030.png) ### 配置连接器功能: 1. 创建 HTTP 连接器。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350109713.png) 1. 配置连接器,使其指向 Google Vision API 端点。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350109975.png) **主机**:vision.googleapis.com **TLS**: Yes3.编辑 Connector 的**标题**以包含**Content-Type。** ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350110415.png) 1. **测试**连接器并**保存**配置。 2. 接下来,创建一个**POST**请求连接器函数,并在端点中添加以下路径:**v1/images:annotate** ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350110778.png) 1. 添加一张**图片**作为连接器函数的输入。确保输入类型为**文本**。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350111087.png) 1. 确保请求类型为 JSON,且**请求** **主体**与 Google Vision API 请求类型一致: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_357122749.png) 注:将`PUT_YOUR_API_KEY_HERE`替换为您在上述步骤中创建的自己的 API 密钥。 8.接下来,将文本图像转换为**base64string**(可使用本[网站](https://www.browserling.com/tools/image-to-base64)进行转换),以测试此连接器函数。将此字符串作为**图片**输入变量的测试值。 你应该会收到类似的回复: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350111901.png) 1. 设置输出变量指向**.responses.0.textAnnotations.0.description** 2. 保存连接器函数。 ## 创建使用快照和 Google OCR 连接器的 Tulip 应用程序 1. 转到应用程序编辑器并使用在设置快照触发器时创建的应用程序:[使用快照功能](https://support.tulip.co/docs/using-visions-snapshot-feature) 2. 接下来,创建一个带有触发器的按钮,以调用连接器功能。使用快照输出存储的图像变量作为连接器函数的输入。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350112339.png) 1. 在应用程序步骤中添加变量**detected_text**,以便查看连接器函数返回的结果: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_350112868.png) 1. 测试应用程序并观察 OCR 结果: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Using%20Vision%27s%20Snapshot%20feature%20with%20an%20External%20OCR%20Service_349150050.png) 您现在已经创建了一个能连接 Google Vision API OCR 服务的 Tulip Vision 应用程序。现在就在你的车间里试试吧! ## 进一步阅读: - [视觉入门](https://support.tulip.co/docs/getting-started-with-vision) - [使用变化检测器](https://support.tulip.co/docs/using-the-change-detector)(要求:英特尔 RealSense D415) - [使用夹具检测器](https://support.tulip.co/docs/using-the-jig-detector) - [使用颜色检测器](https://support.tulip.co/docs/using-the-color-detector) - [在应用程序中使用视觉相机小工具](https://support.tulip.co/docs/using-the-vision-camera-widget-in-apps)