-
Notifications
You must be signed in to change notification settings - Fork 2
UmiOCR EN
皮卡超人 edited this page Dec 23, 2025
·
2 revisions
Language: 中文 (Chinese) | English
WodToolKit integrates UmiOCR, providing convenient image text recognition functionality. UmiOCR is an open-source OCR recognition service that supports multiple languages and output formats.
The WodToolKit.src.UmiOCR namespace provides two core classes:
-
OCR: image text recognition (/api/ocr) -
Doc: document/PDF recognition (/api/doc)
Main capabilities:
- Image text recognition
- Document/PDF recognition and generation of searchable PDF, TXT, JSONL, etc.
- Support for multiple recognition languages (Chinese, English, Chinese-English mixed, etc.)
- Support for multiple output formats (text, json, jsonl)
- Automatic angle detection
- Ignore area settings
- Custom UmiOCR service address
Before using UmiOCR functionality, you need to start the UmiOCR service. UmiOCR is an independent OCR service program that runs on http://127.0.0.1:1224 by default.
- Visit the UmiOCR official website to download and install
- Start the UmiOCR service
- Ensure the service is running on the default port 1224 (or use a custom address)
using WodToolKit.src.UmiOCR.Ocr;
using WodToolKit.src.UmiOCR.Doc;
// Image OCR (/api/ocr)
var ocr = new OCR(); // Default http://127.0.0.1:1224
var customOcr = new OCR("http://192.168.1.100:1224");
// Document OCR (/api/doc)
var doc = new Doc(); // Default http://127.0.0.1:1224// Simplest usage
string result = ocr.Ocr("image.jpg");
Console.WriteLine(result);The Ocr method supports the following parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
file |
string |
Required | Image file path |
language |
string |
"简体中文" |
Recognition language, options: Simplified Chinese, Traditional Chinese, English, Japanese, etc. |
format |
string |
"text" |
Output format, options: text (plain text), json, jsonl
|
parser |
string |
"none" |
Post-processing parser, options: none, merge_line, merge_line_v2, etc. |
angle |
bool |
false |
Whether to automatically detect image angle |
ignoreArea |
List<int[][]> |
null |
Ignore area array, each item is [[top-left x,y],[bottom-right x,y]]
|
// Recognize Simplified Chinese
string result = umiOcr.Ocr("image.jpg", language: "简体中文");
// Recognize English
string result = umiOcr.Ocr("image.jpg", language: "英文");
// Recognize Chinese-English mixed
string result = umiOcr.Ocr("image.jpg", language: "简体中文+英文");// Output plain text (default)
string textResult = umiOcr.Ocr("image.jpg", format: "text");
// Output JSON format
string jsonResult = umiOcr.Ocr("image.jpg", format: "json");
// Output JSONL format
string jsonlResult = umiOcr.Ocr("image.jpg", format: "jsonl");// Automatically detect image angle and rotate
string result = umiOcr.Ocr("image.jpg", angle: true);Ignore areas are used to specify regions in the image that do not need recognition. Each area is defined by top-left and bottom-right coordinates.
using System.Collections.Generic;
// Define ignore areas
var ignoreAreas = new List<int[][]>
{
// First ignore area: from (10, 20) to (100, 200)
new int[][] { new int[] { 10, 20 }, new int[] { 100, 200 } },
// Second ignore area: from (150, 250) to (300, 400)
new int[][] { new int[] { 150, 250 }, new int[] { 300, 400 } }
};
string result = umiOcr.Ocr("image.jpg", ignoreArea: ignoreAreas);// No post-processing (default)
string result1 = umiOcr.Ocr("image.jpg", parser: "none");
// Use line merge parser
string result2 = umiOcr.Ocr("image.jpg", parser: "merge_line");
// Use line merge parser v2
string result3 = umiOcr.Ocr("image.jpg", parser: "merge_line_v2");var ignoreAreas = new List<int[][]>
{
new int[][] { new int[] { 10, 20 }, new int[] { 100, 200 } }
};
string result = umiOcr.Ocr(
file: "image.jpg",
language: "简体中文",
format: "json",
parser: "merge_line",
angle: true,
ignoreArea: ignoreAreas
);try
{
string result = umiOcr.Ocr("image.jpg");
Console.WriteLine($"Recognition successful: {result}");
}
catch (Exception ex)
{
Console.WriteLine($"OCR recognition failed: {ex.Message}");
}public UmiOCR(string? Url = "http://127.0.0.1:1224")Parameters:
-
Url(string?, optional): UmiOCR service address, defaults to"http://127.0.0.1:1224"
public string Ocr(
string file,
string language = "简体中文",
string format = "text",
string parser = "none",
bool angle = false,
List<int[][]> ignoreArea = null
)Parameters:
-
file(string): Image file path -
language(string): Recognition language, defaults to"简体中文" -
format(string): Output format, defaults to"text" -
parser(string): Post-processing parser, defaults to"none" -
angle(bool): Whether to automatically detect image angle, defaults tofalse -
ignoreArea(List<int[][]>): Ignore area array, defaults tonull
Returns:
-
string: OCR recognition result string
Exceptions:
- Throws
Exceptionif OCR recognition fails, with error message containing the failure reason
- Service Requirement: Ensure UmiOCR service is running before use
- Image Formats: Supports common image formats (jpg, png, bmp, etc.)
- File Paths: Supports both absolute and relative paths
- Performance: OCR recognition is a network request and may take some time, recommended to use in async environments
- Error Handling: Recommended to use try-catch to catch possible exceptions
- Image text extraction
- Document scanning recognition
- Screenshot text recognition
- Batch image OCR processing
- Form data extraction