Skip to content

Commit 0934e33

Browse files
committed
Fixes BlobsSocketPreview Showing background image if 0 blobs
Closes #195
1 parent d6b5545 commit 0934e33

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,31 @@ public void onSocketChanged(SocketChangedEvent event) {
6363
private void convertImage() {
6464
synchronized (this) {
6565
final BlobsReport blobsReport = this.getSocket().getValue().get();
66-
Mat input = blobsReport.getInput();
66+
final Mat input = blobsReport.getInput();
67+
68+
if (input.channels() == 3) {
69+
input.copyTo(tmp);
70+
} else {
71+
cvtColor(input, tmp, CV_GRAY2BGR);
72+
}
73+
// If we don't want to see the background image, set it to black
74+
if (!this.showInputImage) {
75+
bitwise_xor(tmp, tmp, tmp);
76+
}
6777

6878
// If there were lines found, draw them on the image before displaying it
6979
if (!blobsReport.getBlobs().isEmpty()) {
70-
if (input.channels() == 3) {
71-
input.copyTo(tmp);
72-
} else {
73-
cvtColor(input, tmp, CV_GRAY2BGR);
74-
}
75-
76-
input = tmp;
77-
78-
// If we don't want to see the background image, set it to black
79-
if (!this.showInputImage) {
80-
bitwise_xor(tmp, tmp, tmp);
81-
}
82-
8380
// For each line in the report, draw a line along with the starting and ending points
8481
for (BlobsReport.Blob blob : blobsReport.getBlobs()) {
8582
final Point point = new Point((int) blob.x, (int) blob.y);
86-
circle(input, point, (int) (blob.size / 2), Scalar.WHITE, 2, LINE_8, 0);
83+
circle(tmp, point, (int) (blob.size / 2), Scalar.WHITE, 2, LINE_8, 0);
8784
}
8885
}
8986

90-
final Mat inputToConvert = input;
87+
final Mat output = tmp;
9188
final int numBlobs = blobsReport.getBlobs().size();
9289
platform.runAsSoonAsPossible(() -> {
93-
final Image image = this.imageConverter.convert(inputToConvert);
90+
final Image image = this.imageConverter.convert(output);
9491
this.imageView.setImage(image);
9592
this.infoLabel.setText("Found " + numBlobs + " blobs");
9693
});

0 commit comments

Comments
 (0)