javaanpr
javaanpr copied to clipboard
add more image for each charector
hi i change your code to add more than one image for each charector please change it in your project change in class KnnPatternClassifier
public KnnPatternClassifier() {
String path = Configurator.getConfigurator().getPathProperty("char_learnAlphabetPath");
learnLists = new ArrayList<>(36);
davari_learnLists_char = new ArrayList<Character>(1000);
final String alphaString = "0123456789abcdefghijklmnopqrstuvwxyz";
String directory = "alphabet_10x15";
File files[] = new File(directory).listFiles();
System.out.println("directory : " + directory);
List<String> filenames = new ArrayList<>();
for (int i = 0; i < alphaString.length(); i++) {
for (File f : files) {
if ( f.getName().startsWith(alphaString.charAt(i)+"_") ){
// System.out.println("shoro ba "+alphaString.charAt(i)+" ==> " + f.getName());
String s = directory + File.separator +f.getName();
if (Configurator.getConfigurator().getResourceAsStream(s) != null) {
Char imgChar;
try (InputStream is = Configurator.getConfigurator().getResourceAsStream(s)) {
imgChar = new Char(is);
} catch (IOException e) {
throw new IllegalStateException("Failed to load Char: " + s, e);
}
imgChar.normalize();
learnLists.add(imgChar.extractFeatures());
davari_learnLists_char.add(alphaString.charAt(i));
}
}
}
}
/*
List<String> filenames = Char.getAlphabetList(path);
for (String fileName : filenames) {
Char imgChar;
try (InputStream is = Configurator.getConfigurator().getResourceAsStream(fileName)) {
imgChar = new Char(is);
} catch (IOException e) {
throw new IllegalStateException("Failed to load Char: " + fileName, e);
}
imgChar.normalize();
learnLists.add(imgChar.extractFeatures());
}
*/
// check vector elements
for (List<Double> learnList : learnLists) {
if (learnList == null) {
logger.warn("Alphabet in {} is not complete", path);
}
}
}
@Override
public RecognizedChar recognize(Char chr) {
//recognized.setImage(chr.getImage());
List<Double> tested = chr.extractFeatures();
RecognizedChar recognized = new RecognizedChar(chr);
for (int x = 0; x < learnLists.size(); x++) {
float fx = simplifiedEuclideanDistance(tested, learnLists.get(x));
recognized.addPattern(new RecognizedPattern(davari_learnLists_char.get(x), fx));
}
recognized.sort(false);
return recognized;
}
Where is the change in RecognizedChar as you are passing char to it's constructor
here
recognized.addPattern(new RecognizedPattern(davari_learnLists_char.get(x), fx));
i send new image file for each charector
I think you didn't get my point..
My concern is you are calling RecognizedChar recognized = new RecognizedChar(chr);
when actually there is no any constructor in RecognizedChar class that accept char.
ohum i am php programmer and I do not know Java professionally can you correct it?
@vivekbdh are you working on a pull request, or should I review this and potentially merge it in?
@oskopek You can review...
is it ok now? please check this and add this