# 고급 읽기를 위한 OCR 설정
IronOCR는 표준 OCR을 넘어서 `ReadPassport`, `ReadLicensePlate`, `ReadPhoto` 같은 고급 스캔 읽기 방법을 제공합니다. 이 방법들은 `IronOcr.Extensions.AdvancedScan` 패키지로 구동됩니다. 이러한 방법이 텍스트를 처리하는 방식을 세밀 조정하기 위해, IronOCR는 `TesseractConfiguration` 클래스를 제공하여 개발자에게 문자 허용 목록, 배제 목록, 바코드 감지, 데이터 테이블 읽기 등을 포함한 완전한 제어 권한을 부여합니다.
이 글에서는 실제 시나리오에서 OCR을 구성하는 실용적인 예제와 함께 고급 읽기를 위한 `TesseractConfiguration`의 속성을 다룹니다.
*as-heading:2(빠른 시작: OCR 출력 결과를 문자 화이트리스트로 제한하기)*
`Read`을 호출하기 전에 `TesseractConfiguration`에 `WhiteListCharacters`을 설정합니다. 화이트리스트에 없는 문자는 결과에서 자동으로 삭제되어 후처리 없이 노이즈가 제거됩니다.
```cs
:title=Apply a Character Whitelist in One Line
var result = new IronTesseract() { Configuration = new TesseractConfiguration { WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- " } }.Read(new OcrInput("image.png")); Console.WriteLine(result.Text);
```
<div class="hsg-featured-snippet">
<h2>고급 읽기를 위한 OCR 설정 방법</h2>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronOcr/">NuGet에서 IronOCR 설치</a></li>
<li><a href="https://www.nuget.org/packages/IronOcr.Extensions.AdvancedScan">IronOcr.Extensions.AdvancedScan</a> Install-Package</li>
<li><code>TesseractConfiguration</code> 속성을 <code>WhiteListCharacters</code> 및 <code>ReadBarCodes</code>와 같이 구성</li>
<li><code>OcrInput</code>를 사용하여 입력 이미지 로드</li>
<li><code>ReadPhoto</code>, <code>ReadLicensePlate</code>, <code>ReadPassport</code>와 같은 고급 방법을 사용하여 이미지 읽기</li>
</ol>
</div>
<br class="clear" />
## TesseractConfiguration 속성
`TesseractConfiguration` 클래스는 OCR 동작을 사용자 정의하기 위한 다음 속성을 제공합니다. 이들은 `IronTesseract.Configuration`를 통해 설정됩니다.
<table class="table" style="text-align: left;">
<tr style="background-color: rgb(241 249 251);">
<th style="text-align: left;">재산</th>
<th style="text-align: left;">유형</th>
<th style="text-align: left;">설명</th>
</tr>
<tr>
<td><code>WhiteListCharacters</code></td>
<td>string</td>
<td>이 문자열에 있는 문자만 OCR 출력에서 인식됩니다. 다른 모든 문자는 제외됩니다.</td>
</tr>
<tr>
<td><code>BlackListCharacters</code></td>
<td>string</td>
<td>이 문자열의 문자는 적극적으로 무시되며 OCR 출력에서 제거됩니다.</td>
</tr>
<tr>
<td><code>ReadBarCodes</code></td>
<td>bool</td>
<td>OCR 처리 중 문서 내 바코드 감지를 활성화하거나 비활성화합니다.</td>
</tr>
<tr>
<td><code>ReadDataTables</code></td>
<td>bool</td>
<td>Tesseract를 사용하여 문서 내 테이블 구조 감지를 활성화하거나 비활성화합니다.</td>
</tr>
<tr>
<td><code>PageSegmentationMode</code></td>
<td>TesseractPageSegmentationMode</td>
<td>Tesseract가 입력 이미지를 분할하는 방법을 결정합니다. 옵션에는 <code>AutoOsd</code>, <code>Auto</code>, <code>SingleBlock</code>, <code>SingleLine</code>, <code>SingleWord</code> 등이 포함됩니다.</td>
</tr>
<tr>
<td><code>RenderSearchablePdf</code></td>
<td>bool</td>
<td>활성화되면 OCR 출력은 보이지 않는 텍스트 레이어가 포함된 검색 가능한 PDF로 저장될 수 있습니다.</td>
</tr>
<tr>
<td><code>RenderHocr</code></td>
<td>bool</td>
<td>활성화되면 OCR 출력에 추가 처리 또는 내보내기를 위한 hOCR 데이터가 포함됩니다.</td>
</tr>
<tr>
<td><code>TesseractVariables</code></td>
<td>Dictionary<string, object></td>
<td>세밀한 제어를 위해 하위 레벨 Tesseract 구성 변수에 직접 액세스할 수 있습니다.</td>
</tr>
</table>
`TesseractVariables` 사전은 여전히 더 나아가고, 고급 속성이 충분하지 않은 경우 수백 가지의 기본 Tesseract 엔진 매개변수를 제공합니다.
아래 예시는 문자 화이트리스트부터 시작하여 각 속성 그룹을 보여줍니다.
## 번호판을 위한 문자 허용 목록 설정
`WhiteListCharacters`의 일반적인 사용 사례는 대문자, 숫자, 하이픈 및 공백만 허용되는 자동차 번호판에 OCR 출력을 제한하는 것입니다. 이는 엔진에게 예상 문자 집합 외의 것을 무시하도록 지시하여 잡음을 제거하고 정확도를 향상시킵니다.
### 입력
다음 차량 등록 기록에는 대문자 텍스트, 소문자 텍스트, 특수 기호 (`@`, `$`, `#`, `|`, `*`), 및 구두점이 혼합되어 있습니다.
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/advanced-input.webp" alt="OCR 허용 목록 예제를 위한 혼합 문자 차량 등록 기록" class="img-responsive add-shadow" />
</div>
</div>
`BlackListCharacters`는 `, and `*` 등의 알려진 잡음 기호를 적극적으로 제외하여 허용 목록을 보완합니다.
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading.cs
```
### 산출
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/advanced-output-english.webp" alt="OCR 출력에 허용 목록에 포함된 번호판 문자만 표시" class="img-responsive add-shadow" />
</div>
</div>
허용 목록 필터링 결과가 분명히 보입니다:
- **"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'**로 변환됩니다. 물결표 (`~`), 밑줄, 캐럿 (`^`), 및 모든 소문자 문자는 제거됩니다.
같은 `WhiteListCharacters` 및 `BlackListCharacters` 접근법은 자동차 번호판뿐만 아니라 모든 문서 유형에 대해 작동합니다. 다음 섹션에서는 동일한 과정에서 바코드와 테이블 구조를 모두 감지하도록 읽기 기능을 확장하는 방법을 보여줍니다.
## 바코드 및 데이터 테이블 읽기 구성
IronOCR는 문서 내에서 바코드와 구조화된 표를 텍스트와 함께 감지할 수 있습니다. 이 기능은 `TesseractConfiguration`를 통해 제어됩니다:
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-3.cs
```
- **ReadBarCodes**: `true`로 설정하면 IronOCR는 텍스트 외에도 문서에서 바코드를 검색합니다. 바코드를 기대하지 않을 때는 바코드 감지를 건너뛰고 처리 속도를 높이기 위해 `false`으로 설정하십시오.
- **ReadDataTables**: `true`로 설정하면 Tesseract는 문서의 테이블 구조를 감지하고 보존하려고 시도합니다. 이는 송장, 보고서 및 기타 표형식 문서에 유용합니다.
이 옵션들은 `WhiteListCharacters` 및 `BlackListCharacters`와 결합되어 복잡한 문서에서 추출할 내용을 정확하게 제어할 수 있습니다.
필터링 및 감지 기능은 추출될 내용을 제어하는 반면, 레이아웃 해석은 별개의 문제입니다. 다음 섹션에서는 문서 유형에 맞는 정확한 `PageSegmentationMode`을 선택하는 방법을 다룹니다.
## 페이지 분할 모드 제어
`PageSegmentationMode`는 인식 전에 Tesseract가 입력 이미지를 어떻게 세그먼트화할지를 설명합니다. 주어진 레이아웃에 맞지 않는 모드를 선택하면 엔진이 텍스트를 잘못 읽거나 완전히 건너뛸 수 있습니다.
| 모드 |사용 사례|
|---|---|
| `AutoOsd` | 방향 및 스크립트 감지가 포함된 자동 레이아웃 분석 |
| `Auto` | OSD 없이 자동 레이아웃 분석 (기본값) |
| `SingleColumn` | 이미지를 텍스트의 단일 열로 가정 |
| `SingleBlock` | 이미지를 단일 균일한 블록의 텍스트로 가정 |
| `SingleLine` | 이미지를 단일 줄의 텍스트로 가정 |
| `SparseText` | 가능한 한 많은 텍스트를 어떤 순서로든 찾음 |
한 줄로 된 레이블이나 배너의 경우 `SingleLine`은 다중 블록 분석을 제거하고 속도와 정확성을 모두 향상시킵니다.
### 입력
`single-line-label.png`은 정확히 한 줄의 굵은 코리어 텍스트: `SHIPPING LABEL: TRK-2024-XR9-001`로 된 좁은 배송 라벨입니다.
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/single-line-label.webp" alt="OCR SingleLine 분할 모드용 단일 라인 배송 라벨" class="img-responsive add-shadow" />
</div>
</div>
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-4.cs
```
불규칙한 텍스트 배치가 있는 스캔 페이지의 경우, `SparseText`은 `Auto`보다 더 많은 내용을 복구합니다.
### 입력
`receipt-scan.png`는 네 줄 항목 (커피, 머핀, 주스, 그래놀라 바), 점선 구분자, 소계, 세금 및 총액이 포함된 코너 마켓의 열영수증입니다. 이는 고정 블록 분할 방식이 서로 다른 수평 위치에 있는 항목을 누락시키는 레이아웃 유형입니다.
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/receipt-scan.webp" alt="OCR 희소텍스트 분할 모드용 감열 영수증" class="img-responsive add-shadow" />
</div>
</div>
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-5.cs
```
문서 유형에 맞게 레이아웃 분할을 조정한 후, 다음 단계는 후속 처리를 위한 출력 형식을 제어하는 것입니다.
## 검색 가능한 PDF 및 hOCR 출력 생성
`RenderSearchablePdf`과 `RenderHocr`는 IronOCR가 단순 텍스트 결과와 함께 생성하는 출력 형식을 제어합니다.
**`RenderSearchablePdf`**는 원본 이미지 위에 보이지 않는 텍스트 레이어를 삽입하여 사용자가 검색하고 텍스트를 복사할 수 있는 PDF를 만들며 스캔된 이미지는 계속 보입니다. 이것은 문서 보관 워크플로우의 표준 출력 형식입니다.
### 입력
`scanned-document.pdf`은 IronOCR Solutions Ltd.에서 발송한 2024년 3월 15일자 한 페이지 비즈니스 편지입니다 (참조: DOC-2024-OCR-0315). 결과는 `searchable-output.pdf`로 저장됩니다.
<iframe loading="lazy" src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/scanned-document.pdf" width="100%" height="300px" style="margin-bottom: 1rem;"></iframe>
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-6.cs
```
### 산출
출력 파일은 입력 파일과 외관상 동일하지만 숨겨진 텍스트 레이어가 포함된 PDF 파일입니다. `searchable-output.pdf`을 열고 Ctrl+F를 사용하여 삽입된 텍스트가 검색 가능하고 복사 가능하도록 확인합니다.
<iframe loading="lazy" src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/searchable-output.pdf" width="100%" height="300px" style="margin-bottom: 1rem;"></iframe>
**`RenderHocr`**은 텍스트 콘텐츠와 각 단어에 대한 경계 상자 좌표를 함께 인코딩하는 HTML 파일인 hOCR 문서를 생성합니다. 이는 하위 도구, 예를 들어 문서 내용 삭제 엔진이나 문서 레이아웃 분석 도구에서 정확한 단어 위치가 필요할 때 유용합니다.
### 입력
`document-page.png`은 "2024년 1분기 요약"이라는 제목과 수익, 운영 비용 및 성장 동인을 다루는 두 개의 단락으로 구성된 문서 페이지입니다. 결과는 `output.html`로 저장됩니다.
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/document-page.webp" alt="hOCR 경계 상자 출력을 위한 문서 페이지 입력" class="img-responsive add-shadow" />
</div>
</div>
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-7.cs
```
### 산출
`output.html`은 인식된 각 단어를 경계 상자 좌표와 함께 인코딩합니다. 파일을 브라우저에서 열어 hOCR 구조를 검사하거나, 레이아웃 분석 또는 수정 작업을 위해 하위 도구로 전달하십시오.
<iframe loading="lazy" src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/output.html" width="100%" height="200px" style="margin-bottom: 1rem;"></iframe>
단일 읽기 호출에서 세 가지 출력 형식(평문 텍스트, 검색 가능한 PDF 및 hOCR)이 모두 필요한 경우 두 플래그를 동시에 활성화할 수 있습니다.
이러한 출력 플래그는 비라틴 문자 체계를 포함하여 읽는 언어와 관계없이 작동합니다. 다음 섹션에서는 일본어 텍스트에 문자 필터링을 적용하는 방법을 보여줍니다.
## 국제 문서를 위한 유니코드 문자 필터링
중국어, 일본어 또는 한국어로 된 국제 문서의 경우 `WhiteListCharacters` 및 `BlackListCharacters` 속성은 유니코드 문자와 함께 작동합니다. 이를 통해 특정 스크립트로 출력 제한이 가능합니다. 예를 들어, 일본어의 경우 히라가나와 가타카나만을 사용할 수 있습니다.
[[i:( 해당 언어 팩이 설치되었는지 확인하십시오 (예: [IronOcr.Languages.Japanese](https://www.nuget.org/packages/IronOcr.Languages.Japanese)) 그런 다음 진행 )]]
### 입력
문서에는 제목(테스트), 히라가나와 가타카나를 유성부호 변형(프, е)과 혼합한 일본어 문장, 블랙리스트에 등록된 노이즈 기호(★, ■) 및 한자(価格)가 포함된 가격 라인, 또 다른 블랙리스트에 등록된 기호(§), 추가 한자(購入), 추가 유성부호 변형(프, Desc) 및 기본 가타카나(메모, ER)가 포함된 메모 라인이 포함되어 있습니다. 화이트리스트는 기본 히라가나, 기본 가타카나, 숫자 및 일반적인 일본어 구두점만 통과시킵니다. 세 가지 노이즈 기호는 명시적으로 블랙리스트에 등록되어 있습니다.
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/advanced-input-jp.webp" alt="OCR 고급 설정 일본어 입력" class="img-responsive add-shadow" />
</div>
</div>
히라가나와 가타카나에 대한 유니코드 문자 범위는 `WhiteListCharacters`에서 문자열 리터럴로 전달되며, 잡음 기호는 `BlackListCharacters`에 나열됩니다.
[[w:( 콘솔이 유니코드 문자를 표시할 수 없을 수도 있습니다. 출력을 .txt 파일로 리다이렉션하는 것은 이러한 문자를 다룰 때 결과를 확인하는 신뢰할 수 있는 방법입니다.)]]
```cs
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-jp.cs
```
### 산출
<div class="content-img-align-center">
<div class="center-image-wrapper" style="width=50%">
<img src="/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/jp-output.webp" alt="OCR 고급 설정 일본어 출력" class="img-responsive add-shadow" />
</div>
</div>
필터링이 완료된 전체 출력 결과는 [jp-output.txt](/static-assets/ocr/how-to/ocr-configurations-for-advanced-reading/jp-output.txt) 라는 텍스트 파일로 제공됩니다.
화이트리스트에는 기본 히라가나와 가타카나 문자만 포함되어 있으므로 プ(pu) 및 デ(de)와 같은 파생 유성 문자는 제외됩니다. 価格(가격)과 購入(구매)와 같은 한자는 허용된 문자 목록에 포함되지 않으므로 제외됩니다. 허용 목록과 상관없이 `★`, `■`, 및 `§` 같은 배제된 기호는 적극적으로 제거됩니다.
## 다음엔 어디로 가야 할까요?
이제 고급 읽기 시나리오에 맞게 IronOCR 구성하는 방법을 이해했으니 다음을 살펴보세요.
- [여권](https://ironsoftware.com/csharp/ocr/how-to/read-passport/) 및 [차량 번호판](https://ironsoftware.com/csharp/ocr/how-to/read-license-plate/) 과 같은 특정 문서 유형을 읽는 것
- [바코드 및 QR 코드 판독을](https://ironsoftware.com/csharp/ocr/how-to/barcodes/) 독립형 OCR 사용 사례로 활용
- 처리된 결과에서 [hOCR 및 검색 가능한 PDF 내보내기](https://ironsoftware.com/csharp/ocr/how-to/html-hocr-export/)
프로덕션 사용을 위해, 워터마크 제거 및 전체 기능에 액세스하려면 [라이센스 획득](https://ironsoftware.com/csharp/ocr/licensing/)을 기억하세요.
IronOCR는 표준 OCR을 넘어서 ReadPassport, ReadLicensePlate, ReadPhoto 같은 고급 스캔 읽기 방법을 제공합니다. 이 방법들은 IronOcr.Extensions.AdvancedScan 패키지로 구동됩니다. 이러한 방법이 텍스트를 처리하는 방식을 세밀 조정하기 위해, IronOCR는 TesseractConfiguration 클래스를 제공하여 개발자에게 문자 허용 목록, 배제 목록, 바코드 감지, 데이터 테이블 읽기 등을 포함한 완전한 제어 권한을 부여합니다.
이 글에서는 실제 시나리오에서 OCR을 구성하는 실용적인 예제와 함께 고급 읽기를 위한 TesseractConfiguration의 속성을 다룹니다.
빠른 시작: OCR 출력 결과를 문자 화이트리스트로 제한하기
Read을 호출하기 전에 TesseractConfiguration에 WhiteListCharacters을 설정합니다. 화이트리스트에 없는 문자는 결과에서 자동으로 삭제되어 후처리 없이 노이즈가 제거됩니다.
1Install IronOCR with NuGet Package Manager
PM > Install-Package IronOcr
Install-Package IronOcr
2다음 코드 조각을 복사하여 실행하세요.
var result = new IronTesseract() { Configuration = new TesseractConfiguration { WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- " } }.Read(new OcrInput("image.png")); Console.WriteLine(result.Text);
var result = new IronTesseract() { Configuration = new TesseractConfiguration { WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- " } }.Read(new OcrInput("image.png")); Console.WriteLine(result.Text);
TesseractConfiguration 속성을 WhiteListCharacters 및 ReadBarCodes와 같이 구성
OcrInput를 사용하여 입력 이미지 로드
ReadPhoto, ReadLicensePlate, ReadPassport와 같은 고급 방법을 사용하여 이미지 읽기
TesseractConfiguration 속성
TesseractConfiguration 클래스는 OCR 동작을 사용자 정의하기 위한 다음 속성을 제공합니다. 이들은 IronTesseract.Configuration를 통해 설정됩니다.
재산
유형
설명
WhiteListCharacters
string
이 문자열에 있는 문자만 OCR 출력에서 인식됩니다. 다른 모든 문자는 제외됩니다.
BlackListCharacters
string
이 문자열의 문자는 적극적으로 무시되며 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<string, object>
세밀한 제어를 위해 하위 레벨 Tesseract 구성 변수에 직접 액세스할 수 있습니다.
TesseractVariables 사전은 여전히 더 나아가고, 고급 속성이 충분하지 않은 경우 수백 가지의 기본 Tesseract 엔진 매개변수를 제공합니다.
아래 예시는 문자 화이트리스트부터 시작하여 각 속성 그룹을 보여줍니다.
번호판을 위한 문자 허용 목록 설정
WhiteListCharacters의 일반적인 사용 사례는 대문자, 숫자, 하이픈 및 공백만 허용되는 자동차 번호판에 OCR 출력을 제한하는 것입니다. 이는 엔진에게 예상 문자 집합 외의 것을 무시하도록 지시하여 잡음을 제거하고 정확도를 향상시킵니다.
입력
다음 차량 등록 기록에는 대문자 텍스트, 소문자 텍스트, 특수 기호 (@, $, #, |, *), 및 구두점이 혼합되어 있습니다.
BlackListCharacters는 , and *` 등의 알려진 잡음 기호를 적극적으로 제외하여 허용 목록을 보완합니다.
using IronOcr;// Initialize the Tesseract OCR engineIronTesseract ocr = new IronTesseract();ocr.Configuration = new TesseractConfiguration{ // Whitelist only characters that appear on license platesWhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ", // Blacklist common noise charactersBlackListCharacters = "`~@#$%&*",};var ocrInput = new OcrInput();// Load the input imageocrInput.LoadImage("advanced-input.png");// Perform OCR on the input image with ReadPhoto methodvar results = ocr.ReadPhoto(ocrInput);// Print the filtered text result to the consoleConsole.WriteLine(results.Text);
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);
ImportsIronOcr' Initialize the Tesseract OCR engineDim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { ' Whitelist only characters that appear on license plates .WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ", ' Blacklist common noise characters .BlackListCharacters = "`~@#$%&*"}Dim ocrInput As New OcrInput()' Load the input imageocrInput.LoadImage("advanced-input.png")' Perform OCR on the input image with ReadPhoto methodDim results = ocr.ReadPhoto(ocrInput)' Print the filtered text result to the consoleConsole.WriteLine(results.Text)
Imports IronOcr
' Initialize the Tesseract OCR engine
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
' Whitelist only characters that appear on license plates
.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ",
' Blacklist common noise characters
.BlackListCharacters = "`~@#$%&*"
}
Dim ocrInput As New OcrInput()
' Load the input image
ocrInput.LoadImage("advanced-input.png")
' Perform OCR on the input image with ReadPhoto method
Dim results = ocr.ReadPhoto(ocrInput)
' Print the filtered text result to the console
Console.WriteLine(results.Text)
산출
허용 목록 필터링 결과가 분명히 보입니다:
**"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'**로 변환됩니다. 물결표 (~), 밑줄, 캐럿 (^), 및 모든 소문자 문자는 제거됩니다.
같은 WhiteListCharacters 및 BlackListCharacters 접근법은 자동차 번호판뿐만 아니라 모든 문서 유형에 대해 작동합니다. 다음 섹션에서는 동일한 과정에서 바코드와 테이블 구조를 모두 감지하도록 읽기 기능을 확장하는 방법을 보여줍니다.
바코드 및 데이터 테이블 읽기 구성
IronOCR는 문서 내에서 바코드와 구조화된 표를 텍스트와 함께 감지할 수 있습니다. 이 기능은 TesseractConfiguration를 통해 제어됩니다:
IronTesseract ocr = new IronTesseract();ocr.Configuration = new TesseractConfiguration{ // Enable barcode detection within documentsReadBarCodes = true, // Enable table structure detectionReadDataTables = true,};
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
// Enable barcode detection within documents
ReadBarCodes = true,
// Enable table structure detection
ReadDataTables = true,
};
Dim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .ReadBarCodes = True, .ReadDataTables = True}
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.ReadBarCodes = True,
.ReadDataTables = True
}
ReadBarCodes: true로 설정하면 IronOCR는 텍스트 외에도 문서에서 바코드를 검색합니다. 바코드를 기대하지 않을 때는 바코드 감지를 건너뛰고 처리 속도를 높이기 위해 false으로 설정하십시오.
ReadDataTables: true로 설정하면 Tesseract는 문서의 테이블 구조를 감지하고 보존하려고 시도합니다. 이는 송장, 보고서 및 기타 표형식 문서에 유용합니다.
이 옵션들은 WhiteListCharacters 및 BlackListCharacters와 결합되어 복잡한 문서에서 추출할 내용을 정확하게 제어할 수 있습니다.
필터링 및 감지 기능은 추출될 내용을 제어하는 반면, 레이아웃 해석은 별개의 문제입니다. 다음 섹션에서는 문서 유형에 맞는 정확한 PageSegmentationMode을 선택하는 방법을 다룹니다.
페이지 분할 모드 제어
PageSegmentationMode는 인식 전에 Tesseract가 입력 이미지를 어떻게 세그먼트화할지를 설명합니다. 주어진 레이아웃에 맞지 않는 모드를 선택하면 엔진이 텍스트를 잘못 읽거나 완전히 건너뛸 수 있습니다.
모드
사용 사례
AutoOsd
방향 및 스크립트 감지가 포함된 자동 레이아웃 분석
Auto
OSD 없이 자동 레이아웃 분석 (기본값)
SingleColumn
이미지를 텍스트의 단일 열로 가정
SingleBlock
이미지를 단일 균일한 블록의 텍스트로 가정
SingleLine
이미지를 단일 줄의 텍스트로 가정
SparseText
가능한 한 많은 텍스트를 어떤 순서로든 찾음
한 줄로 된 레이블이나 배너의 경우 SingleLine은 다중 블록 분석을 제거하고 속도와 정확성을 모두 향상시킵니다.
입력
single-line-label.png은 정확히 한 줄의 굵은 코리어 텍스트: SHIPPING LABEL: TRK-2024-XR9-001로 된 좁은 배송 라벨입니다.
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);
ImportsIronOcrDim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .PageSegmentationMode = TesseractPageSegmentationMode.SingleLine}Using input As New OcrInput() input.LoadImage("single-line-label.png") Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)EndUsing
Imports IronOcr
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine
}
Using input As New OcrInput()
input.LoadImage("single-line-label.png")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
불규칙한 텍스트 배치가 있는 스캔 페이지의 경우, SparseText은 Auto보다 더 많은 내용을 복구합니다.
입력
receipt-scan.png는 네 줄 항목 (커피, 머핀, 주스, 그래놀라 바), 점선 구분자, 소계, 세금 및 총액이 포함된 코너 마켓의 열영수증입니다. 이는 고정 블록 분할 방식이 서로 다른 수평 위치에 있는 항목을 누락시키는 레이아웃 유형입니다.
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);
ImportsIronTesseractDim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .PageSegmentationMode = TesseractPageSegmentationMode.SparseText}Using input As New OcrInput() input.LoadImage("receipt-scan.png") Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)EndUsing
Imports IronTesseract
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.PageSegmentationMode = TesseractPageSegmentationMode.SparseText
}
Using input As New OcrInput()
input.LoadImage("receipt-scan.png")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
문서 유형에 맞게 레이아웃 분할을 조정한 후, 다음 단계는 후속 처리를 위한 출력 형식을 제어하는 것입니다.
검색 가능한 PDF 및 hOCR 출력 생성
RenderSearchablePdf과 RenderHocr는 IronOCR가 단순 텍스트 결과와 함께 생성하는 출력 형식을 제어합니다.
**RenderSearchablePdf**는 원본 이미지 위에 보이지 않는 텍스트 레이어를 삽입하여 사용자가 검색하고 텍스트를 복사할 수 있는 PDF를 만들며 스캔된 이미지는 계속 보입니다. 이것은 문서 보관 워크플로우의 표준 출력 형식입니다.
입력
scanned-document.pdf은 IronOCR Solutions Ltd.에서 발송한 2024년 3월 15일자 한 페이지 비즈니스 편지입니다 (참조: DOC-2024-OCR-0315). 결과는 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");
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");
ImportsIronTesseractDim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .RenderSearchablePdf = True}Using input As New OcrInput() input.LoadPdf("scanned-document.pdf") Dim result AsOcrResult = ocr.Read(input) result.SaveAsSearchablePdf("searchable-output.pdf")EndUsing
Imports IronTesseract
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.RenderSearchablePdf = True
}
Using input As New OcrInput()
input.LoadPdf("scanned-document.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable-output.pdf")
End Using
산출
출력 파일은 입력 파일과 외관상 동일하지만 숨겨진 텍스트 레이어가 포함된 PDF 파일입니다. searchable-output.pdf을 열고 Ctrl+F를 사용하여 삽입된 텍스트가 검색 가능하고 복사 가능하도록 확인합니다.
**RenderHocr**은 텍스트 콘텐츠와 각 단어에 대한 경계 상자 좌표를 함께 인코딩하는 HTML 파일인 hOCR 문서를 생성합니다. 이는 하위 도구, 예를 들어 문서 내용 삭제 엔진이나 문서 레이아웃 분석 도구에서 정확한 단어 위치가 필요할 때 유용합니다.
입력
document-page.png은 "2024년 1분기 요약"이라는 제목과 수익, 운영 비용 및 성장 동인을 다루는 두 개의 단락으로 구성된 문서 페이지입니다. 결과는 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");
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");
ImportsIronOcrDim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .RenderHocr = True}Using input As New OcrInput() input.LoadImage("document-page.png") Dim result AsOcrResult = ocr.Read(input) result.SaveAsHocrFile("output.html")EndUsing
Imports IronOcr
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.RenderHocr = True
}
Using input As New OcrInput()
input.LoadImage("document-page.png")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsHocrFile("output.html")
End Using
산출
output.html은 인식된 각 단어를 경계 상자 좌표와 함께 인코딩합니다. 파일을 브라우저에서 열어 hOCR 구조를 검사하거나, 레이아웃 분석 또는 수정 작업을 위해 하위 도구로 전달하십시오.
단일 읽기 호출에서 세 가지 출력 형식(평문 텍스트, 검색 가능한 PDF 및 hOCR)이 모두 필요한 경우 두 플래그를 동시에 활성화할 수 있습니다.
이러한 출력 플래그는 비라틴 문자 체계를 포함하여 읽는 언어와 관계없이 작동합니다. 다음 섹션에서는 일본어 텍스트에 문자 필터링을 적용하는 방법을 보여줍니다.
국제 문서를 위한 유니코드 문자 필터링
중국어, 일본어 또는 한국어로 된 국제 문서의 경우 WhiteListCharacters 및 BlackListCharacters 속성은 유니코드 문자와 함께 작동합니다. 이를 통해 특정 스크립트로 출력 제한이 가능합니다. 예를 들어, 일본어의 경우 히라가나와 가타카나만을 사용할 수 있습니다.
문서에는 제목(테스트), 히라가나와 가타카나를 유성부호 변형(프, е)과 혼합한 일본어 문장, 블랙리스트에 등록된 노이즈 기호(★, ■) 및 한자(価格)가 포함된 가격 라인, 또 다른 블랙리스트에 등록된 기호(§), 추가 한자(購入), 추가 유성부호 변형(프, Desc) 및 기본 가타카나(메모, ER)가 포함된 메모 라인이 포함되어 있습니다. 화이트리스트는 기본 히라가나, 기본 가타카나, 숫자 및 일반적인 일본어 구두점만 통과시킵니다. 세 가지 노이즈 기호는 명시적으로 블랙리스트에 등록되어 있습니다.
히라가나와 가타카나에 대한 유니코드 문자 범위는 WhiteListCharacters에서 문자열 리터럴로 전달되며, 잡음 기호는 BlackListCharacters에 나열됩니다.
경고: 콘솔이 유니코드 문자를 표시할 수 없을 수도 있습니다. 출력을 .txt 파일로 리다이렉션하는 것은 이러한 문자를 다룰 때 결과를 확인하는 신뢰할 수 있는 방법입니다.
using IronOcr;using System.IO;IronTesseract ocr = new IronTesseract();ocr.Configuration = new TesseractConfiguration{ // Whitelist only Hiragana, Katakana, numbers, and common Japanese punctuationWhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" + "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" + "0123456789、。?!()¥ー", // Blacklist common noise/symbols you want to ignoreBlackListCharacters = "★■§",};var ocrInput = new OcrInput();// Load Japanese input imageocrInput.LoadImage("jp.png");// Perform OCR on the input image with ReadPhoto methodvar 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");
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");
ImportsIronOcrImportsSystem.IODim ocr As New IronTesseract()ocr.Configuration = New TesseractConfigurationWith { .WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" & "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" & "0123456789、。?!()¥ー", .BlackListCharacters = "★■§"}Dim ocrInput As New OcrInput()' Load Japanese input imageocrInput.LoadImage("jp.png")' Perform OCR on the input image with ReadPhoto methodDim 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")
Imports IronOcr
Imports System.IO
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" &
"アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" &
"0123456789、。?!()¥ー",
.BlackListCharacters = "★■§"
}
Dim ocrInput As New OcrInput()
' Load Japanese input image
ocrInput.LoadImage("jp.png")
' Perform OCR on the input image with ReadPhoto method
Dim 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")
화이트리스트에는 기본 히라가나와 가타카나 문자만 포함되어 있으므로 プ(pu) 및 デ(de)와 같은 파생 유성 문자는 제외됩니다. 価格(가격)과 購入(구매)와 같은 한자는 허용된 문자 목록에 포함되지 않으므로 제외됩니다. 허용 목록과 상관없이 ★, ■, 및 § 같은 배제된 기호는 적극적으로 제거됩니다.
다음엔 어디로 가야 할까요?
이제 고급 읽기 시나리오에 맞게 IronOCR 구성하는 방법을 이해했으니 다음을 살펴보세요.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.