using IronOcr;
using IronSoftware.Drawing;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
ocrInput.LoadImage("blue_and_pink.png");
ocrInput.WithTitle("Recolored");
ocrInput.ReplaceColor(Color.Pink, Color.White, 10);
// Pink detection has 10% tolerance
ocrInput.ReplaceColor(Color.Blue, Color.Black, 5);
// Blue detection has 5% tolerance
// Export the modified image so you can manually inspect it.
foreach (var page in ocrInput.GetPages())
{
page.SaveAsImage($"black_and_white_page_{page.Index}.bmp");
}
var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Private ocrTesseract = New IronTesseract()
Private ocrInput = New OcrInput()
ocrInput.LoadImage("blue_and_pink.png")
ocrInput.WithTitle("Recolored")
ocrInput.ReplaceColor(Color.Pink, Color.White, 10)
' Pink detection has 10% tolerance
ocrInput.ReplaceColor(Color.Blue, Color.Black, 5)
' Blue detection has 5% tolerance
' Export the modified image so you can manually inspect it.
For Each page In ocrInput.GetPages()
page.SaveAsImage($"black_and_white_page_{page.Index}.bmp")
Next page
Dim ocrResult = ocrTesseract.Read(ocrInput)
Console.WriteLine(ocrResult.Text)
Install-Package IronOcr
OCR 이미지 색상 편집
OCR은 검은색 문자를 흰색 배경에서 읽을 때 더 빠르고 정확하게 작동합니다.
예를 들어 분홍색 배경에 파란색 텍스트가 있다면, OCR을 수행하기 전에 파란색을 검은색으로, 분홍색을 흰색으로 바꾸기를 원할 것입니다.
이는 System.Drawing를 사용하여 매우 시간이 많이 걸리고 느릴 수 있습니다, 하지만 IronOCR를 사용하면 완전히 자동화됩니다.
OcrInput.ReplaceColor 메서드는 문서에서 하나의 색을 다른 색으로 교체할 수 있게 합니다. 이 메서드는 적응형으로, 정확한 RGB 색과의 일치를 위한 백분율 허용오차를 지정할 수 있게 합니다. 이로 인해 Photoshop이나 ImageMagick 스크립트를 사용하여 OCR용 이미지를 준비할 필요가 없어집니다.
ReplaceColor 메서드 매개변수
첫 번째 매개변수는 대체할 색상입니다.
두 번째 매개변수는 대체 후의 색상입니다.
세 번째 선택적 매개변수는 색이 얼마나 가까워야 하는지 허용 오차를 지정하며, 이는 지정된 백분율 내에서 다양성을 허용합니다.