Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 149 additions & 81 deletions ocr/arabic/java/ocr-basics/calculate-skew-angle/_index.md

Large diffs are not rendered by default.

154 changes: 108 additions & 46 deletions ocr/arabic/java/ocr-basics/get-rectangles-with-text-areas/_index.md

Large diffs are not rendered by default.

143 changes: 99 additions & 44 deletions ocr/arabic/net/text-recognition/recognize-table/_index.md

Large diffs are not rendered by default.

255 changes: 155 additions & 100 deletions ocr/chinese/java/ocr-basics/calculate-skew-angle/_index.md

Large diffs are not rendered by default.

172 changes: 117 additions & 55 deletions ocr/chinese/java/ocr-basics/get-rectangles-with-text-areas/_index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
---
date: 2026-02-09
description: 了解如何使用 Aspose OCR Java 库将图像转换为文本并提取文本区域矩形。分步指南并附代码示例。
linktitle: Recognize Text from Image and Retrieve Text Area Rectangles
date: 2026-06-19
description: 了解如何在 Java 中将图像转换为文本(convert image to text),从图像中提取段落(extract paragraphs),并使用
Aspose OCR Java library 检索文本区域矩形。
keywords:
- image to text java
- convert scanned image text
- extract paragraphs from image
- aspose ocr java tutorial
linktitle: Image to Text Java – 识别图像中的文本并检索文本区域矩形
schemas:
- author: Aspose
dateModified: '2026-06-19'
description: Learn how to convert image to text in Java, extract paragraphs from
image, and retrieve text area rectangles using Aspose OCR Java library.
headline: Image to Text Java – Convert Image to Text and Retrieve Text Area Rectangles
type: TechArticle
- description: Learn how to convert image to text in Java, extract paragraphs from
image, and retrieve text area rectangles using Aspose OCR Java library.
name: Image to Text Java – Convert Image to Text and Retrieve Text Area Rectangles
steps:
- name: Set Up Your Project
text: Create a new Java project (or add to an existing one) and place the Aspose.OCR
JAR on the classpath. If you use Maven, add the dependency as described in the
download package.
- name: Define Document Directory and Image Path
text: 'Specify where your sample image resides:'
- name: Create AsposeOCR Instance
text: '`AsposeOCR` is the main class that provides OCR functionality. Instantiate
the OCR engine:'
- name: Recognize Text in the Image
text: Load your image and call `RecognizePage` to convert the picture into plain
text. This single method call performs image preprocessing, character segmentation,
and language‑specific recognition in one step.
- name: Get Rectangles with Text Areas
text: Retrieve the bounding rectangles for each paragraph (or other area types).
This step returns a collection of `Rectangle` objects that precisely enclose
the detected text blocks, enabling you to highlight or further process individual
sections. CODE_BLOCK_PLACEHOLDER_5_END
type: HowTo
- questions:
- answer: Yes, Aspose.OCR works with Java 11 and later versions.
question: Is Aspose.OCR compatible with Java 11?
- answer: Yes, you can use it in any type of project. For licensing details, visit
[here](https://purchase.aspose.com/buy).
question: Can I use Aspose.OCR for both personal and commercial projects?
- answer: You can obtain a temporary license [here](https://purchase.aspose.com/temporary-license/).
question: How do I obtain a temporary license for evaluation?
- answer: For support and discussions, visit the [Aspose.OCR forum](https://forum.aspose.com/c/ocr/16).
question: Where can I find community support or official assistance?
- answer: Yes, the library is thread‑safe and can be used in concurrent environments
for better performance.
question: Does Aspose.OCR support multithreading?
type: FAQPage
second_title: Aspose.OCR Java API
title: 将图像转换为文本——从图像中识别文本并获取文本区域矩形
title: Image to Text Java – 将图像转换为文本并检索文本区域矩形
url: /zh/java/ocr-basics/get-rectangles-with-text-areas/
weight: 12
---
Expand All @@ -12,37 +62,38 @@ weight: 12
{{< blocks/products/pf/main-container >}}
{{< blocks/products/pf/tutorial-page-section >}}

# 将图像转换为文本 – 从图像识别文本并获取文本区域矩形
# Java 图像转文本 – 将图像转换为文本并检索文本区域矩形

## 介绍

如果您需要在 Java 应用程序中 **将图像转换为文本** 并 **从图像识别文本**,Aspose.OCR for Java 提供了一种快速、精准的实现方式。在本教程中,我们将逐步演示如何从图像中提取段落、获取每个文本区域的边界矩形,并将这些坐标打印到控制台。完成后,您将了解该方法的原理、如何集成该库,以及在何处可以扩展以满足自己的使用场景
如果您需要在 Java 应用程序中 **convert image to text**,Aspose.OCR for Java 提供了快速、准确的解决方案。在本教程中,我们将逐步演示从图像中提取段落、获取每个文本区域的边界矩形,并将这些坐标打印到控制台的完整步骤。完成后,您将了解为何此方法有效、如何集成该库以及在哪里可以为自己的使用场景进行扩展

## 快速答疑
- **“从图像识别文本”是什么意思?** 指将图片中的可视字符转换为可编辑的字符串数据。
- **Java 中使用哪个库实现?** Aspose.OCR for Java。
- **开发阶段需要许可证吗?** 提供用于测试的临时许可证;生产环境需要正式许可证。
- **可以提取段落而不是单词吗?** 可以——使用 `AreasType.PARAGRAPHS` 获取段落级别的矩形。
- **代码是否兼容 Java 11+?** 完全兼容,API 支持 Java 11 及更高版本。
## 快速回答
`AreasType` 是一个枚举,指定文本分割的层级(单词、行、段落)。

## Aspose.OCR 中的 “将图像转换为文本” 是什么?
Aspose.OCR 的 `RecognizePage` 方法会分析位图,应用 OCR 算法,并返回识别后的字符串。当您请求文本区域时,库还会计算每个文本块的精确 `Rectangle` 坐标,便于后续高亮或处理特定区域。
- **What does “recognize text from image” mean?** 这意味着将图片中的可视字符转换为可编辑的字符串数据。
- **哪个库在 Java 中处理此功能?** Aspose.OCR for Java。
- **我在开发时需要许可证吗?** 临时许可证可用于测试;生产环境需要正式许可证。
- **我可以提取段落而不是单个单词吗?** 是的 – 使用 `AreasType.PARAGRAPHS` 获取段落级别的矩形。
- **代码兼容 Java 11+ 吗?** 当然,API 在 Java 11 及更高版本上均可工作。

## 为什么选择这款 **java ocr library**?
- **高准确率** – 支持多语言和复杂字体。
- **易于集成** – 单个 JAR 即可提供完整的 OCR 功能。
- **灵活的输出** – 可获取原始文本、格式化的 HTML,或精确的文本区域矩形。
- **线程安全** – 适用于高吞吐量的服务器环境。
## 在 Aspose.OCR 中,“convert image to text” 是什么?

## 前置条件
`convert image to text` 指的是分析位图、应用 OCR 算法并将识别的字符返回为字符串的过程。Aspose.OCR 的 `RecognizePage` 方法执行此转换,同时可选地提供每个检测到的文本块的精确 `Rectangle` 坐标。

- 已在机器上安装 **Java Development Kit**(JDK 11 或更高)。
- 已下载 **Aspose.OCR for Java** 库,可从官方站点 [here](https://releases.aspose.com/ocr/java/) 获取。
- 具备 IDE 或构建工具(Maven/Gradle)以管理 JAR 依赖。
## 为什么使用这个 **java ocr library**?

Aspose.OCR 支持 **30+ languages**,并且能够在不将整个文件加载到内存中的情况下处理高达 **50 MB** 的图像,在典型服务器硬件上实现亚秒级响应时间。该库是线程安全的,仅需一个 JAR,即可提供灵活的输出格式——包括原始文本、HTML 和精确的文本区域矩形——使其非常适合高吞吐量的企业场景。

## 先决条件

- **Java Development Kit** (JDK 11 或更高) 已安装在您的机器上。
- **Aspose.OCR for Java** 库 – 从官方网站 [here](https://releases.aspose.com/ocr/java/) 下载。
- 用于管理 JAR 依赖的 IDE 或构建工具(Maven/Gradle)。

## 导入包

Java 项目中导入所需的类
在您的 Java 项目中,导入必要的类

```java
package com.aspose.ocr.examples.OcrFeatures;
Expand All @@ -57,13 +108,10 @@ import java.io.IOException;
import java.util.ArrayList;
```

## 步骤指南
## 分步指南

### 步骤 1:设置项目
创建一个新的 Java 项目(或在已有项目中添加),并将 Aspose.OCR JAR 放入类路径。如果使用 Maven,请按下载包中的说明添加依赖。

### 步骤 2:定义文档目录和图像路径
指定示例图像所在的位置:
创建一个新的 Java 项目(或在现有项目中添加),并将 Aspose.OCR JAR 放置在类路径上。如果使用 Maven,请按照下载包中描述的方式添加依赖。

```java
// The path to the documents directory.
Expand All @@ -73,16 +121,18 @@ String dataDir = "Your Document Directory";
String imagePath = dataDir + "p3.png";
```

### 步骤 3:创建 Aspose.OCR 实例
实例化 OCR 引擎
### 步骤 2:定义文档目录和图像路径
指定您的示例图像所在的位置

```java
// Create AsposeOCR instance
AsposeOCR api = new AsposeOCR();
```

### 步骤 4:识别图像中的文本
调用 `RecognizePage` 将图片转换为纯文本。此步骤演示了核心的 **recognize text image java** 能力:
### 步骤 3:创建 AsposeOCR 实例
`AsposeOCR` 是提供 OCR 功能的主类。

实例化 OCR 引擎:

```java
try {
Expand All @@ -94,8 +144,8 @@ try {
}
```

### 步骤 5:获取文本区域的矩形
现在检索每个段落(或其他区域类型)的边界矩形。这正是 **extract paragraphs from image** 并获取其坐标的地方:
### 步骤 4:识别图像中的文本
加载图像并调用 `RecognizePage` 将图片转换为纯文本。此单一方法调用在一步中完成图像预处理、字符分割和语言特定的识别。

```java
// Get rectangles with text areas in the image.
Expand All @@ -107,43 +157,55 @@ for (Rectangle r : rectResult) {
}
```

### 步骤 5:获取带有文本区域的矩形
检索每个段落(或其他区域类型)的边界矩形。此步骤返回 `Rectangle` 对象的集合,精确包围检测到的文本块,使您能够突出显示或进一步处理各个部分。

CODE_BLOCK_PLACEHOLDER_5_END

## 常见问题与故障排除

| 症状 | 可能原因 | 解决方案 |
|------|----------|----------|
| `IOException` `RecognizePage` 上抛出 | 文件路径不正确或缺少读取权限 | 确认 `imagePath` 指向存在的 PNG/JPG 文件,并确保应用拥有文件系统访问权限。 |
| 返回的字符串为空 | 图像质量低或语言不受支持 | 对图像进行预处理(提升对比度、二值化)或使用 `api.setLanguage("eng")` 指定正确的语言。 |
| 未返回矩形 | 使用了错误的 `AreasType`(例如期望段落却使用 `WORDS`) | 根据需求切换为 `AreasType.PARAGRAPHS` 或 `AreasType.LINES`。 |
|---------|--------------|-----|
| `IOException` on `RecognizePage` | 文件路径不正确或缺少读取权限 | 验证 `imagePath` 指向现有的 PNG/JPG,并且应用具有文件系统访问权限。 |
| 结果字符串为空 | 图像质量低或语言不受支持 | 对图像进行预处理(提高对比度、二值化)或使用 `api.setLanguage("eng")` 指定正确的语言。 |
| 未返回矩形 | 使用了错误的 `AreasType`(例如在期望段落时使用 `WORDS`) | 根据需要切换到 `AreasType.PARAGRAPHS` 或 `AreasType.LINES`。 |

## 常见问答
## 常见问题

**问:Aspose.OCR 是否兼容 Java 11?**
答:是的,Aspose.OCR 可在 Java 11 及更高版本上运行。
**Q: Aspose.OCR Java 11 兼容吗?**
**A:** 是的,Aspose.OCR 可在 Java 11 及更高版本上运行。

**问:我可以在个人项目和商业项目中使用 Aspose.OCR 吗?**
答:可以,任何类型的项目均可使用。许可证详情请访问 [here](https://purchase.aspose.com/buy)。
**Q: 我可以在个人和商业项目中使用 Aspose.OCR 吗?**
**A:** 可以,您可以在任何类型的项目中使用。有关许可详情,请访问 [here](https://purchase.aspose.com/buy)。

**问:如何获取用于评估的临时许可证?**
答:可在此处获取临时许可证 [here](https://purchase.aspose.com/temporary-license/)。
**Q: 我如何获取用于评估的临时许可证?**
**A:** 您可以在 [here](https://purchase.aspose.com/temporary-license/) 获取临时许可证

**问:在哪里可以找到社区支持或官方帮助?**
答:请访问 [Aspose.OCR 论坛](https://forum.aspose.com/c/ocr/16) 进行支持和讨论
**Q: 我在哪里可以找到社区支持或官方帮助?**
**A:** 请访问 [Aspose.OCR forum](https://forum.aspose.com/c/ocr/16) 获取支持和讨论

**问:Aspose.OCR 支持多线程吗?**
答:支持,库是线程安全的,可在并发环境中使用以提升性能
**Q: Aspose.OCR 支持多线程吗?**
**A:** 是的,该库是线程安全的,可在并发环境中使用以获得更好性能

## 结论

在本 **aspose ocr java tutorial** 中,您学习了如何使用 Aspose.OCR for Java **将图像转换为文本**、提取段落并获取围绕每个文本块的精确矩形。这些功能可帮助您构建可搜索的 PDF在 UI 覆盖层中高亮文本,或将结构化数据输送到下游流程。进一步探索 API,可自定义语言设置、处理不同图像格式,或与云存储集成
在本 **aspose ocr java tutorial** 中,您学习了如何使用 Aspose.OCR for Java **convert image to text**,提取段落,并获取围绕每个文本块的精确矩形。这些功能使您能够构建可搜索的 PDF在 UI 覆盖层中高亮文本,或将结构化数据输送到下游流程。进一步探索 API,以自定义语言设置、处理不同的图像格式或集成云存储

---

**最后更新:** 2026-02-09
**最后更新:** 2026-06-19
**测试环境:** Aspose.OCR 23.10 for Java
**作者:** Aspose

{{< blocks/products/products-backtop-button >}}

## 相关教程

- [提取文本图像 – 使用 Aspose.OCR for Java 的 OCR 基础](/ocr/java/ocr-basics/)
- [使用 Aspose.OCR 检测区域模式的 Java 图像提取文本](/ocr/java/ocr-operations/perform-ocr-detect-areas-mode/)
- [使用 Aspose.OCR BufferedImage 在 Java 中将图像转换为文本](/ocr/java/advanced-ocr-techniques/perform-ocr-buffered-image/)


{{< /blocks/products/pf/tutorial-page-section >}}
{{< /blocks/products/pf/main-container >}}
{{< /blocks/products/pf/main-wrap-class >}}

{{< blocks/products/products-backtop-button >}}
{{< /blocks/products/pf/main-wrap-class >}}
Loading