public class KNNCharacterClassifier extends Object
FontSimulator
.
In this base implementation, the pixels of the character images are used as the vector for classification which will achieve somewhere in the region of 60% correct classification for the characters 0-9 and somewhat worse for larger character ranges.
Override the getImageVector(FImage)
method to try different
features. This class provides the training, classification and testing.
Modifier and Type | Class and Description |
---|---|
protected class |
KNNCharacterClassifier.ImageTrainer
This class is the
FontSimulator.FontSimListener implementation that receives
each character as an image in some randomised font. |
Constructor and Description |
---|
KNNCharacterClassifier()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
char |
classify(FImage img)
Classify the given image with the nearest neighbour classifier.
|
double[] |
getImageVector(FImage img)
Get the feature vector for a single image.
|
static void |
main(String[] args)
The main does a training run then a test run.
|
void |
test(int nTestRuns)
Run a bunch of tests to determine how good the classifier is.
|
void |
train()
Train the classifier by generating a bunch of random training examples
of characters in various fonts (using the
FontSimulator )
and using the features extracted from those images, train a nearest
neighbour classifier. |
public KNNCharacterClassifier()
public double[] getImageVector(FImage img)
img
- The character image.public void train()
FontSimulator
)
and using the features extracted from those images, train a nearest
neighbour classifier.public char classify(FImage img)
img
- the character image to classifypublic void test(int nTestRuns)
FontSimulator
and classifies them.nTestRuns
- The number of tests to run