net.sourceforge.javaocr.ocrPlugins.mseOCR
Class OCRScanner

java.lang.Object
  extended by net.sourceforge.javaocr.scanner.DocumentScannerListenerAdaptor
      extended by net.sourceforge.javaocr.ocrPlugins.mseOCR.OCRScanner
All Implemented Interfaces:
AccuracyProviderInterface, DocumentScannerListener

public class OCRScanner
extends DocumentScannerListenerAdaptor
implements AccuracyProviderInterface

OCR document scanner.

Author:
Ronald B. Cemer

Field Summary
private  CharacterRange[] acceptableChars
           
private  AccuracyListenerInterface accListener
           
private  boolean beginningOfRow
           
private static int BEST_MATCH_STORE_COUNT
           
private  Character[] bestChars
           
private  double[] bestMSEs
           
private  StringBuffer decodeBuffer
           
private  DocumentScanner documentScanner
           
private  boolean firstRow
           
private static Logger LOG
           
private  String newline
           
private  HashMap<Character,ArrayList<TrainingImage>> trainingImages
           
 
Constructor Summary
OCRScanner()
           
 
Method Summary
 void acceptAccuracyListener(AccuracyListenerInterface listener)
           
 void addTrainingImages(HashMap<Character,ArrayList<TrainingImage>> images)
          Add training images to the training set.
 void beginRow(PixelImage pixelImage, int y1, int y2)
           
 void clearTrainingImages()
          Remove all training images from the training set.
 void endRow(PixelImage pixelImage, int y1, int y2)
           
 DocumentScanner getDocumentScanner()
           
private  boolean isTrainingImageACandidate(float aspectRatio, int w, int h, float topWhiteSpaceFraction, float bottomWhiteSpaceFraction, TrainingImage ti)
           
 void processChar(PixelImage pixelImage, int x1, int y1, int x2, int y2, int rowY1, int rowY2)
           
 void processSpace(PixelImage pixelImage, int x1, int y1, int x2, int y2)
           
 String scan(Image image, int x1, int y1, int x2, int y2, CharacterRange[] acceptableChars)
          Scan an image and return the decoded text.
 
Methods inherited from class net.sourceforge.javaocr.scanner.DocumentScannerListenerAdaptor
beginDocument, endDocument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEST_MATCH_STORE_COUNT

private static final int BEST_MATCH_STORE_COUNT
See Also:
Constant Field Values

decodeBuffer

private StringBuffer decodeBuffer

acceptableChars

private CharacterRange[] acceptableChars

beginningOfRow

private boolean beginningOfRow

firstRow

private boolean firstRow

newline

private String newline

trainingImages

private HashMap<Character,ArrayList<TrainingImage>> trainingImages

bestChars

private Character[] bestChars

bestMSEs

private double[] bestMSEs

documentScanner

private DocumentScanner documentScanner

accListener

private AccuracyListenerInterface accListener

LOG

private static final Logger LOG
Constructor Detail

OCRScanner

public OCRScanner()
Method Detail

acceptAccuracyListener

public void acceptAccuracyListener(AccuracyListenerInterface listener)
Specified by:
acceptAccuracyListener in interface AccuracyProviderInterface

getDocumentScanner

public DocumentScanner getDocumentScanner()
Returns:
The DocumentScanner instance that is used to scan the document(s). This is useful if the caller wants to adjust some of the scanner's parameters.

clearTrainingImages

public void clearTrainingImages()
Remove all training images from the training set.


addTrainingImages

public void addTrainingImages(HashMap<Character,ArrayList<TrainingImage>> images)
Add training images to the training set.

Parameters:
images - A HashMap using Characters for the keys. Each value is an ArrayList of TrainingImages for the specified character. The training images are added to any that may already have been loaded.

scan

public String scan(Image image,
                   int x1,
                   int y1,
                   int x2,
                   int y2,
                   CharacterRange[] acceptableChars)
Scan an image and return the decoded text.

Parameters:
image - The Image to be scanned.
x1 - The leftmost pixel position of the area to be scanned, or 0 to start scanning at the left boundary of the image.
y1 - The topmost pixel position of the area to be scanned, or 0 to start scanning at the top boundary of the image.
x2 - The rightmost pixel position of the area to be scanned, or 0 to stop scanning at the right boundary of the image.
y2 - The bottommost pixel position of the area to be scanned, or 0 to stop scanning at the bottom boundary of the image.
acceptableChars - An array of CharacterRange objects representing the ranges of characters which are allowed to be decoded, or null to not limit which characters can be decoded.
Returns:
The decoded text.

endRow

public void endRow(PixelImage pixelImage,
                   int y1,
                   int y2)
Specified by:
endRow in interface DocumentScannerListener
Overrides:
endRow in class DocumentScannerListenerAdaptor

beginRow

public void beginRow(PixelImage pixelImage,
                     int y1,
                     int y2)
Specified by:
beginRow in interface DocumentScannerListener
Overrides:
beginRow in class DocumentScannerListenerAdaptor

processChar

public void processChar(PixelImage pixelImage,
                        int x1,
                        int y1,
                        int x2,
                        int y2,
                        int rowY1,
                        int rowY2)
Specified by:
processChar in interface DocumentScannerListener
Overrides:
processChar in class DocumentScannerListenerAdaptor

isTrainingImageACandidate

private boolean isTrainingImageACandidate(float aspectRatio,
                                          int w,
                                          int h,
                                          float topWhiteSpaceFraction,
                                          float bottomWhiteSpaceFraction,
                                          TrainingImage ti)

processSpace

public void processSpace(PixelImage pixelImage,
                         int x1,
                         int y1,
                         int x2,
                         int y2)
Specified by:
processSpace in interface DocumentScannerListener
Overrides:
processSpace in class DocumentScannerListenerAdaptor


Copyright © -2012. All Rights Reserved.