이미지에서 Optical Character Recognition(OCR)을 수행하는 것은 복잡한 작업입니다. 이 항목에서는 C#의 이미지에서 텍스트를 빠르고 쉽게 추출하는 방법을 단계별로 설명합니다. Aspose.OCR for .NET를 사용하면 몇 단계만 거치면 C#의 이미지에서 문자를 읽을 수 있습니다.
C#의 이미지에서 텍스트를 추출하는 단계
- Aspose.OCR for .NET NuGet 패키지 사용
- 먼저 Aspose.OCR namespace 참조 포함
- SetLicense 메서드를 사용하여 Aspose 라이선스 적용
- AsposeOcr Class 인스턴스의 개체 만들기
- RecognizeImage 메서드를 사용하여 OCR를 적용하여 이미지에서 텍스트를 추출합니다.
- FileStream 및 StreamWriter 클래스를 사용하여 추출된 텍스트를 텍스트 파일에 저장
위의 단계는 C#의 이미지에서 문자를 읽는 것이 매우 쉽다는 것을 보여줍니다. 위 단계에 대한 코드는 아래에 나와 있습니다.
C#의 이미지에서 텍스트를 추출하는 코드
using System; | |
using System.IO; | |
//Add Aspose.OCR for .NET package reference | |
//Use following namespaces to Extract Text from Image | |
using Aspose.OCR; | |
namespace ExtractTextFromImage | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before extracting text from image | |
//using Aspose.OCR for .NET | |
Aspose.OCR.License AsposeOCRLicense = new Aspose.OCR.License(); | |
AsposeOCRLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//Create an instance of AsposeOcr class before you can apply | |
//OCR on an image to extract the text from it | |
AsposeOcr ExtractTextFromImage = new AsposeOcr(); | |
//Read image using RecognizeImage method on which OCR need to be applied for text extraction | |
string TextExtractedFromImage = ExtractTextFromImage.RecognizeImage("ExampleOCRImageToExtractText.jpg"); | |
//Save extracted text to a text file using File Stream and StreamWriter | |
//classes of System.IO | |
FileStream FStream = new FileStream("ExtractTextFromImageUsingOCR.txt", FileMode.Create); | |
StreamWriter SWriter = new StreamWriter(FStream); | |
//Write extracted text to the file | |
SWriter.WriteLine(TextExtractedFromImage); | |
SWriter.Flush(); | |
//Close FileStream and StreamWriter bojects | |
SWriter.Close(); | |
FStream.Close(); | |
} | |
} | |
} |
접근 방식은 C# 언어를 사용하는 경우 모든 유형의 .NET 응용 프로그램에 대해 동일합니다. 이미지에서 모든 텍스트를 추출하거나 이미지에서 텍스트를 한 줄씩 읽으려면 .NET용 Aspose.OCR이 도움이 될 수 있습니다.