public class AsposeOCR extends Object implements AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DebugMode
Enables debug mode.
|
static String |
DebugModeSaveDirectory
Directory where debug results will be saved.
|
| Constructor and Description |
|---|
AsposeOCR()
Public constructor.
|
| Modifier and Type | Method and Description |
|---|---|
ArrayList<SkewOutput> |
CalculateSkew(OcrInput input)
Calculates the skew angles of an images.
|
void |
close() |
boolean |
CompareImageTexts(String fullPath1,
String fullPath2)
Check if two images contain the same text.
|
boolean |
CompareImageTexts(String fullPath1,
String fullPath2,
RecognitionSettings settings)
Check if two images contain the same text.
|
boolean |
CompareImageTexts(String fullPath1,
String fullPath2,
RecognitionSettings settings,
boolean ignoreCase)
Check if two images contain the same text.
|
String |
CorrectSpelling(String text,
SpellCheckLanguage language)
Corrects text (replaces misspelled words).
|
String |
CorrectSpelling(String text,
SpellCheckLanguage language,
String dictionaryPath)
Corrects text (replaces misspelled words).
|
static void |
debugModeCheckAndDrawDsr(BufferedImage image,
int imgIdx,
ArrayList<Map.Entry<RegionTypes,Rectangle>> list) |
static void |
debugModeCheckAndExecute(BufferedImage image,
String fileName,
List<Rectangle> rectangles) |
static void |
debugModeCheckAndExecuteForResult(BufferedImage image,
String fileName,
RecognitionResult result) |
ArrayList<DefectOutput> |
DetectDefects(OcrInput input,
DefectType defectType)
Automatically find problematic areas of an image that can significantly impact the accuracy of OCR.
|
ArrayList<LayoutOutput> |
DetectDocumentLayout(OcrInput input)
Analyzes the image and identifies the different types of content areas within it.
|
ArrayList<LanguageDetectionOutput> |
DetectLanguages(OcrInput input)
Analyzes the text on the image to determine the languages it is written in.
|
ArrayList<RectangleOutput> |
DetectRectangles(OcrInput input,
AreasType areasType,
boolean isDetectAreas)
Deprecated.
Will be removed in the release 25.11.0. Use DetectDocumentLayout instead.
|
boolean |
ImageHasText(String fullPath,
Pattern regex)
Check if the image text matches the provided regular expression.
|
boolean |
ImageHasText(String fullPath,
Pattern regex,
RecognitionSettings settings)
Check if the image text matches the provided regular expression.
|
boolean |
ImageHasText(String fullPath,
String text)
Check if the image contains the provided text fragment with a case-insensitive search.
|
boolean |
ImageHasText(String fullPath,
String text,
RecognitionSettings settings)
Check if the image contains the provided text fragment with a case-insensitive search.
|
boolean |
ImageHasText(String fullPath,
String text,
RecognitionSettings settings,
boolean ignoreCase)
Check if the image contains the provided text fragment.
|
float |
ImageTextDiff(String fullPath1,
String fullPath2)
Compare the texts on the two images and return a number representing how similar they are (0 to 1).
|
float |
ImageTextDiff(String fullPath1,
String fullPath2,
RecognitionSettings settings)
Compare the texts on the two images and return a number representing how similar they are (0 to 1).
|
float |
ImageTextDiff(String fullPath1,
String fullPath2,
RecognitionSettings settings,
boolean ignoreCase)
Compare the texts on the two images and return a number representing how similar they are (0 to 1).
|
OcrOutput |
Recognize(OcrInput input)
Recognizes image with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
OcrOutput |
Recognize(OcrInput input,
RecognitionSettings settings)
Recognizes image with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
OcrOutput |
RecognizeCarPlate(OcrInput input,
CarPlateRecognitionSettings settings)
Recognizes car plate with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
ArrayList<CharacterRecognitionResult> |
RecognizeCharacters(OcrInput input)
Detects symbols on images.
|
ArrayList<CharacterRecognitionResult> |
RecognizeCharacters(OcrInput input,
DetectAreasMode detectAreasMode,
Language language)
Detects symbols on images.
|
ArrayList<String> |
RecognizeFast(OcrInput input)
Recognizes text on good quality image.
|
OcrOutput |
RecognizeHandwrittenText(OcrInput input)
Recognizes handwritten text on images.
|
OcrOutput |
RecognizeIDCard(OcrInput input,
IDCardRecognitionSettings settings)
Recognizes ID card with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
OcrOutput |
RecognizeInvoice(OcrInput input,
InvoiceRecognitionSettings settings)
Recognizes invoice with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
OcrOutput |
RecognizePassport(OcrInput input,
PassportRecognitionSettings settings)
Recognizes passport with the ability to specify.
|
OcrOutput |
RecognizeReceipt(OcrInput input,
ReceiptRecognitionSettings settings)
Recognizes receipts with the ability to specify
Supports GIF, PNG, JPEG, WBMP, TIFF, JFIF, TIFF, PDF, InputStream, BufferedImage, folder, array, zip archive, URL, base64.
|
static void |
SaveMultipageDocument(OutputStream stream,
Format saveFormat,
ArrayList<RecognitionResult> results)
Allows to get multipage document from list of RecognitionResult objects.
|
static void |
SaveMultipageDocument(OutputStream stream,
Format saveFormat,
ArrayList<RecognitionResult> results,
String embeddedFontPath)
Allows to get multipage document from list of RecognitionResult objects.
|
static void |
SaveMultipageDocument(OutputStream stream,
Format saveFormat,
ArrayList<RecognitionResult> results,
String embeddedFontPath,
PdfOptimizationMode optimizePdf)
Allows to get multipage document from list of RecognitionResult objects.
|
static void |
SaveMultipageDocument(String fullFileName,
Format saveFormat,
ArrayList<RecognitionResult> results)
Allows to get multipage document from list of RecognitionResult objects.
|
static void |
SaveMultipageDocument(String fullFileName,
Format saveFormat,
ArrayList<RecognitionResult> results,
SpellCheckLanguage language)
Allows to get multipage document from list of RecognitionResult objects with spell-check correction.
|
static void |
SaveMultipageDocument(String fullFileName,
Format saveFormat,
ArrayList<RecognitionResult> results,
String embeddedFontPath)
Allows to get multipage document from list of RecognitionResult objects.
|
static void |
SaveMultipageDocument(String fullFileName,
Format saveFormat,
ArrayList<RecognitionResult> results,
String embeddedFontPath,
PdfOptimizationMode optimizePdf)
Allows to get multipage document from list of RecognitionResult objects.
|
public static boolean DebugMode
public static String DebugModeSaveDirectory
public boolean ImageHasText(String fullPath, String text, RecognitionSettings settings, boolean ignoreCase)
fullPath - Path to the image.text - Text fragment for searching on the image.settings - Recognition settings.ignoreCase - True - means a case-insensitive search.public boolean ImageHasText(String fullPath, String text, RecognitionSettings settings)
fullPath - Path to the image.text - Text fragment for searching on the image.settings - Recognition settings.public boolean ImageHasText(String fullPath, String text)
fullPath - Path to the image.text - Text fragment for searching on the image.public boolean ImageHasText(String fullPath, Pattern regex, RecognitionSettings settings)
fullPath - Path to the image.regex - java.util.regex.Pattern object with the provided pattern and options.settings - Recognition settings.public boolean ImageHasText(String fullPath, Pattern regex)
fullPath - Path to the image.regex - java.util.regex.Pattern object with the provided pattern and options.public boolean CompareImageTexts(String fullPath1, String fullPath2, RecognitionSettings settings, boolean ignoreCase)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.settings - Recognition settings.ignoreCase - True - means a case-insensitive search.public boolean CompareImageTexts(String fullPath1, String fullPath2, RecognitionSettings settings)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.settings - Recognition settings.public boolean CompareImageTexts(String fullPath1, String fullPath2)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.public float ImageTextDiff(String fullPath1, String fullPath2, RecognitionSettings settings, boolean ignoreCase)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.settings - Recognition settings.ignoreCase - True - means a case-insensitive search.public float ImageTextDiff(String fullPath1, String fullPath2, RecognitionSettings settings)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.settings - Recognition settings.public float ImageTextDiff(String fullPath1, String fullPath2)
fullPath1 - Path to the first image.fullPath2 - Path to the second image.public static void SaveMultipageDocument(String fullFileName, Format saveFormat, ArrayList<RecognitionResult> results)
fullFileName - Filename with a path for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, Xlsx, Xml, Json).results - List of RecognitionResult. objects.public static void SaveMultipageDocument(String fullFileName, Format saveFormat, ArrayList<RecognitionResult> results, String embeddedFontPath)
fullFileName - Filename with a path for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, Xlsx, Xml, Json).results - List of RecognitionResult. objects.embeddedFontPath - Optionally. Full path to the user font.public static void SaveMultipageDocument(String fullFileName, Format saveFormat, ArrayList<RecognitionResult> results, String embeddedFontPath, PdfOptimizationMode optimizePdf)
fullFileName - Filename with a path for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, Xlsx, Xml, Json).results - List of RecognitionResult. objects.embeddedFontPath - Optionally. Full path to the user font.optimizePdf - Reduce the PDF file size by lowering the quality of background images. By default, the original image quality is preserved.public static void SaveMultipageDocument(String fullFileName, Format saveFormat, ArrayList<RecognitionResult> results, SpellCheckLanguage language)
fullFileName - Filename with a path for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, Xlsx, Xml, Json).results - List of RecognitionResult. objects.language - SpellCheckLanguage enum value.public static void SaveMultipageDocument(OutputStream stream, Format saveFormat, ArrayList<RecognitionResult> results)
stream - OutputStream for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, PdfNoImg, Xlsx, Xml, Json, Rtf).results - List of RecognitionResult. objects.public static void SaveMultipageDocument(OutputStream stream, Format saveFormat, ArrayList<RecognitionResult> results, String embeddedFontPath)
stream - OutputStream for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, PdfNoImg, Xlsx, Xml, Json, Rtf).results - List of RecognitionResult. objects.embeddedFontPath - Optionally. Full path to the user font.public static void SaveMultipageDocument(OutputStream stream, Format saveFormat, ArrayList<RecognitionResult> results, String embeddedFontPath, PdfOptimizationMode optimizePdf)
stream - OutputStream for saving recognition result in the selected format.saveFormat - Document format (Docx, Txt, Pdf, PdfNoImg, Xlsx, Xml, Json, Rtf).results - List of RecognitionResult. objects.embeddedFontPath - Optionally. Full path to the user font.optimizePdf - Reduce the PDF file size by lowering the quality of background images. By default, the original image quality is preserved.public String CorrectSpelling(String text, SpellCheckLanguage language)
text - Text for correction.language - Dictionary to use
SpellCheckLanguage.public String CorrectSpelling(String text, SpellCheckLanguage language, String dictionaryPath)
text - Text for correction.language - Dictionary to use
SpellCheckLanguage.dictionaryPath - Full path to the user dictionary (frequency dictionary).
Dictionary file format:
Plain text file in UTF-8 encoding.
Word and Word Frequency are separated by comma, the word is expected in the first column and the frequency in the second column.
Every word-frequency-pair in a separate line.A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"),
or a carriage return immediately followed by a line feed("\r\n").
Every word is expected to be in lower case.public OcrOutput Recognize(OcrInput input, RecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - RecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput Recognize(OcrInput input) throws AsposeOCRException
input - OcrInput. instance.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<String> RecognizeFast(OcrInput input) throws AsposeOCRException
input - OcrInput instance.AsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizeReceipt(OcrInput input, ReceiptRecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - ReceiptRecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizeInvoice(OcrInput input, InvoiceRecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - InvoiceRecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizeIDCard(OcrInput input, IDCardRecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - IDCardRecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizeCarPlate(OcrInput input, CarPlateRecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - CarPlateRecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizePassport(OcrInput input, PassportRecognitionSettings settings) throws AsposeOCRException
input - OcrInput. instance.settings - PassportRecognitionSettings.RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public OcrOutput RecognizeHandwrittenText(OcrInput input) throws AsposeOCRException
input - OcrInput. The container with sources..RecognitionResultAsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<SkewOutput> CalculateSkew(OcrInput input) throws AsposeOCRException
input - The container with sources.OcrInputSkewOutputAsposeOCRException - if file not found.@Deprecated public ArrayList<RectangleOutput> DetectRectangles(OcrInput input, AreasType areasType, boolean isDetectAreas) throws AsposeOCRException
input - The container with sources.OcrInputareasType - Determinates wich rectangles to return - line or paragraphs.isDetectAreas - Enable automatic text areas detection.RectangleOutput with detected text areas or lines.AsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<DefectOutput> DetectDefects(OcrInput input, DefectType defectType) throws AsposeOCRException
input - The container with sources.OcrInputdefectType - The types of defects to be recognized DefectType.DefectOutput with detected text areas or lines.AsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<LanguageDetectionOutput> DetectLanguages(OcrInput input) throws AsposeOCRException
input - The container with sources.OcrInputLanguageDetectionOutputAsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<LayoutOutput> DetectDocumentLayout(OcrInput input) throws AsposeOCRException
input - The container with sources.OcrInputLayoutOutputAsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<CharacterRecognitionResult> RecognizeCharacters(OcrInput input, DetectAreasMode detectAreasMode, Language language) throws AsposeOCRException
input - The container with sources.OcrInputdetectAreasMode - Determines the type of neural network used for areas detection.language - Language used for OCR.Character with detected symbols data.AsposeOCRException - if file not found, resource not found or recognition error.public ArrayList<CharacterRecognitionResult> RecognizeCharacters(OcrInput input) throws AsposeOCRException
input - The container with sources.OcrInputCharacter with detected symbols data for each image.AsposeOCRException - if file not found, resource not found or recognition error.public void close()
throws Exception
close in interface AutoCloseableExceptionpublic static void debugModeCheckAndExecute(BufferedImage image, String fileName, List<Rectangle> rectangles)
public static void debugModeCheckAndExecuteForResult(BufferedImage image, String fileName, RecognitionResult result)
public static void debugModeCheckAndDrawDsr(BufferedImage image, int imgIdx, ArrayList<Map.Entry<RegionTypes,Rectangle>> list)
Copyright © 2025 Aspose. All rights reserved.