跳至页脚内容
使用 IRONOCR

带有计算机视觉的 OCR(示例教程)

Optical Character Recognition (OCR) with IronOCR

Optical Character Recognition (OCR) is a technology that enables machines to read and interpret text from images, making data processing and automation faster and more efficient. This article provides guidelines on using OCR with the IronOCR library and how it can enhance text recognition, automating this process.

Why OCR is Important?

OCR along with computer vision is an advanced form of Optical Character Recognition (OCR) that leverages the power of artificial intelligence and machine learning algorithms to recognize text characters from images more accurately and efficiently.

Computer vision image processing algorithms allow OCR systems to understand the context and layout of text in an image and recognize characters based on their shape and structure. OCR along with computer vision can extract text from complex images with multiple fonts, styles, and sizes, making it a valuable tool in document digitization, data extraction, and automation.

IronOCR: C# OCR Library

IronOCR is a popular OCR library that uses computer vision techniques for text extraction from images and documents. It is easy to use and integrates with multiple programming languages, including C# and VB.NET. IronOCR is available in both on-premise and cloud versions and offers a range of functionalities to process and extract text from images.

Installing IronOCR

To install IronOCR, use the following command in the NuGet Package Manager Console:

Install-Package IronOcr

OCR System with IronOCR

The following image is used to test the OCR System with Computer Vision using IronOCR.

OCR With Computer Vision (Example Tutorial), Figure 1: Image sample used for OCR detection Image sample used for OCR detection

FindTextRegion Method

The FindTextRegion method is used to identify a single text region within an image. The method takes several optional parameters, including Scale, DilationAmount, Binarize, and Invert:

  • Scale adjusts the size of the image for better text recognition.
  • DilationAmount increases the thickness of the text to enhance visibility.
  • Binarize converts the image into black and white, improving contrast.
  • Invert inverts the colors of the image, which can be useful for certain types of images.
using IronOcr;
using System;

// Initialize the IronTesseract OCR engine
var ocr = new IronTesseract();

// Create an OcrInput object for the image
using (var inputOCR = new OcrInput("test.jpg")) 
{
    // Identify a text region within the image
    inputOCR.FindTextRegion();

    // Perform OCR on the identified text region
    OcrResult result = ocr.Read(inputOCR);

    // Extract and print the recognized text
    string resultText = result.Text;
    Console.WriteLine(resultText);
}
using IronOcr;
using System;

// Initialize the IronTesseract OCR engine
var ocr = new IronTesseract();

// Create an OcrInput object for the image
using (var inputOCR = new OcrInput("test.jpg")) 
{
    // Identify a text region within the image
    inputOCR.FindTextRegion();

    // Perform OCR on the identified text region
    OcrResult result = ocr.Read(inputOCR);

    // Extract and print the recognized text
    string resultText = result.Text;
    Console.WriteLine(resultText);
}
Imports IronOcr
Imports System

' Initialize the IronTesseract OCR engine
Private ocr = New IronTesseract()

' Create an OcrInput object for the image
Using inputOCR = New OcrInput("test.jpg")
	' Identify a text region within the image
	inputOCR.FindTextRegion()

	' Perform OCR on the identified text region
	Dim result As OcrResult = ocr.Read(inputOCR)

	' Extract and print the recognized text
	Dim resultText As String = result.Text
	Console.WriteLine(resultText)
End Using
$vbLabelText   $csharpLabel

Note: After running the code, you'll see that it extracts text from the text region using a machine-learning process. The output result appears in the console with high text recognition accuracy.

OCR With Computer Vision (Example Tutorial), Figure 2: The Console results from the text extraction process The Console results from the text extraction process

FindMultipleTextRegions Method

The FindMultipleTextRegions method is similar to FindTextRegion, but it is used when there are multiple text regions in an image. It returns a list of CropRectangle objects that define the location of each text region. This method is useful when you want to extract text from an image that contains multiple sections of text.

using IronOcr;

// Initialize the IronTesseract OCR engine
var ocr = new IronTesseract();

// Create an OcrInput object for the image
using (var input = new OcrInput("test.jpg"))
{
    // Identify multiple text regions within the image
    input.FindMultipleTextRegions(Scale: 2.0, DilationAmount: -1, Binarize: true, Invert: false);

    // Perform OCR on the pre-processed image
    OcrResult result = ocr.Read(input);

    // Extract and print the recognized text
    string resultText = result.Text;
    Console.WriteLine(resultText);
}
using IronOcr;

// Initialize the IronTesseract OCR engine
var ocr = new IronTesseract();

// Create an OcrInput object for the image
using (var input = new OcrInput("test.jpg"))
{
    // Identify multiple text regions within the image
    input.FindMultipleTextRegions(Scale: 2.0, DilationAmount: -1, Binarize: true, Invert: false);

    // Perform OCR on the pre-processed image
    OcrResult result = ocr.Read(input);

    // Extract and print the recognized text
    string resultText = result.Text;
    Console.WriteLine(resultText);
}
Imports IronOcr

' Initialize the IronTesseract OCR engine
Private ocr = New IronTesseract()

' Create an OcrInput object for the image
Using input = New OcrInput("test.jpg")
	' Identify multiple text regions within the image
	input.FindMultipleTextRegions(Scale:= 2.0, DilationAmount:= -1, Binarize:= True, Invert:= False)

	' Perform OCR on the pre-processed image
	Dim result As OcrResult = ocr.Read(input)

	' Extract and print the recognized text
	Dim resultText As String = result.Text
	Console.WriteLine(resultText)
End Using
$vbLabelText   $csharpLabel

Explanation: The code snippet provided above is an example of how to use the IronOCR library to perform OCR on an image file. It first imports the IronOCR library and creates a new instance of the IronTesseract class. Then, it initializes an OcrInput object with the path of the input image file and applies some pre-processing techniques for image correction using the FindMultipleTextRegions method.

The Output of IronOCR

The output of IronOCR is very accurate, even when dealing with complex images with multiple fonts, sizes, and styles of text.

OCR accuracy is crucial when extracting data from images because the extracted text is often used for further processing, such as data analysis, manual data entry, machine learning, or natural language processing. If the extracted text contains errors, it can cause problems downstream. Additionally, IronOCR allows investigation into result objects to check confidence levels.

Use Cases of OCR Computer Vision

Optical Character Recognition (OCR) technology has revolutionized the way printed text is handled. OCR tools have become an indispensable part of document processing and data extraction. Here are some use cases of Optical Character Recognition software:

OCR License Plate Recognition

License plate recognition plays a significant role in automating traffic management, parking systems, and law enforcement activities. By implementing OCR computer vision in C#, developers can create applications that quickly and accurately identify license plates from images or live video feeds. This technology can be used to:

  • Monitor traffic violations and identify vehicles involved in criminal activities.
  • Automate the parking systems, facilitating entry and exit management and streamlining the billing process.
  • Enhance security measures by tracking and monitoring vehicle movement in restricted areas.

Extracting Text from Invoices

OCR computer vision in C# can be utilized to develop OCR applications that automate the extraction of text from invoices and other financial documents. This process can drastically reduce manual data entry errors and streamline accounting tasks. Key benefits include:

  • Increased productivity by automating the data entry process.
  • Improved accuracy, as OCR reduces the likelihood of human errors.
  • Seamless integration with accounting software and systems for efficient data management.

OCR Subtitles Generation

Creating subtitles for videos can be time-consuming and labor-intensive. OCR computer vision in C# can simplify this process by automatically detecting and transcribing the on-screen text, enabling developers to:

  • Create accurate subtitles for movies, TV shows, and online videos.
  • Enhance accessibility for individuals with hearing impairments or those who speak different languages.
  • Boost SEO efforts by providing searchable, indexable content for the video platform

OCR PDF Processing

PDFs are widely used for sharing and storing documents, but extracting text from them can be challenging. OCR computer vision in C# can help developers build OCR applications that effortlessly process PDF files and extract their content, facilitating:

Digitizing Printed Text

OCR software is widely used to digitize printed text from document images. OCR tools can extract text from scanned digital documents, PDFs, and images in various formats. This is particularly useful in document management, where you can easily search, store, and share text-based documents.

Data Extraction

OCR technology is widely used to extract data from input data such as invoices, receipts, and forms. OCR models can recognize and extract key data fields such as names, addresses, dates, and amounts. This eliminates the need for manual data entry and reduces errors in the data processing.

OCR technology is also used for image search, where you can search for images based on the text contained within them. This is particularly useful for large image libraries, where manual searching would be time-consuming.

Translation

OCR software can be used to extract text from documents in one language and translate it into another language. This is particularly useful for international businesses, where documents need to be translated quickly and accurately.

Summary

Optical character recognition (OCR) is a technology that enables computers to read text from images. OCR along with computer vision is important because it allows machines to understand and interpret the visual world, which is essential for applications such as self-driving cars, robotics, and automated document processing.

IronOCR is a powerful OCR engine that can be used to apply OCR with computer vision to accurately recognize text and perform text extraction from images. It provides a range of methods for finding and extracting text regions, including FindTextRegion, FindMultipleTextRegions, and GetTextRegions. Each method has its own set of parameters that can be used to fine-tune the OCR process and provide high OCR accuracy.

By using IronOCR, you can extract the scanned text from input images quickly and accurately using concurrency and customized configuration, which can save you time and effort when dealing with large volumes of input image data. Whether you are working with scanned documents, photographs, or screenshots, IronOCR can help you unlock the text contained within.

IronOCR offers a free trial to users who want to test the software before making a purchase decision. The license for IronOCR starts from $799 and includes support and updates for one year. With its robust features and reasonable pricing, IronOCR is a great option for anyone looking for a reliable OCR solution with high OCR accuracy.

常见问题解答

如何使用C#将图像转换为文本?

您可以使用IronOCR的OCR功能结合C#将图像转换为文本。通过使用ReadReadAsync等方法,您可以高效地处理图像以提取文本。

使用OCR和计算机视觉的好处是什么?

使用OCR与计算机视觉相结合,可以更准确地从复杂的图像布局、字体和样式中识别文本。IronOCR利用AI和机器学习增强文本提取,自动化数据处理。

如何在C#中提高OCR的准确性?

IronOCR提供了多种方法来提高OCR准确性,包括调整配置设置,使用并发,检查结果对象的可信度等级。这有助于微调OCR过程以获得更好的结果。

从图像中的多个区域提取文本的过程是什么?

要使用IronOCR从图像中的多个区域提取文本,您可以使用FindMultipleTextRegions方法。此方法返回一个CropRectangle对象列表,指示每个文本区域的位置。

OCR技术可以用于车牌识别吗?

是的,诸如IronOCR提供的OCR技术可以应用于车牌识别。通过处理车牌图像,IronOCR可以提取文本以供各种应用使用。

如何在C#项目中安装IronOCR?

您可以通过使用NuGet包管理器控制台将IronOCR安装到您的C#项目中。执行命令Install-Package IronOcr以将库添加到您的项目中。

是否有用于尝试C# OCR库的试用版?

是的,IronOCR提供免费试用版本,允许用户在购买许可证之前测试库的功能。

C#的OCR库有哪些许可选项?

IronOCR提供多种许可选项,从$liteLicense起,包括一年的支持和更新,以满足不同项目需求和预算。

Kannaopat Udonpant
软件工程师
在成为软件工程师之前,Kannapat 在日本北海道大学完成了环境资源博士学位。在攻读学位期间,Kannapat 还成为了车辆机器人实验室的成员,隶属于生物生产工程系。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程团队,专注于 IronPDF。Kannapat 珍视他的工作,因为他可以直接从编写大多数 IronPDF 代码的开发者那里学习。除了同行学习外,Kannapat 还喜欢在 Iron Software 工作的社交方面。不撰写代码或文档时,Kannapat 通常可以在他的 PS5 上玩游戏或重温《最后生还者》。