在本教程中,您将学习使用 Python 将手写内容转换为文本。它包含设置 IDE 的所有详细信息、步骤列表以及使用 Python 开发手写内容转换为文本应用程序的示例代码。此应用程序将从加载的 PNG 图像中读取手写笔记,并将其转换为可搜索和可编辑的数字文本。
使用 Python 将手写笔记转换为文本的步骤
- 按照此处的说明安装 Aspose.OCR for Python via .NET
- 使用 AsposeOcr 类创建 OCR 引擎的实例
- 使用单一图像类型初始化用于 OCR 处理的输入容器
- 添加需要处理的图像文件以进行文本识别
- 在提供的图像上执行手写 text recognition
- 获取已识别文本段总数
- 遍历所有识别的文本段并打印
这些步骤描述了如何使用 Python 实现手写识别。实例化 OCR 引擎,创建图像输入容器,设置输入图像,并执行手写文本识别。获取已识别文本段的总数,并通过解析输出集合将其显示在屏幕上。
使用 Python 将手写内容转换为文本的代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.ocr as api # Import the Aspose.OCR module | |
from aspose.ocr import License # Import the License class from the module | |
license = License() # Instantiate and apply a license | |
license.set_license("License.lic") # Load the license file | |
extractTextFromImage = api.AsposeOcr() # Create OCR engine | |
imageDatas = api.OcrInput(api.InputType.SINGLE_IMAGE) # Initialize an input container | |
imageDatas.add("sample2.png")# Add the image file | |
# Perform handwritten text recognition on the provided image | |
textExtractedFromImage = extractTextFromImage.recognize_handwritten_text(imageDatas) | |
length = textExtractedFromImage.length # Get the total number | |
# Iterate through all recognized text segments | |
for i in range(length): | |
# Print each recognized text segment to the console | |
print(textExtractedFromImage[i].recognition_text) |
本文教我们如何使用 Python 将手写笔记转换为文本。要从扫描的 PDF 中提取文本,请参阅 如何使用 C# 从扫描的 PDF 中提取文本 上的文章。