> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 ocr_service 运行基本 OCR

> ocr_service 示例应用启用了一个提供光学字符识别 (OCR) 功能的服务。它从 ROS 系统捕获图像话题，并使用 ocr_topic 发布结果。

## `ocr_service` 的管道流程

下图展示了相关客户端/服务器和 ROS 节点之间的管道流程，以及基本的消息和数据传输通道。

<Frame caption="ocr_service 管道。">
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-Ubuntu/images/image7.png" style={{width: "70%"}} alt="OCR_Client calling OCR_Server over ocr_msg.srv, the server forking OCR_Node, which subscribes to image_topic and publishes OCR_Topic." />
</Frame>

## `ocr_service` 管道中使用的 ROS 节点

下表列出了 `ocr_service` 管道中使用的 ROS 节点，并说明每个节点的功能。

| ROS 节点        | 说明                                                 |
| ------------- | -------------------------------------------------- |
| `OCR_CLIENT`  | 向 `ocr_server` 发送光学字符识别 (OCR) 请求并获取服务器结果。          |
| `OCR_SERVER`  | 从 `ocr_server` 获取 OCR 请求，并根据请求 fork `ocr_rosnode`。 |
| `OCR_ROSNODE` | 根据请求订阅图像话题。                                        |

## `ocr_service` 管道中使用的 ROS 话题

下表列出了 `ocr_service` 管道中使用的 ROS 话题，以及每个话题的消息类型和发布者。

| ROS 话题                  | 类型                          | 发布者              |
| ----------------------- | --------------------------- | ---------------- |
| `/image_topic_name`     | `< sensor_msgs.msg.Image >` | 任意 ROS 节点        |
| `/ocr_image_topic_name` | `< std_msgs/msg/String >`   | `ocr-rosnode` 节点 |

## 前提条件

你已根据[安装 QIR SDK](./install-the-qir-sdk)完成设备设置，并在设备上安装了 ROS2 Jazzy 和 Qualcomm Intelligent Robotics (QIR) SDK。

## 开箱即用运行 `ocr_service`

使用以下命令运行 `ocr_service`：

```bash Run ocr_service theme={null}
source /opt/ros/jazzy/setup.bash
ros2 run ocr_service ocr_server
ros2 run ocr_service ocr_testnode --topic <image_topic> --picture <image_path>
ros2 run ocr_service ocr_client <image_topic>
```

### 示例

此示例展示了可以在三个终端中运行的命令：

* 在终端 1：

  ```bash Start the OCR server theme={null}
  source /opt/ros/jazzy/setup.bash
  ros2 run ocr_service ocr_server
  ```

* 在终端 2：

  ```bash Publish a test image theme={null}
  source /opt/ros/jazzy/setup.bash
  scp <pic_path>/test.png ubuntu@IP:/home/ubuntu/image
  ros2 run ocr_service ocr_testnode --topic test --picture /home/ubuntu/image/test.png
  ```

* 在终端 3：

  ```bash Run the OCR client theme={null}
  source /opt/ros/jazzy/setup.bash
  ros2 run ocr_service ocr_client test
  ```
