-
Notifications
You must be signed in to change notification settings - Fork 5
/
Zone.java
54 lines (41 loc) · 1.42 KB
/
Zone.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
package org.genericsystem.cv;
import java.util.stream.Stream;
import org.opencv.core.Core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
public class Zone {
private final int num;
private final Rect rect;
public Zone(int num, Rect rect) {
this.num = num;
this.rect = rect;
}
public Rect getRect() {
return rect;
}
public ZoneScorer newUnsupervisedScorer(Stream<Img> imgs) {
return new ZoneScorer(this, imgs);
}
public Zone adjustRect(double dx, double dy, int maxWidht, int maxHeight) {
Point tl = new Point(rect.tl().x > dx ? rect.tl().x - dx : 0d, rect.tl().y > dy ? rect.tl().y - dy : 0d);
Point br = new Point((rect.br().x + dx > maxWidht) ? maxWidht : rect.br().x + dx,
(rect.br().y + dy > maxHeight) ? maxHeight : rect.br().y + dy);
return new Zone(num, new Rect(tl, br));
}
public void draw(Img img, Scalar color, int thickness) {
write(img, String.valueOf(num), 3, new Scalar(0, 0, 255), thickness);
Imgproc.rectangle(img.getSrc(), rect.tl(), rect.br(), color, thickness);
}
public void write(Img img, String text, double fontScale, Scalar color, int thickness) {
Imgproc.putText(img.getSrc(), text, new Point(rect.tl().x, rect.br().y), Core.FONT_HERSHEY_PLAIN, fontScale,
color, thickness);
}
public String ocr(Img img) {
return Ocr.doWork(img.getSrc(), getRect());
}
public int getNum() {
return num;
}
}