3
3
import edu .wpi .grip .core .events .RenderEvent ;
4
4
import edu .wpi .grip .core .operations .composite .LinesReport ;
5
5
import edu .wpi .grip .core .sockets .OutputSocket ;
6
+ import edu .wpi .grip .core .util .ImageDrawer ;
6
7
import edu .wpi .grip .ui .util .GripPlatform ;
7
8
import edu .wpi .grip .ui .util .ImageConverter ;
8
9
11
12
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
12
13
13
14
import java .util .List ;
15
+
14
16
import javafx .application .Platform ;
15
17
import javafx .geometry .Orientation ;
16
18
import javafx .scene .control .CheckBox ;
24
26
import static org .bytedeco .javacpp .opencv_core .Mat ;
25
27
import static org .bytedeco .javacpp .opencv_core .Point ;
26
28
import static org .bytedeco .javacpp .opencv_core .Scalar ;
27
- import static org .bytedeco .javacpp .opencv_core .bitwise_xor ;
28
- import static org .bytedeco .javacpp .opencv_imgproc .CV_GRAY2BGR ;
29
29
import static org .bytedeco .javacpp .opencv_imgproc .circle ;
30
- import static org .bytedeco .javacpp .opencv_imgproc .cvtColor ;
31
30
import static org .bytedeco .javacpp .opencv_imgproc .line ;
32
31
33
32
/**
@@ -39,11 +38,10 @@ public class LinesSocketPreviewView extends SocketPreviewView<LinesReport> {
39
38
private final ImageConverter imageConverter = new ImageConverter ();
40
39
private final ImageView imageView = new ImageView ();
41
40
private final Label infoLabel = new Label ();
42
- private final Mat tmp = new Mat ();
43
41
private final GripPlatform platform ;
44
42
@ SuppressWarnings ("PMD.ImmutableField" )
45
43
@ SuppressFBWarnings (value = "IS2_INCONSISTENT_SYNC" ,
46
- justification = "Do not need to synchronize inside of a constructor" )
44
+ justification = "Do not need to synchronize inside of a constructor" )
47
45
private boolean showInputImage = false ;
48
46
49
47
/**
@@ -82,30 +80,13 @@ private void convertImage() {
82
80
final List <LinesReport .Line > lines = linesReport .getLines ();
83
81
Mat input = linesReport .getInput ();
84
82
85
- // If there were lines found, draw them on the image before displaying it
86
- if (!linesReport .getLines ().isEmpty ()) {
87
- if (input .channels () == 3 ) {
88
- input .copyTo (tmp );
89
- } else {
90
- cvtColor (input , tmp , CV_GRAY2BGR );
91
- }
92
-
93
- input = tmp ;
94
-
95
- // If we don't want to see the background image, set it to black
96
- if (!this .showInputImage ) {
97
- bitwise_xor (tmp , tmp , tmp );
98
- }
99
-
100
- // For each line in the report, draw a line along with the starting and ending points
101
- for (LinesReport .Line line : lines ) {
102
- final Point startPoint = new Point ((int ) line .x1 , (int ) line .y1 );
103
- final Point endPoint = new Point ((int ) line .x2 , (int ) line .y2 );
104
- line (input , startPoint , endPoint , Scalar .WHITE , 2 , LINE_8 , 0 );
105
- circle (input , startPoint , 2 , Scalar .WHITE , 2 , LINE_8 , 0 );
106
- circle (input , endPoint , 2 , Scalar .WHITE , 2 , LINE_8 , 0 );
107
- }
108
- }
83
+ input = ImageDrawer .draw (
84
+ input ,
85
+ showInputImage ,
86
+ linesReport ::getLines ,
87
+ (m , lr ) -> lr .forEach (l -> drawLine (m , l ))
88
+ );
89
+
109
90
final Mat convertInput = input ;
110
91
final int numLines = lines .size ();
111
92
platform .runAsSoonAsPossible (() -> {
@@ -115,4 +96,13 @@ private void convertImage() {
115
96
});
116
97
}
117
98
}
99
+
100
+ private void drawLine (Mat image , LinesReport .Line line ) {
101
+ final Point startPoint = new Point ((int ) line .x1 , (int ) line .y1 );
102
+ final Point endPoint = new Point ((int ) line .x2 , (int ) line .y2 );
103
+ line (image , startPoint , endPoint , Scalar .WHITE , 2 , LINE_8 , 0 );
104
+ circle (image , startPoint , 2 , Scalar .WHITE , 2 , LINE_8 , 0 );
105
+ circle (image , endPoint , 2 , Scalar .WHITE , 2 , LINE_8 , 0 );
106
+ }
107
+
118
108
}
0 commit comments