com.aspose.ocr

Class AsposeOCR



  • public class AsposeOCR
    extends Object
    Main class for recognize text from images.
    Version:
    21.11
    Author:
    Aspose
    • Constructor Detail

      • AsposeOCR

        public AsposeOCR(String alphabet)
        Public constructor.
        Parameters:
        alphabet - Narrow alphabet for recognition.
        See Also:
        AsposeOCR()
    • Method Detail

      • CalcSkewImage

        public double CalcSkewImage(String fullPath)
                             throws IOException
        Calculates the skew angle of an image.
        Parameters:
        fullPath - Path to image.
        Returns:
        Skew angle in degrees.
        Throws:
        IOException - if file not found.
      • CalcSkewImage

        public double CalcSkewImage(BufferedImage image)
                             throws IOException
        Calculates the skew angle of an image. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        image - BufferedImage instance.
        Returns:
        Skew angle in degrees.
        Throws:
        IOException - if file not found.
      • CalcSkewImageFromUri

        public double CalcSkewImageFromUri(String uri)
                                    throws IOException
        Calculates the skew angle of an image provided by URI link.
        Parameters:
        uri - URI link to the image.
        Returns:
        Skew angle in degrees.
        Throws:
        IOException - if file not found.
      • PreprocessImage

        public BufferedImage PreprocessImage(String fullPath,
                                             PreprocessingFilter filters)
        Use image preprocessing to improve the accuracy of OCR. Create a list of filters that will be applied to the input image in the order you specify. example to create filters: PreprocessingFilter filters = new PreprocessingFilter(); filters.add(PreprocessingFilter.ToGrayscale()); filters.add(PreprocessingFilter.Invert()); filters.add(PreprocessingFilter.Threshold(20));
        Parameters:
        fullPath - Full path to the image.
        filters - Image optimization filters @see PreprocessingFilter
        Returns:
        BufferedImage with modified image so you can save or recognize it.
      • PreprocessImage

        public BufferedImage PreprocessImage(BufferedImage image,
                                             PreprocessingFilter filters)
        Use image preprocessing to improve the accuracy of OCR. Create a list of filters that will be applied to the input image in the order you specify. example to create filters: PreprocessingFilter filters = new PreprocessingFilter(); filters.add(PreprocessingFilter.ToGrayscale()); filters.add(PreprocessingFilter.Invert()); filters.add(PreprocessingFilter.Threshold(20));
        Parameters:
        image - Source BufferedImage.
        filters - Image optimization filters @see PreprocessingFilter
        Returns:
        BufferedImage with modified image so you can save or recognize it.
      • RecognizePage

        public String RecognizePage(String fullPath)
                             throws IOException
        Recognizes text on image. Uses automatic image skew correction and text areas detection. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        fullPath - Path to image.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizePage

        public String RecognizePage(String fullPath,
                                    boolean autoSkew)
                             throws IOException
        Recognizing image with automatic detection of text areas and ability to disable image skew correction. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        fullPath - Path to the image.
        autoSkew - Enable automatic image skew correction.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizePage

        public String RecognizePage(String fullPath,
                                    ArrayList<Rectangle> boxes_)
                             throws IOException
        Recognizes text on image. Recognizes image with ability to specify text areas. Support for GIF, PNG, JPEG, BMP and WBMP. Automatic image skew correction is not applied.
        Parameters:
        fullPath - Path to image.
        boxes_ - List of areas to recognize.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizeLine

        public String RecognizeLine(String fullPath)
                             throws IOException
        Recognizes image that contains single line of text. Automatic image skew correction is not applied. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        fullPath - Path to the image.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizePage

        public String RecognizePage(BufferedImage image)
                             throws IOException
        Recognizes text on image. Uses automatic image skew correction and text areas detection. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        image - Source BufferedImage.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizePage

        public String RecognizePage(BufferedImage image,
                                    boolean autoSkew)
                             throws IOException
        Recognizing image with automatic detection of text areas and ability to disable image skew correction. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        image - BufferedImage instance.
        autoSkew - Enable automatic image skew correction.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizePage

        public String RecognizePage(BufferedImage image_,
                                    ArrayList<Rectangle> boxes_)
                             throws IOException
        Recognizes text on image. Recognizes image with ability to specify text areas. Support for GIF, PNG, JPEG, BMP and WBMP. Automatic image skew correction is not applied.
        Parameters:
        image_ - BufferedImage instance.
        boxes_ - List of areas to recognize.
        Returns:
        Recognized text.
        Throws:
        IOException - if file not found.
      • RecognizeLine

        public String RecognizeLine(BufferedImage image_)
        Recognizes image that contains single line of text. Automatic image skew correction is not applied. Support for GIF, PNG, JPEG, BMP and WBMP.
        Parameters:
        image_ - BufferedImage instance.
        Returns:
        Recognized text.
      • RecognizePageFromUri

        public String RecognizePageFromUri(String uri)
                                    throws IOException
        Recognizes text on image provided by URI link. Uses automatic image skew correction and text areas detection. Supports GIF, PNG, JPEG, BMP, TIFF.
        Parameters:
        uri - URI link to the image.
        Returns:
        Recognized text.
        Throws:
        IOException - uri is incorrect
      • getTextAreas

        public ArrayList<Rectangle> getTextAreas(String fullPath,
                                                 AreasType areasType,
                                                 boolean isDetectAreas)
                                          throws IOException
        Detects text areas on image. Automatic image skew correction is not applied.
        Parameters:
        fullPath - Path to the image.
        areasType - Determinate which rectangles to return - line or paragraphs.
        isDetectAreas - Enable automatic text areas detection.
        Returns:
        ArrayList of detected text areas.
        Throws:
        IOException - if file not found
      • getTextAreas

        public ArrayList<Rectangle> getTextAreas(BufferedImage image_,
                                                 AreasType areasType,
                                                 boolean isDetectAreas)
                                          throws IOException
        Detects text areas on image. Automatic image skew correction is not applied.
        Parameters:
        image_ - BufferedImage instance.
        areasType - Determinate which rectangles to return - line or paragraphs.
        isDetectAreas - Enable automatic text areas detection.
        Returns:
        ArrayList of detected text areas.
        Throws:
        IOException - if file not found
      • SaveMultipageDocument

        public static void SaveMultipageDocument(String fullFileName,
                                                 Format saveFormat,
                                                 ArrayList<RecognitionResult> results)
        Allows to get multipage document from list of RecognitionResult objects.
        Parameters:
        fullFileName - Filename with a path for saving recognition result in the selected format.
        saveFormat - Document format (Docx, Txt, Pdf).
        results - List of RecognitionResult. objects.
      • CorrectSpelling

        public String CorrectSpelling(String text,
                                      SpellCheckLanguage language)
        Corrects text (replaces misspelled words).
        Parameters:
        text - Text for correction.
        language - Dictionary to use SpellCheckLanguage.
        Returns:
        Text with replaced words.
      • CorrectSpelling

        public String CorrectSpelling(String text,
                                      SpellCheckLanguage language,
                                      String dictionaryPath)
        Corrects text (replaces misspelled words).
        Parameters:
        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.
        Returns:
        Text with replaced words.