Class OCR


  • public class OCR
    extends java.lang.Object
    Static helper class for OCR via Tess4J/Tesseract.

    The methods in this class are not threadsafe.

    See Also:
    SikuliX docs: Text and OCR
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  OCR.OEM
      OCR Engine modes.
      static class  OCR.Options
      A container for the options relevant for using OCR on Region or Image.
      static class  OCR.PSM
      Page segmentation modes.
    • Constructor Summary

      Constructors 
      Constructor Description
      OCR()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static OCR.Options globalOptions()
      access/get the current global Options as singleton.
      static <SFIRBS> java.lang.String readChar​(SFIRBS from)
      Reads text from the given source (character).
      static <SFIRBS> java.lang.String readChar​(SFIRBS from, OCR.Options options)
      Reads text from the given source (character).
      static <SFIRBS> java.lang.String readLine​(SFIRBS from)
      Reads text from the given source (line).
      static <SFIRBS> java.lang.String readLine​(SFIRBS from, OCR.Options options)
      Reads text from the given source (line).
      static <SFIRBS> java.util.List<Match> readLines​(SFIRBS from)
      Treats text from the given source as lines.
      static <SFIRBS> java.util.List<Match> readLines​(SFIRBS from, OCR.Options options)
      Treats text from the given source as lines.
      static <SFIRBS> java.lang.String readText​(SFIRBS from)
      Reads text from the given source.
      static <SFIRBS> java.lang.String readText​(SFIRBS from, OCR.Options options)
      Reads text from the given source.
      static <SFIRBS> java.lang.String readWord​(SFIRBS from)
      Reads text from the given source (word).
      static <SFIRBS> java.lang.String readWord​(SFIRBS from, OCR.Options options)
      Reads text from the given source (word).
      static <SFIRBS> java.util.List<Match> readWords​(SFIRBS from)
      Treats text from the given source as words.
      static <SFIRBS> java.util.List<Match> readWords​(SFIRBS from, OCR.Options options)
      Treats text from the given source as words.
      static OCR.Options reset()
      Resets the global options to the initial defaults.
      static void status()
      prints out the current global options.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OCR

        public OCR()
    • Method Detail

      • globalOptions

        public static OCR.Options globalOptions()
        access/get the current global Options as singleton.
        Returns:
        the global Options
      • reset

        public static OCR.Options reset()
        Resets the global options to the initial defaults.
         oem = OcrEngineMode.DEFAULT.ordinal();
         psm = PageSegMode.AUTO.ordinal();
         language = Settings.OcrLanguage;
         dataPath = null; //(see comment)
         textHeight = getDefaultTextHeight();
         variables.clear();
         configs.clear();
         
        comment on dataPath==null: dataPath will be evaluated at the next use of an OCR feature to the SikuliX default or Settings.OcrDataPath (if set)
        Returns:
        the global Options
      • status

        public static void status()
        prints out the current global options.
      • readText

        public static <SFIRBS> java.lang.String readText​(SFIRBS from)
        Reads text from the given source.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        text
      • readText

        public static <SFIRBS> java.lang.String readText​(SFIRBS from,
                                                         OCR.Options options)
        Reads text from the given source.

        Uses the given options

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - Options to be used
        Returns:
        text
      • readLine

        public static <SFIRBS> java.lang.String readLine​(SFIRBS from)
        Reads text from the given source (line).

        assuming the source contains a single line of text.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        text
      • readLine

        public static <SFIRBS> java.lang.String readLine​(SFIRBS from,
                                                         OCR.Options options)
        Reads text from the given source (line).

        assuming the source contains a single line of text.

        Uses the given options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - options for the used TextRecognizer
        Returns:
        text
      • readLines

        public static <SFIRBS> java.util.List<Match> readLines​(SFIRBS from)
        Treats text from the given source as lines.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        lines as a list of matches
      • readLines

        public static <SFIRBS> java.util.List<Match> readLines​(SFIRBS from,
                                                               OCR.Options options)
        Treats text from the given source as lines.

        Uses the given options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - options for the used TextRecognizer
        Returns:
        lines as a list of matches
      • readWord

        public static <SFIRBS> java.lang.String readWord​(SFIRBS from)
        Reads text from the given source (word).

        assuming the source contains a single word of text.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        text
      • readWord

        public static <SFIRBS> java.lang.String readWord​(SFIRBS from,
                                                         OCR.Options options)
        Reads text from the given source (word).

        assuming the source contains a single word of text.

        Uses the given options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - options for the used TextRecognizer
        Returns:
        text
      • readWords

        public static <SFIRBS> java.util.List<Match> readWords​(SFIRBS from)
        Treats text from the given source as words.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        words as alist of matches
      • readWords

        public static <SFIRBS> java.util.List<Match> readWords​(SFIRBS from,
                                                               OCR.Options options)
        Treats text from the given source as words.

        Uses the given options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - options for the used TextRecognizer
        Returns:
        words as a list of matches
      • readChar

        public static <SFIRBS> java.lang.String readChar​(SFIRBS from)
        Reads text from the given source (character).

        assuming the source contains a single character.

        Uses the global options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        Returns:
        text
      • readChar

        public static <SFIRBS> java.lang.String readChar​(SFIRBS from,
                                                         OCR.Options options)
        Reads text from the given source (character).

        assuming the source contains a single character.

        Uses the given options.

        Type Parameters:
        SFIRBS - File name, File, Image, Region, BufferdImage or ScreenImage
        Parameters:
        from - source to read text from
        options - options for the used TextRecognizer
        Returns:
        text