Member-only story
ASP.NET Core MVC OCR (Tesseract) Image Text Extraction Application
3 min readFeb 1, 2025
You can use OCR (Optical Character Recognition) technology to read text from an image using C#.
In an ASP.NET Core MVC project, we can perform OCR operations along with file upload functionality. When a user uploads an image, the system will automatically read the text on the image and display it on the screen.
Install Required NuGet Packages Run the following command in the Package Manager Console in Visual Studio:
Install-Package Tesseract
To open the Package Manager Console:
- Navigate to Tools > NuGet Package Manager > Package Manager Console in Visual Studio.
- Paste the above command into the console and hit Enter.
OCRHelper.cs (Helper Class for OCR Processing)
using System;
using System.IO;
using Tesseract;
using System.Drawing;
namespace OCRDemo.Helpers
{
public class OCRHelper
{
private readonly string _tessDataPath;
// Constructor to specify the tessdata path
public OCRHelper()
{
_tessDataPath = Path.Combine(Directory.GetCurrentDirectory(), "tessdata");
}
// Method to perform OCR
public string ExtractTextFromImage(string imagePath)
{
try
{
using (var engine = new TesseractEngine(_tessDataPath, "tur", EngineMode.Default))
{…