Skip to content

Commit d0f675a

Browse files
committed
Fixed analysis warning about if statements in PlateHorizontalGraph. Changed empty if statements to while statements. Removed unused argument count. Removed unused field handle. Changed Plate.java to reflect this change.
1 parent 45b7c34 commit d0f675a

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/main/java/net/sf/javaanpr/imageanalysis/Plate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private BufferedImage cutTopBottom(BufferedImage origin, PlateVerticalGraph grap
127127

128128
private BufferedImage cutLeftRight(BufferedImage origin, PlateHorizontalGraph graph) {
129129
graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2));
130-
Vector<Graph.Peak> peaks = graph.findPeak(3);
130+
Vector<Graph.Peak> peaks = graph.findPeak();
131131
if (peaks.size() != 0) {
132132
Graph.Peak p = peaks.elementAt(0);
133133
return origin.getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight());
@@ -162,7 +162,7 @@ private PlateVerticalGraph histogramYaxis(BufferedImage bi) {
162162
}
163163

164164
private PlateHorizontalGraph histogramXaxis(BufferedImage bi) {
165-
PlateHorizontalGraph graph = new PlateHorizontalGraph(this);
165+
PlateHorizontalGraph graph = new PlateHorizontalGraph();
166166
int w = bi.getWidth();
167167
int h = bi.getHeight();
168168
for (int x = 0; x < w; x++) {

src/main/java/net/sf/javaanpr/imageanalysis/PlateHorizontalGraph.java

+17-21
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,42 @@ public class PlateHorizontalGraph extends Graph {
2525
private static int horizontalDetectionType =
2626
Configurator.getConfigurator().getIntProperty("platehorizontalgraph_detectionType");
2727

28-
private Plate handle;
29-
30-
public PlateHorizontalGraph(Plate handle) {
31-
this.handle = handle;
32-
}
33-
3428
public float derivation(int index1, int index2) {
3529
return this.yValues.elementAt(index1) - this.yValues.elementAt(index2);
3630
}
3731

38-
public Vector<Peak> findPeak(int count) {
32+
public Vector<Peak> findPeak() {
3933
if (PlateHorizontalGraph.horizontalDetectionType == 1) {
40-
return this.findPeak_edgedetection(count);
34+
return this.findPeak_edgedetection();
4135
}
42-
return this.findPeak_derivative(count);
36+
return this.findPeak_derivative();
4337
}
4438

45-
public Vector<Peak> findPeak_derivative(int count) {
46-
int a, b;
39+
public Vector<Peak> findPeak_derivative() {
40+
int a = 2;
41+
int b = this.yValues.size() - 1 - 2;
4742
float maxVal = this.getMaxValue();
48-
for (a = 2; (-this.derivation(a, a + 4) < (maxVal * 0.2)) && (a < (this.yValues.size() - 2 - 2 - 4)); a++) {
49-
// intentionally empty
43+
while ((-this.derivation(a, a + 4) < (maxVal * 0.2)) && (a < (this.yValues.size() - 2 - 2 - 4))) {
44+
a++;
5045
}
51-
for (b = this.yValues.size() - 1 - 2; (this.derivation(b - 4, b) < (maxVal * 0.2)) && (b > (a + 2)); b--) {
52-
// intentionally empty
46+
while ((this.derivation(b - 4, b) < (maxVal * 0.2)) && (b > (a + 2))) {
47+
b--;
5348
}
5449
Vector<Peak> outPeaks = new Vector<Peak>();
5550
outPeaks.add(new Peak(a, b));
5651
super.peaks = outPeaks;
5752
return outPeaks;
5853
}
5954

60-
public Vector<Peak> findPeak_edgedetection(int count) {
55+
public Vector<Peak> findPeak_edgedetection() {
6156
float average = this.getAverageValue();
62-
int a, b;
63-
for (a = 0; this.yValues.elementAt(a) < average; a++) {
64-
// intentionally empty
57+
int a = 0;
58+
int b = this.yValues.size() - 1;
59+
while (this.yValues.elementAt(a) < average) {
60+
a++;
6561
}
66-
for (b = this.yValues.size() - 1; this.yValues.elementAt(b) < average; b--) {
67-
// intentionally empty
62+
while (this.yValues.elementAt(b) < average) {
63+
b--;
6864
}
6965
Vector<Peak> outPeaks = new Vector<Peak>();
7066
a = Math.max(a - 5, 0);

0 commit comments

Comments
 (0)