Package net.kanjitomo

Class KanjiTomo


  • public class KanjiTomo
    extends java.lang.Object
    Main class of the KanjiTomo OCR library
    • Constructor Summary

      Constructors 
      Constructor Description
      KanjiTomo()  
    • Method Summary

      Modifier and Type Method Description
      void close()
      Stops all threads.
      java.util.List<Column> getColumns()
      Gets columns detected from target image
      void loadData()
      Loads data structures into memory.
      OCRResults runOCR​(java.awt.Point point)
      Runs OCR starting from a point.
      OCRResults runOCR​(java.util.List<java.awt.Rectangle> areas)
      Runs OCR inside pre-defined areas where each rectangle contains single characters.
      java.util.List<Word> searchDictionary​(java.lang.String searchString, boolean startsWith)
      Searches words from selected dictionary.
      void setCharacterColor​(CharacterColor color)
      Sets character and background color.
      void setDictionary​(DictionaryType primaryDictionary, DictionaryType secondaryDictionary)
      Sets which dictionary is used.
      void setOrientation​(Orientation orientation)
      Sets the reading direction.
      void setPrintOutput​(boolean printOutput)
      If true, OCR results are printed to stdout.
      void setTargetImage​(java.awt.image.BufferedImage image)
      Sets the target image.
      • Methods inherited from class java.lang.Object

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

      • KanjiTomo

        public KanjiTomo()
    • Method Detail

      • loadData

        public void loadData()
                      throws java.lang.Exception
        Loads data structures into memory. This should be called first on it's own thread as the program starts because loading data can take couple of seconds. It's allowed to call this multiple times, results are cached and further calls don't take any more time unless dictionary is changed.
        Throws:
        java.lang.Exception
      • setTargetImage

        public void setTargetImage​(java.awt.image.BufferedImage image)
                            throws java.lang.Exception
        Sets the target image. This can be a screenshot around target characters or a whole page.
        Throws:
        java.lang.Exception
      • getColumns

        public java.util.List<Column> getColumns()
        Gets columns detected from target image
      • runOCR

        public OCRResults runOCR​(java.awt.Point point)
                          throws java.lang.Exception
        Runs OCR starting from a point.
        Parameters:
        point - Coordinates inside target image. Closest character near this point will be selected as the first target character. Point should correspond to mouse cursor position relative to target image.
        Returns:
        null if no characters found near point
        Throws:
        java.lang.Exception
      • runOCR

        public OCRResults runOCR​(java.util.List<java.awt.Rectangle> areas)
                          throws java.lang.Exception
        Runs OCR inside pre-defined areas where each rectangle contains single characters. This can be used if area detection is done externally and KanjiTomo is only used for final OCR.
        Throws:
        java.lang.Exception
      • searchDictionary

        public java.util.List<Word> searchDictionary​(java.lang.String searchString,
                                                     boolean startsWith)
                                              throws java.lang.Exception
        Searches words from selected dictionary.
        Parameters:
        searchString - Search term supplied by the user or read from OCR results
        startsWith - If true, only words starting with the searchString are considered. If false, searchString can appear anywhere in the word (kanji or kana fields, search from description field is not supported)
        Returns:
        List of maching words sorted by increasing length of kanji/kana field
        Throws:
        java.lang.Exception
      • setDictionary

        public void setDictionary​(DictionaryType primaryDictionary,
                                  DictionaryType secondaryDictionary)
        Sets which dictionary is used. It's recommended to call loadData() after changing the dictionary in background thread before user interaction. It's possible to turn off dictionary search by setting primaryDictionary to null but this is not recommended since search is used to refine OCR results.
        Parameters:
        primaryDictionary - First dictionary used for searching
        secondaryDictionary - If a match is not found from primary dictionary, secondary is used for searching
      • setOrientation

        public void setOrientation​(Orientation orientation)
        Sets the reading direction. Default is automatic. Target image needs to be re-analyzed after changing the orientation by calling setTargetImage again.
      • setCharacterColor

        public void setCharacterColor​(CharacterColor color)
        Sets character and background color. Black and white characters work best, but coloured characters might also work if there's enough contrast. Target image needs to be re-analyzed after changing the color by calling setTargetImage again. Default: CharacterColor.AUTOMATIC
      • setPrintOutput

        public void setPrintOutput​(boolean printOutput)
        If true, OCR results are printed to stdout. If false, nothing is printed. Default: false
      • close

        public void close()
        Stops all threads. This should be called before closing the program.