-
Notifications
You must be signed in to change notification settings - Fork 5
/
Field.java
93 lines (74 loc) · 1.82 KB
/
Field.java
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
package org.genericsystem.cv.retriever;
import java.util.ArrayList;
import java.util.List;
import org.genericsystem.cv.Img;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
public class Field extends AbstractField {
private Field parent;
private List<Field> children;
private static final int LABELS_SIZE_THRESHOLD = 15;
private static final double CONFIDENCE_THRESHOLD = 0.92;
private boolean locked = false;
public Field(Rect rect) {
super(rect);
this.parent = null;
this.children = new ArrayList<>();
}
public Field(Field other) {
super(other);
if (other instanceof Field) {
this.parent = other.parent;
this.children = other.children;
setFinal();
}
}
@Override
public void ocr(Img rootImg) {
super.ocr(rootImg);
if (attempts <= 3 || attempts % 5 == 0)
consolidateOcr(false);
}
@Override
public void merge(AbstractField field) {
super.merge(field);
if (field instanceof Field)
setFinal();
}
@Override
public void resetDeadCounter() {
super.resetDeadCounter();
setFinal();
}
public void drawLockedField(Img display, Mat homography) {
if (locked)
drawRect(display, getRectPointsWithHomography(homography), new Scalar(255, 172, 0), 2);
}
public void setFinal() {
if (!locked)
if (getLabelsSize() > LABELS_SIZE_THRESHOLD && getConfidence() > CONFIDENCE_THRESHOLD)
this.locked = true;
}
public boolean isLocked() {
return locked;
}
public void setChildren(List<Field> children) {
this.children = children;
}
public void addChild(Field child) {
children.add(child);
}
public List<Field> getChildren() {
return children;
}
public void addChildren(List<Field> children) {
children.addAll(children);
}
public Field getParent() {
return parent;
}
public void setParent(Field parent) {
this.parent = parent;
}
}