-
Notifications
You must be signed in to change notification settings - Fork 5
/
Lines.java
78 lines (63 loc) · 1.76 KB
/
Lines.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
package org.genericsystem.cv.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
public class Lines implements Iterable<Line> {
public final List<Line> lines = new ArrayList<>();
protected final double mean;
public Lines(Mat src) {
double mean = 0;
for (int i = 0; i < src.rows(); i++) {
double[] val = src.get(i, 0);
Line line = new Line(val[0], val[1], val[2], val[3]);
lines.add(line);
mean += line.getAngle();
}
this.mean = mean / src.rows();
}
public Lines(Collection<Line> lines) {
double mean = 0;
for (Line line : lines) {
this.lines.add(line);
mean += line.getAngle();
}
this.mean = mean / lines.size();
}
public List<Point[]> toLinesSegments() {
return lines.stream().map(line -> line.getSegment()).collect(Collectors.toList());
}
public List<Line> rotate(Mat matrix) {
return lines.stream().map(line -> line.rotationTransform(matrix)).collect(Collectors.toList());
}
public List<Line> perspectivTransform(Mat matrix) {
return lines.stream().map(line -> line.perspectivTransform(matrix)).collect(Collectors.toList());
}
public void draw(Mat frame, Scalar color) {
lines.forEach(line -> line.draw(frame, color, 1));
}
public List<Line> getLines() {
return lines.stream().collect(Collectors.toList());
}
public int size() {
return lines.size();
}
public double getMean() {
return mean;
}
public double getMeanInDegree() {
return mean / Math.PI * 180;
}
@Override
public Iterator<Line> iterator() {
return lines.iterator();
}
public Stream<Line> stream() {
return lines.stream();
}
}