자동화 된 문서 처리는 법률 및 금융 서비스에서 건강 관리 및 제조에 이르기까지 다양한 산업에서 생산성과 정확성을 크게 향상시킬 수 있습니다.이 작업을위한 강력한 도구 중 하나는 .NET에 대한 Aspose.OCR입니다, 개발자가 스캔 된 서류와 이미지에서 높은 정확도로 텍스트를 추출 할 수 있도록합니다.
완전한 예제
아래는 ASPOSE.OCR을 .NET에서 사용하여 디렉토리에서 여러 이미지에서 OCR를 실행하고 해당 텍스트 파일에 추출 된 문서를 저장하는 방법을 보여주는 완전한 예입니다.
단계별 가이드
단계 1 : OCR 엔진을 시작합니다.
원하는 언어를 설정하고 OCR 엔진을 설정합니다 (이 예제의 영어).
// Step 1: Initialize the OCR Engine
using Aspose.Ocr;
using (Ocr ocrEngine = new Ocr())
{
// Set language and other configurations if needed
ocrEngine.Language = Language.English;
// (Continue with steps below inside this using block)
}
단계 2 : 처리에 대한 이미지 충전
입력/출력 디렉토리를 설정하고 출력 폴더가 존재하는지 확인하고 이미지 파일을 나열합니다.
// Step 2: Load Images for Processing
string inputDirectory = @"path\to\input\images";
string outputDirectory = @"path\to\output\text";
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
// Get all files from the input directory (same pattern as the gist)
// TIP: to restrict to specific formats, replace "*.*" with "*.png" or "*.jpg"
string[] imageFiles = Directory.GetFiles(
inputDirectory,
"*.*",
SearchOption.TopDirectoryOnly
);
단계 3: 각 이미지에 OCR를 수행
파일을 통과하고 텍스트를 사용하여 인식 RecognizeImage(string path)
.
// Step 3: Perform OCR on Each Image
foreach (string imageFile in imageFiles)
{
try
{
// Recognize text from the image (exactly as in the gist)
string recognizedText = ocrEngine.RecognizeImage(imageFile);
// Proceed to Step 4: save text to disk...
}
catch (Exception ex)
{
Console.WriteLine($"Error processing {imageFile}: {ex.Message}");
}
}
단계 4 : 파일에 추출 된 텍스트를 저장
상호 작용을 만드는 방법 .txt
각 처리된 이미지에 대한 파일.
// Step 4: Save Extracted Text to Files
string outputFilePath = Path.Combine(
outputDirectory,
Path.GetFileNameWithoutExtension(imageFile) + ".txt"
);
File.WriteAllText(outputFilePath, recognizedText);
Console.WriteLine($"Processed: {imageFile} -> {outputFilePath}");
팁 & 트윗
- ** 필터 형식**: 같은 패턴을 사용하여
"*.png"
또는"*.jpg"
비 이미지 파일을 삭제합니다. - 리커스 하위 플러그인* : 변경
SearchOption.TopDirectoryOnly
에 대 한SearchOption.AllDirectories
.
- 리커스 하위 플러그인* : 변경
- 배가 텅 비어있는 출구*: 만약
string.IsNullOrWhiteSpace(recognizedText)
로그인하고 계속하십시오.
- 배가 텅 비어있는 출구*: 만약
- 파일러 배치 : 사용하기
Parallel.ForEach(imageFiles, file => { ... })
더 빠른 실행을 위해 (I/O 및 라이센스)
이 단계를 따르면 .NET에 대한 Aspose.OCR을 사용하여 OCR 배치를 자동화하고 다운로드 처리를 위한 깨끗한 텍스트 파일을 수출할 수 있습니다.