Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/upgradeRecipes/upgradeRecipe-2.0.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ JavaANPR Contributors <javaanpr@googlegroups.com>
== Major API changes

== Minor API changes
=== `Parser.parse` method parameters

The method `String Parser.parse(RecognizedPlate, int)` changed to `String Parser.parse(RecognizedPlate, SyntaxAnalysisMode)`.

Workaround: `parse(plate, syntaxAnalysisModeInt)` -> `parse(plate, SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(syntaxAnalysisModeInt))`
10 changes: 3 additions & 7 deletions src/main/java/net/sf/javaanpr/intelligence/Intelligence.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@

import net.sf.javaanpr.configurator.Configurator;
import net.sf.javaanpr.gui.TimeMeter;
import net.sf.javaanpr.imageanalysis.Band;
import net.sf.javaanpr.imageanalysis.CarSnapshot;
import net.sf.javaanpr.imageanalysis.Char;
import net.sf.javaanpr.imageanalysis.HoughTransformation;
import net.sf.javaanpr.imageanalysis.Photo;
import net.sf.javaanpr.imageanalysis.Plate;
import net.sf.javaanpr.imageanalysis.*;
import net.sf.javaanpr.jar.Main;
import net.sf.javaanpr.recognizer.CharacterRecognizer;
import net.sf.javaanpr.recognizer.RecognizedChar;
Expand Down Expand Up @@ -66,7 +61,8 @@ public long getLastProcessDuration() {
public String recognize(CarSnapshot carSnapshot, final boolean enableReportGeneration)
throws IllegalArgumentException, IOException {
TimeMeter time = new TimeMeter();
int syntaxAnalysisMode = configurator.getIntProperty("intelligence_syntaxanalysis");
int syntaxAnalysisModeInt = configurator.getIntProperty("intelligence_syntaxanalysis");
SyntaxAnalysisMode syntaxAnalysisMode = SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(syntaxAnalysisModeInt);
int skewDetectionMode = configurator.getIntProperty("intelligence_skewdetection");
if (enableReportGeneration) {
Main.rg.insertText("<h1>Automatic Number Plate Recognition Report</h1>");
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/net/sf/javaanpr/intelligence/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,31 @@ public void invertFlags() {
/**
* Syntactically parses text from the given {@link RecognizedPlate} in the specified analysis mode.
* <p>
* Syntax analysis mode: <ul>
* <li>0 (do not parse)</li>
* <li>1 (only equal length)</li>
* <li>2 (equal or shorter)</li>
* </ul>
*
* @param recognizedPlate the plate to parse
* @param syntaxAnalysisMode the mode in which to parse
* @return the parsed recognized plate text
*/
public String parse(RecognizedPlate recognizedPlate, int syntaxAnalysisMode) { // TODO enum
if (syntaxAnalysisMode == 0) {
Main.rg.insertText(
" result : " + recognizedPlate.getString() + " --> <font size=15>" + recognizedPlate.getString()
+ "</font><hr><br>");
return recognizedPlate.getString();
}

public String parse(RecognizedPlate recognizedPlate, SyntaxAnalysisMode syntaxAnalysisMode) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes one of the methods in the "public API" (there is no such thing currently, but I suspect people use the method in their code). We should be able to do this change for the next major release, but we should document it somehow. I added the following file: docs/upgradeRecipes/upgradeRecipe-2.0.0.adoc. It will be of great help to all users if they wish to upgrade in the future.

Just add something along the lines of

=== `Parser.parse` method parameters

The method `String Parser.parse(RecognizedPlate, int)` changed to
`String Parser.parse(RecognizedPlate, SyntaxAnalysisMode)`.

Workaround: `parse(plate, syntaxAnalysisModeInt)`
-> `parse(plate, SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(syntaxAnalysisModeInt))`

To the "Minor API changes" part of that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

int length = recognizedPlate.getChars().size();
this.unFlagAll();
if (syntaxAnalysisMode == 1) {
this.flagEqualLength(length);
} else {
this.flagEqualOrShorterLength(length);

switch (syntaxAnalysisMode) {
case DO_NOT_PARSE:
Main.rg.insertText(
" result : " + recognizedPlate.getString() + " --> <font size=15>" + recognizedPlate.getString()
+ "</font><hr><br>");
return recognizedPlate.getString();
case ONLY_EQUAL_LENGTH:
this.unFlagAll();
this.flagEqualLength(length);
break;
case EQUAL_OR_SHORTER_LENGTH:
this.unFlagAll();
this.flagEqualOrShorterLength(length);
break;
default:
throw new IllegalArgumentException("Expected SyntaxAnalysisMode.DO_NOT_PARSE, "
+ "SyntaxAnalysisMode.ONLY_EQUAL_LENGTH or SyntaxAnalysisMode.EQUAL_OR_SHORTER_LENGTH.");
}

Vector<FinalPlate> finalPlates = new Vector<FinalPlate>();
Expand Down Expand Up @@ -293,5 +294,4 @@ public void addChar(char chr) {
this.plate = this.plate + chr;
}
}

}
36 changes: 36 additions & 0 deletions src/main/java/net/sf/javaanpr/intelligence/SyntaxAnalysisMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package net.sf.javaanpr.intelligence;

public enum SyntaxAnalysisMode {
DO_NOT_PARSE,
ONLY_EQUAL_LENGTH,
EQUAL_OR_SHORTER_LENGTH;

public static SyntaxAnalysisMode getSyntaxAnalysisModeFromInt(int syntaxAnalysisModeInt) {
switch (syntaxAnalysisModeInt) {
case 0:
return SyntaxAnalysisMode.DO_NOT_PARSE;
case 1:
return SyntaxAnalysisMode.ONLY_EQUAL_LENGTH;
case 2:
return SyntaxAnalysisMode.EQUAL_OR_SHORTER_LENGTH;
default:
throw new IllegalArgumentException("Expected: 0, 1, or 2. Got: " + syntaxAnalysisModeInt);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package net.sf.javaanpr.intelligence;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class SyntaxAnalysisModeTest {

@Test
public void testGetSyntaxAnalysisModeFromIntReturnsDoNotParseWhenIntIsZero() {
assertEquals(SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(0), SyntaxAnalysisMode.DO_NOT_PARSE);
}

@Test
public void testGetSyntaxAnalysisModeFromIntReturnsOnlyEqualLengthWhenIntIsOne() {
assertEquals(SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(1), SyntaxAnalysisMode.ONLY_EQUAL_LENGTH);
}

@Test
public void testGetSyntaxAnalysisModeFromIntReturnsEqualOrShorterLengthWhenIntIsTwo() {
assertEquals(SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(2), SyntaxAnalysisMode.EQUAL_OR_SHORTER_LENGTH);
}

@Test(expected = IllegalArgumentException.class)
public void testGetSyntaxAnalysisModeThrowsIllegalArgumentExceptionWhenGivenIntNotEqualToOneTwoOrThree() {
SyntaxAnalysisMode.getSyntaxAnalysisModeFromInt(3);
}
}