-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectionResult.java
More file actions
102 lines (84 loc) · 2.64 KB
/
DetectionResult.java
File metadata and controls
102 lines (84 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package array.bliffoscope;
import java.awt.Point;
public class DetectionResult implements Comparable<DetectionResult> {
private String detectedTarget;
private double accuracy;
private Point topLeft;
private Point topRight;
private Point bottomLeft;
private Point bottomRight;
DetectionResult( String detectedTarget, double accuracy ) {
this.detectedTarget = detectedTarget;
this.accuracy = accuracy;
}
public void setTopPoints( Point topLeft, Point topRight ) {
this.topLeft = topLeft;
this.topRight = topRight;
}
public void setBottomPoints( Point bottomLeft, Point bottomRight ) {
this.bottomLeft = bottomLeft;
this.bottomRight = bottomRight;
}
/**
* @return Name of the detected target
*/
public String getDetectedTarget() {
return detectedTarget;
}
/**
* @return A number between 0 and 1. The closer the number to 1,
* the more accurate is the detection result.
*/
public double getAccuracy() {
return accuracy;
}
/**
* @return An array of two point coordinates specifying the location
* of the top boundary portion of the target. First point is
* the Top Left coordinate, the second is the Top Right
* coordinate.
*/
public Point[] getTopPoints() {
return new Point[] { topLeft, topRight };
}
/**
* @return An array of two point coordinates specifying the location
* of the bottom boundary portion of the target. First point is
* the Bottom Left coordinate, the second is the Bottom Right
* coordinate.
*/
public Point[] getBottomPoints() {
return new Point[] { bottomLeft, bottomRight };
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append( getDetectedTarget() );
int simplePercent = (int)(getAccuracy() * 100);
sb.append( " (" + simplePercent + "%) detected in area [ " );
sb.append( getPointDisplay(topLeft) + ", ");
sb.append( getPointDisplay(topRight) + ", " );
sb.append( getPointDisplay(bottomLeft) + ", ");
sb.append( getPointDisplay(bottomRight) + " ]");
return sb.toString();
}
private String getPointDisplay( Point point ) {
int x = (int)point.getX();
int y = (int)point.getY();
return "(" + x + "," + y + ")";
}
/**
* @throws NullPointerException if that is null
*/
@Override
public int compareTo( DetectionResult that ) {
double accuracyComparision = this.accuracy - that.accuracy;
if( accuracyComparision > 0 ) {
return 1;
} else if( accuracyComparision < 0 ) {
return -1;
} else {
return this.detectedTarget.compareTo( that.detectedTarget );
}
}
}