使用机器学习软件从图像中提取文本
利用机器学习从捕获的文本图像或扫描文档中提取文本是计算机视觉和自然语言处理交叉领域的一个新兴领域。 该技术利用先进的机器学习、对象识别算法、高级图形软件、深网和暗网及神经网络架构,准确识别和提取图像和扫描纸质文档中的文本信息。 通过使用光学字符识别(OCR)和深度学习等多种机器学习技术,实现了视觉场景文本检测的自动化和高效转换,将其转换为可编辑和可搜索的结构化数据,并进行对象检测。
在这个不断发展的领域,研究人员和从业者不断努力提高准确性、速度和多功能性,使得图像、机器可读数据和扫描文档中的文本检测和提取成为打印文档数字化、内容索引、翻译和无障碍增强等应用的关键组成部分。
在本文中,我们将讨论如何使用强大的机器学习算法和与文本相关的功能支持的OCR库 IronOCR 从图像中提取文本。 文本提取,也称为关键词提取,基于机器学习自动扫描和提取来自非结构化数据或公司中央数据库的相关或基本词汇和短语。
如何使用机器学习从图像中提取文本?
- 下载用于从图像中提取文本的C#库。
- 通过实例化OcrInput对象加载特定图像以进行场景文本识别。
- 使用ocrTesseract.Read方法从图片中提取数据。
- 使用Console.WriteLine方法在控制台中打印提取的文本。
- 使用CropRectangle对象对图像的区域执行OCR。
IronOCR - 光学字符识别(OCR)库
IronOCR是一款著名且先进的光学字符识别(OCR)软件,处于图像和文档文本提取技术的前沿。 由Iron Software开发的这款强大的OCR引擎旨在准确和高效地将扫描图像、PDF甚至文本照片转换为可编辑和搜索的数字内容。 凭借其对机器学习算法和神经网络的熟练运用,IronOCR提供了一个解决方案,被应用于数据提取、内容索引和要求精确文本识别的自动化过程。
其处理多种语言和不同字体的能力使其成为开发人员和企业在其软件和应用中寻找精简文本识别算法提取功能的多功能工具。 您可以使用IronOCR自动扫描文本,通过将非结构化数据转换为经过完美扫描的页面的文本提取算法来实现常见的文本识别技术。
安装IronOCR
可以使用NuGet包管理器安装IronOCR。 以下是安装IronOCR的步骤:
- 首先,创建一个新的C# Visual Studio项目或打开一个现有项目。

- 创建项目后,转到顶部菜单的工具并选择NuGet包管理器,然后选择解决方案的NuGet包管理器。

- 屏幕上将出现一个新窗口。 转到浏览选项卡,在搜索栏中输入IronOCR。
- 将出现IronOCR包列表。 选择最新的一个并点击安装。

- 这将根据您的网络情况需要几秒钟; 之后,IronOCR即可在您的C#项目中使用。
从图像检测文本到可编辑和可搜索数据
使用IronOCR,您可以轻松使用图像处理技术和机器学习提取文本。 在本节中,我们将讨论如何使用IronOCR从图像中提取文本。
using IronOcr;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the image path and perform OCR on the image
using (var ocrInput = new OcrInput(@"images\image.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}using IronOcr;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the image path and perform OCR on the image
using (var ocrInput = new OcrInput(@"images\image.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}Imports IronOcr
Imports System
' Create a new instance of the IronTesseract class
Private ocrTesseract = New IronTesseract()
' Specify the image path and perform OCR on the image
Using ocrInput As New OcrInput("images\image.png")
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text to the console
Console.WriteLine(ocrResult.Text)
End Using这段C#代码演示了IronOCR的使用,这是一个光学字符识别(OCR)库。 以下是逐步说明:
导入库:
using IronOcr; using System;using IronOcr; using System;Imports IronOcr Imports System$vbLabelText $csharpLabel代码首先导入必要的库,包括提供OCR功能的IronOcr和用于一般功能的System命名空间。
初始化IronTesseract并加载图像:
var ocrTesseract = new IronTesseract();var ocrTesseract = new IronTesseract();IRON VB CONVERTER ERROR developers@ironsoftware.com$vbLabelText $csharpLabel这行代码创建了一个IronTesseract实例,即IronOCR提供的OCR引擎。
using (var ocrInput = new OcrInput(@"images\image.png"))using (var ocrInput = new OcrInput(@"images\image.png"))Using ocrInput As New OcrInput("images\image.png")$vbLabelText $csharpLabel实例化一个OcrInput对象,提供要处理的图像的路径。 在本例中,图像文件是"images"目录中的"image.png"。
执行OCR并提取文本:
var ocrResult = ocrTesseract.Read(ocrInput);var ocrResult = ocrTesseract.Read(ocrInput);IRON VB CONVERTER ERROR developers@ironsoftware.com$vbLabelText $csharpLabel这行代码调用IronTesseract实例的Read方法,传入OcrInput对象。 此方法对提供的图像执行OCR并提取文本。
显示提取的文本:
Console.WriteLine(ocrResult.Text);Console.WriteLine(ocrResult.Text);Console.WriteLine(ocrResult.Text)$vbLabelText $csharpLabel最终,使用Console.WriteLine将提取的文本打印到控制台,显示从图像中获得的OCR结果。
此代码片段使用IronOCR对指定图像的文本识别进行OCR,并将提取的文本输出到控制台。
输入图像

输出

在图像指定区域执行OCR
您还可以使用IronOCR对图像上的特定区域执行OCR。 这里是一个代码示例:
using IronOcr;
using IronSoftware.Drawing;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the region on the image to be processed
using (var ocrInput = new OcrInput())
{
var ContentArea = new CropRectangle(x: 20, y: 20, width: 400, height: 50);
// Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea);
// Perform OCR on the specified region and extract text
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}using IronOcr;
using IronSoftware.Drawing;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the region on the image to be processed
using (var ocrInput = new OcrInput())
{
var ContentArea = new CropRectangle(x: 20, y: 20, width: 400, height: 50);
// Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea);
// Perform OCR on the specified region and extract text
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Create a new instance of the IronTesseract class
Private ocrTesseract = New IronTesseract()
' Specify the region on the image to be processed
Using ocrInput As New OcrInput()
Dim ContentArea = New CropRectangle(x:= 20, y:= 20, width:= 400, height:= 50)
' Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea)
' Perform OCR on the specified region and extract text
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text to the console
Console.WriteLine(ocrResult.Text)
End Using此C#代码使用IronOCR库进行光学字符识别(OCR)。 它首先导入必要的库,包括IronOCR和System。 创建一个IronTesseract实例,即OCR引擎。 代码使用CropRectangle设置要处理的图像的特定ContentArea,聚焦于定义的区域。 然后,图像("r3.png")在指定区域内被添加进行OCR处理。 OCR引擎读取指定的内容区域,提取文本,并将结果文本使用Console.WriteLine打印到控制台。
输出

结论
通过机器学习从图像中提取文本,特别是使用像IronOCR这样的光学字符识别(OCR)库,标志着计算机视觉和自然语言处理交叉发展的转折点。 OCR技术和深度学习技术在将视觉文本高效转换为可编辑和可搜索数据方面扮演了至关重要的角色,为文档数字化、内容索引和无障碍增强等重要目的提供了服务。
作为一个著名的OCR库,IronOCR展示了这种融合的潜力,擅长于将扫描图像和PDF精确转换为多语言和字体样式的数字可编辑内容。 其在像C#这样的编程语言中的无缝集成使实现过程更加简化,进一步放大了从图像中提取文本在众多应用和领域的变革性影响。
了解更多关于IronOCR和所有相关功能的信息请访问此链接这里。 完整的从图像中提取文本的教程可以在以下链接中找到。 IronOCR许可证可从此链接购买。