oskopek / javaanpr

JavaANPR - Automatic Number Plate Recognition System for Java
Educational Community License v2.0
151 stars 113 forks source link

ArrayIndexOutOfBoundsException #28

Closed MateuszKaczmarczyk closed 7 years ago

MateuszKaczmarczyk commented 8 years ago

When I'm trying to recogonize car plates from jpg, I'm getting ArrayIndexOutOfBoundsException. Below is the code and error.

Code:

Intelligence intel = new Intelligence();
CarSnapshot carSnap = new CarSnapshot("D:/rejestracja.jpg");
String numberPlate = intel.recognize(carSnap, true);
System.out.println(numberPlate);

Error:

java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 at java.util.Vector.elementAt(Unknown Source) at net.sf.javaanpr.intelligence.Intelligence.recognize(Intelligence.java:244) at pl.anpr.test.MainClass.main(MainClass.java:49)

Error is in this line of Intelligence.java: similarityCost = ((RecognizedPattern)rc.getPatterns().elementAt(0)).getCost(); So it's look like rc.getPatterns() returns empty collection.

I tried with different images, and error is occuring every time. I'm using lastest version of JavaANPR and default settings.

oskopek commented 8 years ago

Hey, could you please upload your config.xml and possibly even the image you are testing against? Thanks for reporting the issue!

MateuszKaczmarczyk commented 8 years ago

config.xml and example photos I used are below. The only thing I changed in config.xml is path to syntax file, it's because it couldn't find syntax file with default path, so I moved it and changed path.

config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

Global configuration file for the Automatic Number Plate Recognition System ``` 7 0 3 3 20 5 15 0.5 0.5 15.0 0.1 0.92 0.161 0.1 0.145 0.24 0.2 100.0 8 13 /alphabets/alphabet_8x13 1 0 0 neuralnetworks/network_avgres_813_map.xml 8000 0.07 0.05 0.5 20 2 syntax.xml 9 25 0.1 0.55 0.2 0.55 1 0.05 0.42 0.86 0.7 ```

Photos: rejestracja-po rejestracja

MateuszKaczmarczyk commented 8 years ago

Now I tried with another photo, and there is no exception, but result is: null. Photo that returns null below: rejestracja-astra-ok

oskopek commented 8 years ago

Thanks for the bug report, I'll get to it as soon as possible.

oskopek commented 8 years ago
  1. It's weird that the syntax file wasn't found.. how are you running your code? When I run the latest master version of JavaANPR with the default configuration, the syntax file is found just fine.
  2. I just tested with your images:
  3. with the default syntax file, the last image wasn't recognized (hence the null), the others were, I think correctly, but still, I couldn't reproduce the exception.
  4. When I used this syntax.xml:
<!DOCTYPE structure SYSTEM "src/main/resources/dtd/syntax.dtd">

<structure>
    <type name="poland">
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
    </type>
    <type name="poland2">
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
    </type>
</structure>

Almost all of them were mostly correct. Still no exceptions.

I pushed 2 new commits into master, try to rebuild with the newest version and see if the error still appears.

MateuszKaczmarczyk commented 8 years ago

Still the same error on first two photos, and third returns null. I think some problems may be caused by wrong project import. I created new project with only one class, and added jar (after running mvn clean install) of javaanpr, so i can use net.sf.javaanpr.* packages. First problem i've faced was:

ERROR net.sf.javaanpr.intelligence.Parser - Failed to load from parser syntax description file java.io.FileNotFoundException: C:\prj\anprtest\src\main\resources\dtd\syntax.dtd

And then, after fixing above error:

java.lang.ArrayIndexOutOfBoundsException: 0 >= 00 >= 0 at java.util.Vector.elementAt(Unknown Source) at net.sf.javaanpr.intelligence.Intelligence.recognize(Intelligence.java:244) at main.java.pl.anpr.MainClass.main(MainClass.java:12)

oskopek commented 8 years ago

I fixed the dtd loading issue in 8f121829243eb488421f7b62314a04ade8a8fa25.

I could not reproduce you're other error. It worked for me doing the following steps:

package cz.matfyz.oskopek;

import net.sf.javaanpr.configurator.Configurator;
import net.sf.javaanpr.imageanalysis.CarSnapshot;
import net.sf.javaanpr.intelligence.Intelligence;

public class Main {

    public static void main(String[] args) throws Exception {
        Configurator.getConfigurator().loadConfiguration("cz/matfyz/oskopek/config.xml");
        Intelligence intel = new Intelligence();

        String[] imgs = {"img1.jpg", "img2.jpg", "img3.jpg"};
        for (String img : imgs) {
            CarSnapshot carSnap = new CarSnapshot("/home/oskopek/tmp/" + img);
            String numberPlate = intel.recognize(carSnap, true);
            System.out.println(img + ":\t" + numberPlate);
        }

    }
}
<entry key="intelligence_syntaxDescriptionFile">cz/matfyz/oskopek/syntax.xml</entry>
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE structure SYSTEM "https://raw.githubusercontent.com/oskopek/javaanpr/master/src/main/resources/dtd/syntax.dtd">

<structure>
    <type name="poland">
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
    </type>
    <type name="poland2">
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="0123456789"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
        <char content="abcdefghijklmnopqrstuvwxyz"/>
    </type>
</structure>

Resulting output:

img1.jpg:   null
img2.jpg:   PO082CC
img3.jpg:   NNI12742
MateuszKaczmarczyk commented 8 years ago

I tried to run this project on Linux OS (Ubuntu) and everything seems to be ok, there is no exception. Output is the same:

img1.jpg:   null
img2.jpg:   PO082CC
img3.jpg:   NNI12742

However on Windows 10 still "java.lang.ArrayIndexOutOfBoundsException: 0 >= 0". Maybe it's OS fault, or maybe - different version of Java or Maven?

I'm going to run JavaANPR on Raspberry Pi (Linux, Raspbian), so i think it will be working there. For now, I will work on Linux. Thank you for help, now there are no configuration problems (like missing syntax file), and I can develop my application.

oskopek commented 7 years ago

Couldn't reproduce issue on Windows 7, JDK8. Closing as "wontfix".