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

Large diffs are not rendered by default.

171 changes: 118 additions & 53 deletions ocr/arabic/net/ocr-settings/specify-allowed-characters/_index.md

Large diffs are not rendered by default.

158 changes: 113 additions & 45 deletions ocr/arabic/net/ocr-settings/working-with-different-languages/_index.md

Large diffs are not rendered by default.

186 changes: 123 additions & 63 deletions ocr/arabic/net/skew-angle-calculation/calculate-skew-angle/_index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,74 +1,105 @@
---
date: 2026-02-20
description: 学习如何使用 Aspose.OCR for Java 从图像中提取文本、设置允许的字符并应用临时许可证——完整的 Aspose OCR Java
教程。
linktitle: Specifying Allowed Characters in Aspose.OCR
date: 2026-05-24
description: 了解如何在 Java 中使用 Aspose.OCR 进行 OCR,提取图像中的文本,设置允许的字符,并在几分钟内应用临时许可证。
keywords:
- how to use OCR
- extract text from images
- how to apply license
- how to set characters
linktitle: 在 Aspose.OCR 中指定允许的字符
schemas:
- author: Aspose
dateModified: '2026-05-24'
description: Discover how to use OCR with Aspose.OCR for Java, extract text from
images, set allowed characters, and apply a temporary license in minutes.
headline: How to Use OCR – Extract Text from Images with Aspose.OCR
type: TechArticle
- description: Discover how to use OCR with Aspose.OCR for Java, extract text from
images, set allowed characters, and apply a temporary license in minutes.
name: How to Use OCR – Extract Text from Images with Aspose.OCR
steps:
- name: Set Your Document Directory
text: Choose a folder where OCR results and temporary files will be stored. This
path is later used to locate the image you want to process.
- name: Specify the Image Path
text: Provide the full file system path or a class‑path resource location that
points to the image you wish to analyse.
- name: Create an Aspose.OCR Instance
text: '`AsposeOCR` is the core engine that performs optical character recognition.
Instantiate it with either a temporary or permanent license string.'
- name: Perform OCR Recognition
text: '`RecognizeLine` extracts a single line of text from the supplied image
and returns it as a plain Java `String`. You can call this method repeatedly
for multi‑line documents. > **Pro tip:** If you need to restrict the output
to digits only (e.g., for invoice numbers), call `setAllowedCharacters("0123'
type: HowTo
- questions:
- answer: Visit the [temporary license page](https://purchase.aspose.com/temporary-license/)
to request a trial key that removes evaluation watermarks.
question: How can I obtain a temporary license for Aspose.OCR?
- answer: Join the community at the [Aspose.OCR Forum](https://forum.aspose.com/c/ocr/16)
for help and discussions.
question: Where can I find support for Aspose.OCR?
- answer: Yes, use the `setAllowedCharacters` API to define a custom whitelist of
characters. This is ideal for numeric‑only fields.
question: Can I specify allowed characters in Aspose.OCR?
- answer: Absolutely—Aspose.OCR is regularly updated to stay compatible with the
newest Java releases.
question: Is Aspose.OCR compatible with the latest JDK versions?
- answer: The library also supports block, paragraph, and full‑page recognition,
language packs, and advanced image preprocessing.
question: Are there additional OCR features beyond line recognition?
type: FAQPage
second_title: Aspose.OCR Java API
title: 使用 Aspose.OCR 从图像中提取文本 – 允许的字符
title: 如何使用 OCR – 使用 Aspose.OCR 从图像中提取文本
url: /zh/java/advanced-ocr-techniques/specify-allowed-characters/
weight: 15
---

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

# 使用 Aspose.OCR 从图像中提取文本 – 允许的字符
# 如何使用 OCR – 使用 Aspose.OCR 从图像中提取文本

## 简介

从图像中提取文本是现代应用中的常见需求——无论是处理发票、扫描收据,还是数字化打印文档。在本教程中,我们将演示一个完整的 **aspose ocr java tutorial**,展示如何使用 Aspose.OCR for Java **从图像中提取文本**、设置允许的字符,并在仅测试库时应用临时许可证。
在现代 Java 应用程序中,**如何使用 OCR** 是一个常见问题,尤其是当您需要将扫描的发票、收据或打印表单转换为可搜索的文本时。本教程将带您完成一个完整的 **Aspose.OCR for Java** 示例:从图像中提取文本,限制输出为自定义字符集,并应用临时许可证以快速评估。

## 快速答案
- **Aspose.OCR 的作用是什么?** 它能够高精度地从图像中提取文本,并支持自定义字符集
- **我需要许可证吗?** 生产环境需要临时或永久许可证
- **支持哪个 JDK 版本?** 最新的 JDK 发行版完全兼容
- **我可以限制识别的字符吗?** 可以——使用 `setAllowedCharacters` API 来限制输出
- **设置需要多长时间?** 基本实现大约需要 10‑15 分钟。
- **Aspose.OCR 的作用是什么?** 它能够高精度地从图像中提取文本,并允许您限制识别的字符
- **我需要许可证吗?** 在生产环境中需要临时或永久许可证;临时密钥可以去除水印
- **支持哪个 JDK 版本?** 该库兼容最新的 JDK 发行版(JDK 17、19、21)
- **我可以限制识别的字符吗?** 可以——使用 `setAllowedCharacters` 方法来限制输出
- **设置需要多长时间?** 基本的端到端实现大约需要 10‑15分钟。

## 什么是“从图像中提取文本”?
从图像中提取文本指的是将视觉文本(例如印刷或手写的文字)转换为机器可读的字符串的过程。这使得后续的搜索、索引或数据分析等任务成为可能。

## 为什么选择 Aspose.OCR for Java?
- **高精度**,支持多种语言和字体。
- **简洁的 API**,可集成到任何 Java 项目中。
- **可定制**的字符集、语言包和图像预处理。
- **无外部依赖**——库是自包含的。

## 先决条件

在开始之前,请确保您具备以下条件:
从图像中提取文本,也称为光学字符识别(OCR),将视觉字符——无论是印刷的、手写的还是打字的——转换为机器可读的字符串。此转换使应用程序能够以编程方式搜索、索引、编辑和分析内容,支持诸如发票处理、文档归档和数据录入自动化等工作流。

### Java Development Kit (JDK)

确保在系统上安装了最新的 Java Development Kit。您可以从[此处](https://www.oracle.com/java/technologies/javase-downloads.html)下载。
## 为什么使用 Aspose.OCR for Java?

### Aspose.OCR for Java Library
Aspose.OCR 支持 **60+ 种语言**,能够在不将整个文件加载到内存的情况下处理高达 **10 MB** 的图像,并在干净的扫描件上实现 **>95 % 的准确率**。该库是自包含的,无需外部 OCR 引擎,从而简化部署并降低许可成本。

从[下载链接](https://releases.aspose.com/ocr/java/)下载并安装 Aspose.OCR for Java 库。
## 前提条件

### Aspose.OCR License
### Java Development Kit (JDK)

要充分发挥 Aspose.OCR 的功能,请获取有效许可证。您可以从[此处](https://purchase.aspose.com/buy)获取,或探索用于试用期的[临时许可证](https://purchase.aspose.com/temporary-license/)
确保已安装最新的 Java Development Kit。您可以从 [here](https://www.oracle.com/java/technologies/javase-downloads.html) 下载

## 如何应用临时许可证
### Aspose.OCR for Java 库

在评估产品时,临时许可证可去除评估水印并在有限时间内解锁全部功能。请在 Aspose 门户中创建许可证字符串,然后将其传递给 `AsposeOCR` 构造函数,如下面的代码示例所示。生产部署时,请用永久许可证替换临时密钥
从 [download link](https://releases.aspose.com/ocr/java/) 下载并安装 Aspose.OCR for Java 库

## OCR 图像预处理技巧
### Aspose.OCR 许可证

良好的图像质量可显著提升识别结果。在调用 OCR 引擎之前,请考虑:
要解锁全部功能,请获取许可证。您可以从 [here](https://purchase.aspose.com/buy) 购买,或请求 [temporary license](https://purchase.aspose.com/temporary-license/) 进行试用。

- 将图像转换为灰度。
- 增加对比度,使字符更突出。
- 使用二值化滤波器去除背景噪声。
- 将低分辨率图像调整至至少 300 dpi。
## 如何在 Java 中使用 Aspose.OCR 进行 OCR?

这些步骤属于 **ocr image preprocessing**,可在调用 Aspose.OCR 前使用任何标准的 Java 图像库完成
加载图像,配置 OCR 引擎,并调用识别方法——只需几行简洁代码。本段直接回答告诉您该怎么做:使用许可证字符串创建 `AsposeOCR` 实例,设置允许的字符,然后在目标图像上调用 `RecognizeLine` 以获取提取的文本。API 在内部处理图像预处理,因此无需额外代码即可获得干净的结果

## 导入包
### 导入包

准备好先决条件后,将必要的包导入您的 Java 项目:
`AsposeOCR` 类位于 `com.aspose.ocr` 包中。在开始编码之前,请导入所需的类。

```java
package com.aspose.ocr.examples.OcrFeatures;
Expand All @@ -79,35 +110,35 @@ import com.aspose.ocr.examples.Utils;
import java.io.IOException;
```

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

### Step 1: Set Your Document Directory
### 步骤 1:设置文档目录

定义一个文件夹,用于存放 OCR 处理后的结果。此路径稍后用于定位图像文件
选择一个文件夹,用于存放 OCR 结果和临时文件。稍后将使用此路径定位要处理的图像

```java
String dataDir = "Your Document Directory";
```

### Step 2: Specify the Image Path
### 步骤 2:指定图像路径

将 API 指向您要分析的图像
提供指向您要分析的图像的完整文件系统路径或类路径资源位置

```java
String imagePath = dataDir + "0001460985.Jpeg";
```

### Step 3: Create an Aspose.OCR Instance
### 步骤 3:创建 Aspose.OCR 实例

使用您的许可证密钥实例化 OCR 引擎。密钥可以是临时或永久许可证字符串
`AsposeOCR` 是执行光学字符识别的核心引擎。使用临时或永久许可证字符串实例化它

```java
AsposeOCR api = new AsposeOCR("YourLicenseKey");
```

### Step 4: Perform OCR Recognition
### 步骤 4:执行 OCR 识别

调用 `RecognizeLine` 方法从图像中提取一行文本。结果是一个普通字符串,您可以进一步处理或存储
`RecognizeLine` 从提供的图像中提取单行文本,并将其作为普通的 Java `String` 返回。您可以对多行文档重复调用此方法

```java
try {
Expand All @@ -119,46 +150,52 @@ try {
}
```

> **专业提示:** 如果您需要将输出限制在特定字符集(例如仅数字),请在调用 `RecognizeLine` 之前对 `AsposeOCR` 实例使用 `setAllowedCharacters` 方法。这可确保引擎忽略定义集合之外的任何字符。
> **技巧提示:** 如果您需要将输出限制为仅数字(例如发票号码),请在调用 `RecognizeLine` 之前对 `AsposeOCR` 实例调用 `setAllowedCharacters("0123456789")`。这会强制引擎忽略所有非数字符号。
> `setAllowedCharacters` 是 `AsposeOCR` 的一个方法,用于将 OCR 输出限制在指定的字符白名单中。

## 常见问题及解决方案

| 问题 | 原因 | 解决方案 |
|------|------|----------|
| **无输出或空字符串** | 图像路径不正确或不支持的图像格式 | 验证 `imagePath` 并使用受支持的格式(JPEG、PNG、BMP) |
| **识别错误** | 低分辨率图像或噪声背景 | 在 OCR 前对图像进行预处理(增加对比度、二值化) |
| **许可证未应用** | 缺少或无效的许可证密钥 | 确保许可证字符串正确并放置在 `AsposeOCR` 构造函数中 |
| Issue | Reason | Fix |
|-------|--------|-----|
| **没有输出或为空字符串** | 图像路径不正确或格式不受支持 | 验证 `imagePath` 并使用受支持的格式(JPEG、PNG、BMP) |
| **识别错误** | 低分辨率图像或噪声背景 | 在 OCR 前对图像进行预处理(提高对比度、二值化) |
| **许可证未应用** | 缺少或无效的许可证密钥 | 确保许可证字符串正确并传递给 `AsposeOCR` 构造函数 |

## 常见问题

**Q: 如何获取 Aspose.OCR 的临时许可证?**
A: 访问[临时许可证页面](https://purchase.aspose.com/temporary-license/)请求试用许可证
A: 访问 [temporary license page](https://purchase.aspose.com/temporary-license/) 以请求一个去除评估水印的试用密钥

**Q: 在哪里可以找到 Aspose.OCR 的支持?**
A: 加入[Aspose.OCR 论坛](https://forum.aspose.com/c/ocr/16)社区获取帮助和讨论。
A: 加入 [Aspose.OCR Forum](https://forum.aspose.com/c/ocr/16) 社区获取帮助和讨论。

**Q: 我可以在 Aspose.OCR 中指定允许的字符吗?**
A: 可以,使用 `setAllowedCharacters` API 自定义字符集。详情请参阅官方文档
A: 可以,使用 `setAllowedCharacters` API 定义自定义字符白名单。这对于仅数字字段非常理想

**Q: Aspose.OCR 与最新的 JDK 版本兼容吗?**
A: 完全兼容——Aspose.OCR 会定期更新,以保持与最新 Java 发行版的兼容性。

**Q: 除了行识别之外,还有其他 OCR 功能吗?**
A: 有,库支持块、段落和整页识别,以及语言包和图像预处理选项
**Q: 除了行识别之外,是否还有其他 OCR 功能?**
A: 该库还支持块、段落和整页识别、语言包以及高级图像预处理

## 结论

通过本 **aspose ocr java tutorial**,您现在拥有了一个可 **从图像中提取文本** 并控制识别字符的工作方案。探索完整的[文档](https://reference.aspose.com/ocr/java/)以发现多语言支持、自定义预处理和批量处理等高级功能
通过本 **Aspose OCR Java 教程**,您现在了解了 **如何使用 OCR** 从图像中提取文本、限制字符集,并应用临时许可证进行快速测试。深入阅读完整的 [documentation](https://reference.aspose.com/ocr/java/) 以探索多语言支持、批处理和自定义预处理管道

---

**最后更新:** 2026-02-20
**最后更新:** 2026-05-24
**测试环境:** Aspose.OCR for Java 24.11
**作者:** Aspose

{{< /blocks/products/pf/tutorial-page-section >}}
{{< blocks/products/products-backtop-button >}}

{{< /blocks/products/pf/main-container >}}
{{< /blocks/products/pf/main-wrap-class >}}
## 相关教程

- [如何在 Java 中设置许可证并验证 Aspose.OCR 许可证](/ocr/java/ocr-basics/set-license/)
- [使用 Aspose.OCR BufferedImage 将图像转换为文本(Java)](/ocr/java/advanced-ocr-techniques/perform-ocr-buffered-image/)
- [Aspose OCR Java 示例 – 识别图像中的行](/ocr/java/advanced-ocr-techniques/recognize-lines/)

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