Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more image for each charector #72

Open
parsibox opened this issue Jun 30, 2017 · 7 comments
Open

add more image for each charector #72

parsibox opened this issue Jun 30, 2017 · 7 comments
Assignees
Labels

Comments

@parsibox
Copy link

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;
    }

@vivekbdh
Copy link

vivekbdh commented Jul 1, 2017

Where is the change in RecognizedChar as you are passing char to it's constructor

@parsibox
Copy link
Author

parsibox commented Jul 1, 2017

here

            recognized.addPattern(new RecognizedPattern(davari_learnLists_char.get(x), fx));

i send new image file for each charector

@vivekbdh
Copy link

vivekbdh commented Jul 1, 2017

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.

@parsibox
Copy link
Author

parsibox commented Jul 1, 2017

ohum
i am php programmer and I do not know Java professionally
can you correct it?

@oskopek
Copy link
Owner

oskopek commented Jul 2, 2017

@vivekbdh are you working on a pull request, or should I review this and potentially merge it in?

@vivekbdh
Copy link

vivekbdh commented Jul 2, 2017

@oskopek You can review...

@parsibox
Copy link
Author

parsibox commented Jul 3, 2017

is it ok now?
please check this and add this

@oskopek oskopek self-assigned this Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants