C#에서 이미지의 특정 OCR 영역을 정의하는 방법
C#에서 이미지의 특정 영역에만 OCR을 적용하려면 IronOCR의 Rectangle 객체에 x/y 좌표, width 및 height를 지정한 다음 해당 객체를 LoadImage 메서드에 전달합니다.
-
1IronOCR를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
using IronOcr; using IronSoftware.Drawing; // 1. Install IronOCR via NuGet: Install-Package IronOcr var ocr = new IronTesseract(); using var input = new OcrInput(); // 2. Create a Rectangle with coordinates var region = new Rectangle(x: 215, y: 1250, width: 1335, height: 280); // 3. Load image with region input.LoadImage("image.png", region); // 4. Extract text var result = ocr.Read(input); Console.WriteLine(result.Text);Imports IronOcr Imports IronSoftware.Drawing ' 1. Install IronOCR via NuGet: Install-Package IronOcr Dim ocr = New IronTesseract() Using input = New OcrInput() ' 2. Create a Rectangle with coordinates Dim region = New Rectangle(x:=215, y:=1250, width:=1335, height:=280) ' 3. Load image with region input.LoadImage("image.png", region) ' 4. Extract text Dim result = ocr.Read(input) Console.WriteLine(result.Text) End UsingImports IronOcr Imports IronSoftware.Drawing ' 1. Install IronOCR via NuGet: Install-Package IronOcr Dim ocr = New IronTesseract() Using input = New OcrInput() ' 2. Create a Rectangle with coordinates Dim region = New Rectangle(x:=215, y:=1250, width:=1335, height:=280) ' 3. Load image with region input.LoadImage("image.png", region) ' 4. Extract text Dim result = ocr.Read(input) Console.WriteLine(result.Text) End Using -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronOCR 사용을 시작해보세요 무료 체험
대부분의 경우, 송장의 총액이나 양식의 특정 필드처럼 이미지의 일부에서만 텍스트를 추출해야 할 때가 있습니다. 문서 전체를 스캔하는 것은 비효율적이며 관련 없는 텍스트까지 캡처하여 오류를 발생시킬 수 있습니다.
IronOCR을 사용하면 스캔할 정확한 직사각형 영역을 지정하여 정밀도, 성능 및 정확도를 향상시킬 수 있습니다. 이 가이드는 특정 OCR 영역을 정의하고, 해당 영역에서 텍스트를 추출하고, OCR 작업에 대한 좌표가 올바른지 시각적으로 확인하는 방법을 단계별로 안내합니다.
IronOCR 시작하기
이미지에서 특정 OCR 영역을 정의하는 방법
- OCR 영역 정의를 위한 C# 라이브러리 다운로드합니다.
- OCR 엔진을 인스턴스화합니다.
- 사각형을 사용하여 OCR 영역을 지정합니다.
LoadImage에 지정한 사각형을 전달하여 이미지를 로드합니다.- 추출된 데이터를 보고 조작하려면 OcrResult 속성에 접근합니다.
특정 영역에서 OCR을 수행하는 방법
특정 OCR 영역을 정의하려면 IronSoftware.Drawing 네임스페이스의 Rectangle 객체를 생성합니다. 픽셀 단위의 x 좌표, y 좌표, width, height가 필요합니다. (x, y) 좌표는 원하는 영역의 왼쪽 위 모서리를 나타냅니다.
LoadImage로 이미지를 로드할 때, 이 Rectangle을 두 번째 매개변수로 전달합니다. IronOCR은 해당 경계 상자 내의 픽셀에 대해서만 OCR 처리를 진행합니다.
구조화된 문서에서 특정 정보가 항상 예측 가능한 위치에 나타나는 송장, 스캔한 양식, 또는 신분증 처리 시 영역 OCR이 특히 유용합니다. OCR을 관련 영역으로만 제한하면 처리 속도를 크게 향상시키고 관련 없는 텍스트로 인한 오탐을 줄일 수 있습니다.
Rectangle의 좌표를 찾으려면 MS Paint와 같은 간단한 이미지 편집기를 사용할 수 있습니다. 입력 이미지를 열고 지정된 영역의 왼쪽 상단과 오른쪽 하단 모서리에 마우스를 올려놓은 후 (x, y) 픽셀 좌표를 기록하세요. 그런 다음 사각형의 속성을 계산할 수 있습니다: (x1, y1, width, height), 여기서 width = x2-x1 및 height = y2-y1입니다.
테스트에 사용할 이미지
세 단락이 담긴 샘플 이미지를 사용합니다. 두 번째 단락의 텍스트만 추출하고 나머지는 무시합니다. 이 예제는 더 큰 문서에서 특정 필드나 섹션만 추출해야 하는 경우를 보여줍니다.

코드에서 특정 영역에 OCR을 적용하는 방법
구현에는 OcrInput 객체를 생성하고 지정된 직사각형 영역으로 이미지를 로드하는 것이 포함됩니다. 이 방법은 JPG, PNG, GIF, TIFF, BMP를 포함한 다양한 이미지 형식에서 작동합니다.
using IronOcr;
using IronSoftware.Drawing;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific region as a Rectangle
// (x, y) is the top-left corner.
var ContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text
Console.WriteLine(ocrResult.Text);using IronOcr;
using IronSoftware.Drawing;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific region as a Rectangle
// (x, y) is the top-left corner.
var ContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text
Console.WriteLine(ocrResult.Text);Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Dim ocrTesseract As New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific region as a Rectangle
' (x, y) is the top-left corner.
Dim ContentArea As New Rectangle(x:=215, y:=1250, width:=1335, height:=280)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text
Console.WriteLine(ocrResult.Text)
End UsingImports IronOcr
Imports IronSoftware.Drawing
Imports System
Dim ocrTesseract As New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific region as a Rectangle
' (x, y) is the top-left corner.
Dim ContentArea As New Rectangle(x:=215, y:=1250, width:=1335, height:=280)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text
Console.WriteLine(ocrResult.Text)
End Using더 복잡한 시나리오의 경우, 동일한 이미지 내에 여러 영역을 정의할 수 있습니다. 여러 필드를 가진 양식이나 문서의 표을 처리할 때 특히 유용합니다:
using IronOcr;
using IronSoftware.Drawing;
var ocr = new IronTesseract();
// Define multiple regions for different form fields
var nameField = new Rectangle(x: 100, y: 200, width: 300, height: 50);
var dateField = new Rectangle(x: 100, y: 300, width: 200, height: 50);
var amountField = new Rectangle(x: 400, y: 500, width: 150, height: 50);
// Load the same image with a separate OcrInput per region
OcrResult nameResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", nameField);
nameResult = ocr.Read(input);
}
OcrResult dateResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", dateField);
dateResult = ocr.Read(input);
}
OcrResult amountResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", amountField);
amountResult = ocr.Read(input);
}
// Process each field separately
Console.WriteLine($"Name: {nameResult.Text}");
Console.WriteLine($"Date: {dateResult.Text}");
Console.WriteLine($"Amount: {amountResult.Text}");using IronOcr;
using IronSoftware.Drawing;
var ocr = new IronTesseract();
// Define multiple regions for different form fields
var nameField = new Rectangle(x: 100, y: 200, width: 300, height: 50);
var dateField = new Rectangle(x: 100, y: 300, width: 200, height: 50);
var amountField = new Rectangle(x: 400, y: 500, width: 150, height: 50);
// Load the same image with a separate OcrInput per region
OcrResult nameResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", nameField);
nameResult = ocr.Read(input);
}
OcrResult dateResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", dateField);
dateResult = ocr.Read(input);
}
OcrResult amountResult;
using (var input = new OcrInput())
{
input.LoadImage("form.png", amountField);
amountResult = ocr.Read(input);
}
// Process each field separately
Console.WriteLine($"Name: {nameResult.Text}");
Console.WriteLine($"Date: {dateResult.Text}");
Console.WriteLine($"Amount: {amountResult.Text}");Imports IronOcr
Imports IronSoftware.Drawing
Dim ocr = New IronTesseract()
' Define multiple regions for different form fields
Dim nameField = New Rectangle(x:=100, y:=200, width:=300, height:=50)
Dim dateField = New Rectangle(x:=100, y:=300, width:=200, height:=50)
Dim amountField = New Rectangle(x:=400, y:=500, width:=150, height:=50)
' Load the same image with a separate OcrInput per region
Dim nameResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", nameField)
nameResult = ocr.Read(input)
End Using
Dim dateResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", dateField)
dateResult = ocr.Read(input)
End Using
Dim amountResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", amountField)
amountResult = ocr.Read(input)
End Using
' Process each field separately
Console.WriteLine($"Name: {nameResult.Text}")
Console.WriteLine($"Date: {dateResult.Text}")
Console.WriteLine($"Amount: {amountResult.Text}")Imports IronOcr
Imports IronSoftware.Drawing
Dim ocr = New IronTesseract()
' Define multiple regions for different form fields
Dim nameField = New Rectangle(x:=100, y:=200, width:=300, height:=50)
Dim dateField = New Rectangle(x:=100, y:=300, width:=200, height:=50)
Dim amountField = New Rectangle(x:=400, y:=500, width:=150, height:=50)
' Load the same image with a separate OcrInput per region
Dim nameResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", nameField)
nameResult = ocr.Read(input)
End Using
Dim dateResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", dateField)
dateResult = ocr.Read(input)
End Using
Dim amountResult As OcrResult
Using input = New OcrInput()
input.LoadImage("form.png", amountField)
amountResult = ocr.Read(input)
End Using
' Process each field separately
Console.WriteLine($"Name: {nameResult.Text}")
Console.WriteLine($"Date: {dateResult.Text}")
Console.WriteLine($"Amount: {amountResult.Text}")예상 결과
콘솔 출력에는 OCR로 처리한 두 번째 단락만 표시됩니다. 특정 영역만 처리하면 이미지의 나머지 부분에 있는 관련 없는 텍스트가 결과에 영향을 주지 않습니다.

영역 OCR의 정확도는 여러 요인에 따라 달라집니다.
- 이미지 품질: 고해상도 이미지는 일반적으로 더 나은 결과를 가져옵니다. 이미지를 최적화하려면 DPI 설정을 고려하세요.
- 텍스트 방향: 텍스트가 올바르게 정렬되었는지 확인하세요. 필요 시 페이지 회전 감지를 사용하세요.
- 대비와 선명도: 텍스트 가독성을 향상시키기 위해 이미지 보정 필터를 적용하세요.
OCR 영역의 좌표를 확인하는 방법
입력 이미지에서 선택한 좌표가 올바른지 확인하려면 정의한 ContentArea를 시각화합니다. 입력 이미지에 사각형을 그리고 StampCropRectangleAndSaveAs로 새 파일에 저장하면 됩니다. 이렇게 하면 디버깅 중에 좌표를 세밀하게 조정할 수 있습니다.
이 시각화 기술은 복잡한 레이아웃을 다루거나 품질 보증 목적으로 특정 텍스트 영역 강조가 필요할 때 특히 유용합니다.
다음은 위 예시 입력 이미지에 지정된 경계 상자를 그린 후의 출력 이미지입니다.
선택한 영역을 시각화하는 방법
using IronOcr;
using IronSoftware.Drawing;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific rectangular area to scan within the image.
// The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
var ContentArea = new Rectangle(x: 4, y: 59, width: 365, height: 26);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png");using IronOcr;
using IronSoftware.Drawing;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define the specific rectangular area to scan within the image.
// The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
var ContentArea = new Rectangle(x: 4, y: 59, width: 365, height: 26);
ocrInput.LoadImage("region-input.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
// Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png");Imports IronOcr
Imports IronSoftware.Drawing
Dim ocrTesseract = New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific rectangular area to scan within the image.
' The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
Dim ContentArea As New Rectangle(x:=4, y:=59, width:=365, height:=26)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png")
End UsingImports IronOcr
Imports IronSoftware.Drawing
Dim ocrTesseract = New IronTesseract()
Using ocrInput As New OcrInput()
' Define the specific rectangular area to scan within the image.
' The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
Dim ContentArea As New Rectangle(x:=4, y:=59, width:=365, height:=26)
ocrInput.LoadImage("region-input.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png")
End Using시각화 결과

연한 파란색 사각형을 보면 두 번째 단락만 처리 영역으로 지정되었음을 확인할 수 있습니다.
영역 OCR을 사용하는 경우
영역 OCR은 다음과 같은 여러 일반적인 시나리오에 적합합니다.
- 양식 처리: 데이터가 일관된 위치에 나타나는 표준화된 양식에서 특정 필드를 추출합니다.
- 송장 처리: 전체 문서를 처리하지 않고 총액, 날짜 또는 송장 번호와 같은 특정 값을 추출합니다.
- 번호판: 번호판 인식을 사용할 때, 번호판 영역만 처리합니다.
- 신분증: 여권이나 신분증에서 특정 필드를 추출합니다.
- 스크린샷: 스크린샷의 특정 UI 요소에서 텍스트를 캡처합니다.
영역 OCR을 위한 모범 사례
영역 OCR의 정확도와 성능을 높이려면 다음 방법을 적용하세요.
- 여백 추가: 문자의 가장자리가 잘리지 않도록 텍스트 주변에 작은 여백을 포함하세요.
- 샘플 이미지로 테스트: 대량 처리를 하기 전에 항상 대표 샘플로 좌표를 확인하세요.
- 변형 처리: 스캔한 문서에서 텍스트 위치가 조금씩 달라질 수 있으므로 영역을 필요한 크기보다 약간 넓게 지정하세요.
- 성능 최적화: 멀티스레드 처리를 위해 서로 다른 영역을 병렬로 처리하세요.
- 신뢰도 모니터링: 정확성을 보장하기 위해 결과 신뢰도 점수를 확인하세요.
OCR 처리를 특정 영역에 집중함으로써 텍스트 추출 작업의 속도와 정확도를 크게 향상시킬 수 있습니다. 이러한 목표 지향적인 접근 방식은 .NET 애플리케이션에서 효율적인 문서 처리 워크플로를 구축하는 데 필수적입니다.
자주 묻는 질문
이미지에서 C#을 사용하여 특정 OCR 영역을 어떻게 정의할 수 있나요?
특정 OCR 영역을 C#에서 정의하려면 x/y 좌표, 너비, 높이를 지정하여 IronOCR의 Rectangle 객체를 사용하세요. 그런 다음 이 사각형을 LoadImage 메서드에 전달하여 목표 OCR 처리를 수행합니다.
특정 OCR 영역을 정의하는 것이 왜 유익한가요?
특정한 OCR 영역을 지정하면 이미지의 관련 부분에 집중하여 정밀성과 성능을 향상시킬 수 있으며, 관련 없는 텍스트 추출을 방지하고 오류를 줄일 수 있습니다.
C#에서 특정 이미지 영역에 대해 OCR을 수행하려면 어떤 라이브러리가 필요한가요?
IronOCR와 IronSoftware.Drawing 라이브러리가 필요합니다. IronOCR는 NuGet을 통해 설치하며, 사전 정의된 이미지 영역에 대해 OCR을 수행할 수 있게 해줍니다.
C# 애플리케이션에서 OCR을 위한 사각형 좌표를 어떻게 지정하나요?
이미지 편집기를 사용하여 상단 왼쪽 코너의 x/y 좌표를 결정하고 원하는 영역의 너비와 높이를 픽셀 단위로 설정하세요.
IronOCR를 사용하여 이미지 내 여러 영역에서 텍스트를 추출할 수 있나요?
네, IronOCR는 같은 이미지 내 여러 직사각형 영역을 정의하고 처리할 수 있어 여러 필드가 있는 양식을 처리하기에 이상적입니다.
입력 이미지에서 OCR 영역을 시각화할 수 있나요?
네, StampCropRectangleAndSaveAs 메서드를 사용하여 입력 이미지에 지정된 사각형을 그려 OCR 영역을 시각화하고 좌표 검증을 돕습니다.
지역 OCR은 어떤 애플리케이션에서 특히 유용한가요?
지역 OCR은 양식 처리, 인보이스 스캔, 차량 번호판 인식, 신분증 분석 및 스크린샷의 UI 요소에서 텍스트를 추출하는 데 유용합니다.
문서 처리에서 지역 OCR을 사용할 때의 최선의 방법은 무엇인가요?
최선의 방법에는 텍스트 주변에 여백 추가, 샘플 이미지로 테스트, 약간의 문서 변형 처리, 멀티스레딩으로 성능 최적화 및 결과 신뢰도 점수를 모니터링이 포함됩니다.
IronOCR의 지역 스캔 정확도를 어떻게 향상시킬 수 있나요?
고해상도의 이미지를 사용하고, 적절한 텍스트 방향을 보장하며, 대비 및 명료도 필터를 적용하고, 시각적으로 목표 영역을 확인하여 정확도를 향상시킬 수 있습니다.
IronOCR를 다양한 이미지 형식과 함께 사용할 수 있나요?
네, IronOCR는 다양한 이미지 형식(JPG, PNG, GIF, TIFF, BMP)을 지원하여 다양한 스캔 및 처리 요구에 유연하게 대응할 수 있습니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.