This gRPC service provides OCR (Optical Character Recognition) functionality via a wrapper for the Aspose OCR CLI tool. It also includes health check and documentation endpoints. The service is defined as follows:
syntax = "proto3";
option csharp_namespace = "OcrGrpcWrapper";
package ocr;
service OcrService {
rpc Process (OcrRequest) returns (OcrResponse);
rpc HealthCheck (EchoRequest) returns (OcrResponse);
rpc Documentation (Empty) returns (OcrResponse);
}
message OcrRequest {
bytes input_file = 1;
string file_type = 2;
string language = 3;
string output_format = 4;
string detect_areas_mode = 5;
string allowed_characters = 6;
string alphabet = 7;
string ignored_characters = 8;
bool auto_deskew = 9;
double rotate = 10;
bool upscale_small_font = 11;
bool auto_contrast = 12;
bool auto_denoise = 13;
}
message OcrResponse {
string output = 1;
}
message EchoRequest {
string message = 1;
}
message Empty {}Recognize text from an image using various OCR options.
- Request:
OcrRequestbytes input_file: The image file (PNG, JPEG, BMP, or TIFF) to process.string file_type: The type of the input file. Supported file types are: ".png .jpg .jpeg .bmp .ico .zip .tif .tiff .pdf .djvu"string language: The language of the text in the source image.string output_format: The format of the output (text, json, xml).string detect_areas_mode: The algorithm for detecting, ordering, and classifying content blocks.string allowed_characters: Predefined whitelist of characters the recognition engine will look for.string alphabet: A case-sensitive list of characters to be recognized.string ignored_characters: A blacklist of characters that are ignored during recognition.bool auto_deskew: Automatically correct image tilt.double rotate: Image rotation angle in degrees.bool upscale_small_font: Improve small font recognition.bool auto_contrast: Automatically improve the contrast.bool auto_denoise: Automatically reduce noise.
- Response:
OcrResponsestring output: The recognized text or data in the specified format.
For string file_type : Supported file types are:
".png" (SingleImage)
".jpg" (SingleImage)
".jpeg" (SingleImage)
".bmp" (SingleImage)
".ico" (SingleImage)
".zip" (Zip)
".tif" (TIFF)
".tiff" (TIFF)
".pdf" (PDF)
".djvu" (DJVU)
For string language : Supported file types are:
See Aspose.OCR C++ Documentation
- input_file: Ensure the file is properly encoded in base64 format.
- file_type: Make sure to use the correct file extension from the supported types.
- All other fields are optional and can be adjusted based on the specific requirements of the OCR process.
Check the health status of the service.
- Request:
EchoRequeststring message: A message to be echoed back.
- Response:
OcrResponsestring output: Echos back the input message.
Retrieve the documentation for the service.
- Request:
Empty - Response:
OcrResponsestring output: The documentation of the service.
Assuming you have an image file named example.png in the current directory.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "document",
"auto_deskew": true,
"rotate": 0,
"upscale_small_font": true,
"auto_contrast": true,
"auto_denoise": true
}' localhost:5000 ocr.OcrService/Processgrpcurl -plaintext -d '{"message": "Are you there?"}' localhost:5000 ocr.OcrService/HealthCheckExpected response:
{
"output": "Are you there?"
}grpcurl -plaintext -d '{}' localhost:5000 ocr.OcrService/DocumentationExpected response:
{
"output": "Detailed documentation of the gRPC OCR service."
}base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng"
}' localhost:5000 ocr.OcrService/Processbase64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"auto_contrast": true,
"auto_denoise": true
}' localhost:5000 ocr.OcrService/Process- Make sure you have
grpcurlinstalled on your machine. - The default gRPC server is running on
localhost:5000. Adjust the host and port accordingly if your server configuration is different. - The
input_filemust be provided in base64-encoded format. The bash command when usinggrpcurlworks to read, encode, and include the file in the request.
Assuming you have an image file named french_example.png in the current directory.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 french_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "fra",
"output_format": "xml",
"detect_areas_mode": "document",
"auto_deskew": false,
"rotate": 0,
"upscale_small_font": false,
"auto_contrast": false,
"auto_denoise": false
}' localhost:5000 ocr.OcrService/Process# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "curved_text",
"auto_deskew": true,
"rotate": 0,
"upscale_small_font": true,
"auto_contrast": true,
"auto_denoise": true
}' localhost:5000 ocr.OcrService/ProcessAssuming the image is accessible at a public URL.
grpcurl -plaintext -d '{
"input_file": "'"https://example.com/image.png"'",
"file_type": ".png",
"language": "eng",
"output_format": "text",
"detect_areas_mode": "document",
"auto_deskew": false,
"rotate": 0,
"upscale_small_font": false,
"auto_contrast": false,
"auto_denoise": false
}' localhost:5000 ocr.OcrService/Process# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"alphabet": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"auto_deskew": true,
"rotate": 0,
"upscale_small_font": true,
"auto_contrast": false,
"auto_denoise": false
}' localhost:5000 ocr.OcrService/Process# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"allowed_characters": "digits",
"auto_deskew": true,
"rotate": 0,
"upscale_small_font": true,
"auto_contrast": true,
"auto_denoise": true
}' localhost:5000 ocr.OcrService/Process- document (default): Best for large, multi-column documents, books, articles, and contracts.
- photo: Ideal for photographs or screenshots, where text may be scattered in small lines or blocks.
- combine: Combines the document and photo modes to handle complex images with isolated text blocks.
- table: Suited for scanned spreadsheets, reports, or any other structured tabular content.
- curved_text: Perfect for images with curved text lines, such as those from photographs of books or documents with page distortions.
This is the default mode and is best for large multi-column documents, books, articles, and contracts.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 document_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "document"
}' localhost:5000 ocr.OcrService/ProcessThis mode works well with lines and individual words inside photos or screenshots.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 photo_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "photo"
}' localhost:5000 ocr.OcrService/ProcessThis mode combines document and photo detection capabilities to handle complex images with isolated text blocks.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 complex_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "combine"
}' localhost:5000 ocr.OcrService/ProcessThis mode is perfect for detecting cells in tabular structures like tables and invoices.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 table_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "table"
}' localhost:5000 ocr.OcrService/ProcessThis mode auto-straightens and finds text blocks in images with curved lines, such as those in photographs of books.
# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 curved_text_example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng",
"output_format": "json",
"detect_areas_mode": "curved_text"
}' localhost:5000 ocr.OcrService/Process# Encode the image file to base64 and pass to grpcurl
base64_example=$(base64 -w 0 example.png)
grpcurl -plaintext -d '{
"input_file": "'"$base64_example"'",
"file_type": ".png",
"language": "eng"
}' localhost:5000 ocr.OcrService/Process