- java.lang.Object
-
- com.uddernetworks.newocr.recognition.DefaultScannedImage
-
- All Implemented Interfaces:
ScannedImage
public class DefaultScannedImage extends java.lang.Object implements ScannedImage
An object to store line data forImageLetter
s on a scanned image.- Since:
- April 25, 2019
-
-
Constructor Summary
Constructors Constructor Description DefaultScannedImage(java.io.File originalFile, java.awt.image.BufferedImage binarizedImage, java.awt.image.BufferedImage originalImage)
-
Method Summary
Modifier and Type Method Description void
addLine(int y, java.util.List<ImageLetter> databaseCharacterList)
Adds a line containingImageLetter
s.java.awt.image.BufferedImage
getBinarizedImage()
Gets the binarized image before any preprocessingit.unimi.dsi.fastutil.ints.Int2ObjectMap<java.util.List<ImageLetter>>
getGrid()
Returns the raw, mutable grid ofImageLetter
s internally used with the key of the mpa being the exact Y position of the line.java.util.Optional<java.util.List<ImageLetter>>
getGridLineAtIndex(int index)
Gets the line at the stored index.java.util.List<ImageLetter>
getLine(int y)
Gets the line at the given index value.int
getLineCount()
gets the amount of lines in the image.it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry<java.util.List<ImageLetter>>
getLineEntry(int y)
Gets both the line Y and values at the given index value.java.io.File
getOriginalFile()
Gets the originalFile
scanned by the OCR.java.awt.image.BufferedImage
getOriginalImage()
Gets the original image scanned by the OCR.java.lang.String
getPrettyString()
Gets the string of a scanned imagejava.util.Optional<ImageLetter>
letterAt(int index)
Gets the letter at the given index of the actualScannedImage.getPrettyString()
position, meaning newlines are not returned.ScannedImage
stripLeadingSpaces()
Removes all common leading spaces, just like howOCRUtils.removeLeadingSpaces(String)
removes empty spaces, but with actualImageLetter
objects.
-
-
-
Method Detail
-
getPrettyString
public java.lang.String getPrettyString()
Description copied from interface:ScannedImage
Gets the string of a scanned image- Specified by:
getPrettyString
in interfaceScannedImage
- Returns:
- The string of a scanned image
-
stripLeadingSpaces
public ScannedImage stripLeadingSpaces()
Description copied from interface:ScannedImage
Removes all common leading spaces, just like howOCRUtils.removeLeadingSpaces(String)
removes empty spaces, but with actualImageLetter
objects.- Specified by:
stripLeadingSpaces
in interfaceScannedImage
- Returns:
- The current
ScannedImage
-
letterAt
public java.util.Optional<ImageLetter> letterAt(int index)
Description copied from interface:ScannedImage
Gets the letter at the given index of the actualScannedImage.getPrettyString()
position, meaning newlines are not returned.- Specified by:
letterAt
in interfaceScannedImage
- Parameters:
index
- The character index- Returns:
- The ImageLetter at the given position, if found
-
getGridLineAtIndex
public java.util.Optional<java.util.List<ImageLetter>> getGridLineAtIndex(int index) throws java.lang.IndexOutOfBoundsException
Description copied from interface:ScannedImage
Gets the line at the stored index. This is NOT by the y value.- Specified by:
getGridLineAtIndex
in interfaceScannedImage
- Parameters:
index
- The index of the row- Returns:
- The row
- Throws:
java.lang.IndexOutOfBoundsException
-
getLineCount
public int getLineCount()
Description copied from interface:ScannedImage
gets the amount of lines in the image.- Specified by:
getLineCount
in interfaceScannedImage
- Returns:
- The amount of lines in the image
-
getGrid
public it.unimi.dsi.fastutil.ints.Int2ObjectMap<java.util.List<ImageLetter>> getGrid()
Description copied from interface:ScannedImage
Returns the raw, mutable grid ofImageLetter
s internally used with the key of the mpa being the exact Y position of the line.- Specified by:
getGrid
in interfaceScannedImage
- Returns:
- The raw, mutable grid of values
-
addLine
public void addLine(int y, java.util.List<ImageLetter> databaseCharacterList)
Description copied from interface:ScannedImage
Adds a line containingImageLetter
s.- Specified by:
addLine
in interfaceScannedImage
- Parameters:
y
- The exact Y position of the linedatabaseCharacterList
- A list ofImageLetter
s as the line
-
getLine
public java.util.List<ImageLetter> getLine(int y)
Description copied from interface:ScannedImage
Gets the line at the given index value.- Specified by:
getLine
in interfaceScannedImage
- Parameters:
y
- The index of the line- Returns:
- The line at the given index value
-
getLineEntry
public it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry<java.util.List<ImageLetter>> getLineEntry(int y)
Description copied from interface:ScannedImage
Gets both the line Y and values at the given index value.- Specified by:
getLineEntry
in interfaceScannedImage
- Parameters:
y
- The index of the line- Returns:
- The line at the given Y index value
-
getBinarizedImage
public java.awt.image.BufferedImage getBinarizedImage()
Description copied from interface:ScannedImage
Gets the binarized image before any preprocessing- Specified by:
getBinarizedImage
in interfaceScannedImage
- Returns:
- The binarized image, which may be null if pulled from caches
-
getOriginalImage
public java.awt.image.BufferedImage getOriginalImage()
Description copied from interface:ScannedImage
Gets the original image scanned by the OCR.- Specified by:
getOriginalImage
in interfaceScannedImage
- Returns:
- The original image, which may be null if pulled from caches
-
getOriginalFile
public java.io.File getOriginalFile()
Description copied from interface:ScannedImage
Gets the originalFile
scanned by the OCR.- Specified by:
getOriginalFile
in interfaceScannedImage
- Returns:
- The original File, which may be null if pulled from caches
-
-