고급 읽기를 위한 OCR 설정

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronOCR는 표준 OCR를 뛰어넘는 ReadPassport, ReadLicensePlate, ReadPhoto와 같은 고급 스캔 읽기 방법을 제공합니다. 이러한 방법은 IronOcr.Extensions.AdvancedScan 패키지에 의해 구동됩니다. 이러한 메서드들이 텍스트를 처리하는 방식을 미세 조정하기 위해, IronOCR는 개발자에게 문자 허용 목록, 차단 목록, 바코드 감지, 데이터 테이블 읽기 등을 완전히 제어할 수 있는 TesseractConfiguration 클래스를 제공합니다.

이 기사에서는 고급 읽기를 위한 TesseractConfiguration 속성과 실제 시나리오에서 OCR을 구성하기 위한 실용적인 예제를 다룹니다.

IronOCR 시작하기

!{--010011000100100101000010010100100100000101010010010110010101111101010011010101000100000101010010101000101111101010001010010010010010100000101001100010111110100001001001001100010011110100001101001011--}


TesseractConfiguration 속성

TesseractConfiguration 클래스는 OCR 동작을 사용자 지정하기 위한 다음 속성을 제공합니다. 이들은 IronTesseract.Configuration를 통해 설정됩니다.

재산 유형 설명
`WhiteListCharacters` 이 문자열에 있는 문자만 OCR 출력에서 인식됩니다. 다른 모든 문자는 제외됩니다.
`BlackListCharacters` 이 문자열의 문자는 적극적으로 무시되며 OCR 출력에서 제거됩니다.
`ReadBarCodes` bool OCR 처리 중 문서 내 바코드 감지를 활성화하거나 비활성화합니다.
`ReadDataTables` bool Tesseract를 사용하여 문서 내 테이블 구조 감지를 활성화하거나 비활성화합니다.
`PageSegmentationMode` TesseractPageSegmentationMode Tesseract가 입력 이미지를 분할하는 방법을 결정합니다. 옵션에는 `AutoOsd`, `Auto`, `SingleBlock`, `SingleLine`, `SingleWord` 등이 포함됩니다.
`RenderSearchablePdf` bool 활성화되면 OCR 출력은 보이지 않는 텍스트 레이어가 포함된 검색 가능한 PDF로 저장될 수 있습니다.
`RenderHocr` bool 활성화되면 OCR 출력에 추가 처리 또는 내보내기를 위한 hOCR 데이터가 포함됩니다.
`TesseractVariables` Dictionary<끈, object> 미세 조정을 위한 저수준 Tesseract 구성 변수에 직접 액세스를 제공합니다. Tesseract 변수를 전체 목록을 참조하십시오.

이러한 고급 속성들 외에도, IronOCR는 수백 개의 기본 Tesseract 엔진 매개변수를 전문적인 사용 사례에 대해 노출하는 TesseractVariables 사전을 통해 자세한 사용자 지정을 제공합니다.

번호판을 위한 문자 허용 목록 설정

WhiteListCharacters의 일반적인 사용 사례는 대문자, 숫자, 하이픈 및 공백만 포함할 수 있는 차량 번호판에 OCR 출력을 제한하는 것입니다. 이는 엔진에게 예상 문자 집합 외의 것을 무시하도록 지시하여 잡음을 제거하고 정확도를 향상시킵니다.

입력

다음 차량 등록 기록에는 대문자 텍스트, 소문자 텍스트, 특수 기호 (@, $, #, |, *), 및 문장 부호가 섞여 있습니다. 허용 목록에는 대문자, 숫자, 하이픈, 공백만 남아야 합니다.

OCR 허용 목록 예제를 위한 혼합 문자 차량 등록 기록

암호

이 예에서는 WhiteListCharactersA-Z, 0-9, 하이픈, 및 공백으로 설정됩니다. BlackListCharacters 속성은 `, and * 같은 알려진 노이즈 기호를 필터링합니다.

:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading.cs
using IronOcr;

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

ocr.Configuration = new TesseractConfiguration
{
    // Whitelist only characters that appear on license plates
    WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ",

    // Blacklist common noise characters
    BlackListCharacters = "`~@#$%&*",
};

var ocrInput = new OcrInput();
// Load the input image
ocrInput.LoadImage("advanced-input.png");
// Perform OCR on the input image with ReadPhoto method
var results = ocr.ReadPhoto(ocrInput);

// Print the filtered text result to the console
Console.WriteLine(results.Text);
$vbLabelText   $csharpLabel

산출

OCR 출력에 허용 목록에 포함된 번호판 문자만 표시

허용 목록 필터링 결과가 분명히 보입니다:

  • "Plate: ABC-1234""P ABC-1234"가 됩니다. 소문자 단어 'late:'는 삭제되며, 번호판 번호는 정확히 보존됩니다.
  • 'VIN: 1HGBH41JXMN109186''VIN 1HGBH41JXMN109186'이 됩니다. 콜론은 삭제되지만 대문자 VIN과 전체 번호는 유지됩니다.
  • 'Owner: john.doe@email.com''O'로 변환됩니다. 전체 소문자 이메일과 구두점은 제거됩니다.
  • 'Region: CA-90210 | Zone #5''R CA-90210 Z 5'로 변환됩니다. 파이프는 (|#)와 같은 ) and hash ( 기호는 제거되지만 대문자 및 숫자는 유지됩니다.
  • 'Fee: $125.00 + tax*''F 12500'으로 변환됩니다. 달러 기호, 소수점, 더하기 기호, 소문자 'tax'는 모두 삭제됩니다.
  • 'Ref: ~record_v2^final''R 2'로 변환됩니다. 틸드(~), 밑줄, 캐럿(^), 및 모든 소문자는 제거됩니다.

바코드 및 데이터 테이블 읽기 구성

IronOCR는 문서 내에서 바코드와 구조화된 표를 텍스트와 함께 감지할 수 있습니다. 이 기능들은 TesseractConfiguration를 통해 제어됩니다:

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    // Enable barcode detection within documents
    ReadBarCodes = true,

    // Enable table structure detection
    ReadDataTables = true,
};
IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    // Enable barcode detection within documents
    ReadBarCodes = true,

    // Enable table structure detection
    ReadDataTables = true,
};
$vbLabelText   $csharpLabel
  • ReadBarCodes: true로 설정하면, IronOCR는 텍스트 외에도 문서에서 바코드를 스캔합니다. 바코드가 예상되지 않을 때 false로 설정하여 바코드 감지를 건너뛰고 처리 속도를 높입니다.
  • ReadDataTables: true로 설정된 경우, Tesseract는 문서 구조를 감지하고 보존하려고 시도합니다. 이는 송장, 보고서 및 기타 표형식 문서에 유용합니다.

이러한 옵션은 복잡한 문서에서 추출할 내용을 정확하게 제어하기 위해 WhiteListCharactersBlackListCharacters와 결합될 수 있습니다.

페이지 분할 모드 제어

PageSegmentationMode는 텍스트 인식을 시작하기 전에 입력 이미지의 레이아웃을 Tesseract에 어떻게 해석할지 알려줍니다. 문서 유형에 맞는 적절한 모드를 선택하는 것이 정확도에 직접 영향을 미칩니다.

모드 사용 사례
AutoOsd 방향 및 스크립트 감지가 포함된 자동 레이아웃 분석
Auto OSD 없이 자동 레이아웃 분석 (기본값)
SingleColumn 이미지를 텍스트의 단일 열로 가정
SingleBlock 이미지를 단일 균일한 블록의 텍스트로 가정
SingleLine 이미지를 단일 줄의 텍스트로 가정
SparseText 가능한 한 많은 텍스트를 어떤 순서로든 찾음

단일 줄을 포함하는 레이블이나 배너의 경우, SingleLine는 여러 블록 분석을 제거하여 속도와 정밀성을 모두 개선합니다:

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    PageSegmentationMode = TesseractPageSegmentationMode.SingleLine,
};

using OcrInput input = new OcrInput();
input.LoadImage("single-line-label.png");

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    PageSegmentationMode = TesseractPageSegmentationMode.SingleLine,
};

using OcrInput input = new OcrInput();
input.LoadImage("single-line-label.png");

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
$vbLabelText   $csharpLabel

불규칙한 텍스트 배치가 있는 스캔된 페이지(예: 흩어져 있는 가격이 포함된 영수증)의 경우, SparseTextAuto보다 더 많은 내용을 회복합니다:

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    PageSegmentationMode = TesseractPageSegmentationMode.SparseText,
};

using OcrInput input = new OcrInput();
input.LoadImage("receipt-scan.png");

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    PageSegmentationMode = TesseractPageSegmentationMode.SparseText,
};

using OcrInput input = new OcrInput();
input.LoadImage("receipt-scan.png");

OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
$vbLabelText   $csharpLabel

검색 가능한 PDF 및 hOCR 출력 생성

RenderSearchablePdfRenderHocr는 IronOCR가 평문 텍스트 결과와 함께 생성하는 출력 형식을 제어합니다.

RenderSearchablePdf은 기본 이미지 위에 보이지 않는 텍스트 레이어를 배치하여 사용자가 검색하고 텍스트를 복사할 수 있으면서 스캔 이미지는 계속 보이는 PDF를 생성합니다. 이것은 문서 보관 워크플로우의 표준 출력 형식입니다.

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    RenderSearchablePdf = true,
};

using OcrInput input = new OcrInput();
input.LoadPdf("scanned-document.pdf");

OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable-output.pdf");
IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    RenderSearchablePdf = true,
};

using OcrInput input = new OcrInput();
input.LoadPdf("scanned-document.pdf");

OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable-output.pdf");
$vbLabelText   $csharpLabel

RenderHocr은 hOCR 문서, 즉 각 단어에 대한 경계 상자 좌표와 함께 텍스트 내용을 인코딩하는 HTML 파일을 생성합니다. 이것은 후속 도구가 정밀한 단어 위치를 필요로 할 때 유용합니다 (예: 삭제 엔진 또는 문서 레이아웃 분석).

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    RenderHocr = true,
};

using OcrInput input = new OcrInput();
input.LoadImage("document-page.png");

OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("output.html");
IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    RenderHocr = true,
};

using OcrInput input = new OcrInput();
input.LoadImage("document-page.png");

OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("output.html");
$vbLabelText   $csharpLabel

단일 읽기 호출에서 세 가지 출력 형식(평문 텍스트, 검색 가능한 PDF 및 hOCR)이 모두 필요한 경우 두 플래그를 동시에 활성화할 수 있습니다.

국제 문서를 위한 유니코드 문자 필터링

중국어, 일본어, 한국어로 된 국제 문서의 경우, WhiteListCharactersBlackListCharacters 속성은 유니코드 문자와 함께 작동합니다. 이를 통해 특정 스크립트로 출력 제한이 가능합니다. 예를 들어, 일본어의 경우 히라가나와 가타카나만을 사용할 수 있습니다.

참고해 주세요 해당 언어 팩이 설치되었는지 확인하십시오 (예: IronOcr.Languages.Japanese) 그런 다음 진행

입력

OCR 고급 설정 일본어 입력

암호

이 예에서는 허용 목록에 히라가나, 가타카나, 숫자 및 일반적인 일본어 구두점이 포함됩니다. , , § 같은 노이즈 기호는 차단됩니다.

경고 콘솔이 유니코드 문자를 표시할 수 없을 수도 있습니다. 출력을 .txt 파일로 리다이렉션하는 것은 이러한 문자를 다룰 때 결과를 확인하는 신뢰할 수 있는 방법입니다.

:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-jp.cs
using IronOcr;
using System.IO;

IronTesseract ocr = new IronTesseract();

ocr.Configuration = new TesseractConfiguration
{
    // Whitelist only Hiragana, Katakana, numbers, and common Japanese punctuation
    WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" +
                            "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" +
                            "0123456789、。?!()¥ー",

    // Blacklist common noise/symbols you want to ignore
    BlackListCharacters = "★■§",
};

var ocrInput = new OcrInput();

// Load Japanese input image
ocrInput.LoadImage("jp.png");

// Perform OCR on the input image with ReadPhoto method
var results = ocr.ReadPhoto(ocrInput);

// Write the text result directly to a file named "output.txt"
File.WriteAllText("output.txt", results.Text);

// You can add this line to confirm the file was saved:
Console.WriteLine("OCR results saved to output.txt");
$vbLabelText   $csharpLabel

산출

OCR 고급 설정 일본어 출력

다음은 위의 입력에 대한 출력입니다.

허용 목록에는 기본 히라가나와 가타카나 문자만 포함되어 있기 때문에, プ (pu) 및 デ (de)와 같은 파생 문자는 제외됩니다. 한자, 엔 심볼, 및 전각 괄호는 허용 목록에 없기 때문에 제외됩니다. 같은 차단된 기호는 적극적으로 제거됩니다.

결론

TesseractConfiguration 클래스는 IronOCR가 고급 읽기 시나리오에서 문서를 처리하는 방식에 대해 개발자에게 세밀한 제어를 제공합니다. 문자 허용 목록을 바코드 감지, 표 읽기 및 국제 언어 지원과 결합하여, 차량 번호판, 여권, 청구서 및 다국어 콘텐츠와 같은 특정 문서 유형에 맞춤화된 OCR 파이프라인을 구축할 수 있습니다.

고급 읽기 방법 자체에 대한 자세한 내용은 ReadPassport 가이드, ReadLicensePlate 가이드Tesseract 설정 변수 전체 목록을 참조하세요.

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

시작할 준비 되셨나요?
Nuget 다운로드 5,525,971 | 버전: 2026.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronOcr
샘플을 실행하세요 이미지가 검색 가능한 텍스트로 바뀌는 것을 확인해 보세요.