Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public static void addOperations(EventBus eventBus) {
eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(BlobsReport.class)));
eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(LinesReport.class)));
eventBus.post(new OperationAddedEvent(new PublishVideoOperation()));
eventBus.post(new OperationAddedEvent(new PlaceRectangleOperation()));
eventBus.post(new OperationAddedEvent(new NumberThresholdOperation()));
eventBus.post(new OperationAddedEvent(new CountContoursOperation()));
eventBus.post(new OperationAddedEvent(new CropOperation()));
}
//eventBus.post(new OperationAddedEvent(new ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line here.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package edu.wpi.grip.core.operations.composite;

import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.*;

import java.io.InputStream;
import java.util.Optional;

/**
* An {@link Operation} that takes in a list of contours and outputs a list of any contours in the input that match
* all of several criteria. Right now, the user can specify a minimum area, minimum perimeter, and ranges for width
* and height.
* <p>
* This is useful because running a Find Contours on a real-life image typically leads to many small undesirable
* contours from noise and small objects, as well as contours that do not meet the expected characteristics of the
* feature we're actually looking for. So, this operation can help narrow them down.
*/
public class CountContoursOperation implements Operation {

private final SocketHint<ContoursReport> contoursHint = new SocketHint.Builder<>(ContoursReport.class)
.identifier("Contours").initialValueSupplier(ContoursReport::new).build();

private final SocketHint<Number> amountHint =
SocketHints.Inputs.createNumberSpinnerSocketHint("Amount", 0, 0, Integer.MAX_VALUE);

@Override
public String getName() {
return "Count Contours";
}

@Override
public String getDescription() {
return "Find number of contours.";
}

@Override
public Optional<InputStream> getIcon() {
return Optional.of(getClass().getResourceAsStream("/edu/wpi/grip/ui/icons/grip.png"));
}

@Override
public InputSocket<?>[] createInputSockets(EventBus eventBus) {
return new InputSocket<?>[]{
new InputSocket<>(eventBus, contoursHint)
};
}

@Override
public OutputSocket<?>[] createOutputSockets(EventBus eventBus) {
return new OutputSocket<?>[]{new OutputSocket<>(eventBus, amountHint)};
}

@Override
@SuppressWarnings("unchecked")
public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
final InputSocket<ContoursReport> inputSocket = (InputSocket<ContoursReport>) inputs[0];

long amount = inputSocket.getValue().get().getContours().size();

final OutputSocket<Number> outputSocket = (OutputSocket<Number>) outputs[0];
outputSocket.setValue(amount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package edu.wpi.grip.core.operations.composite;

import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.*;
import org.bytedeco.javacpp.opencv_core;

import java.io.InputStream;
import java.util.Optional;

import static org.bytedeco.javacpp.opencv_imgproc.rectangle;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* @author Jaxon A Brown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a general practice of not including authorship on class files.

*/
public class CropOperation implements Operation {
private final SocketHint<opencv_core.Mat> inputHint = SocketHints.Inputs.createMatSocketHint("Input", false);
private final SocketHint<opencv_core.Point> p1Hint = SocketHints.Inputs.createPointSocketHint("P1", false);
private final SocketHint<opencv_core.Point> p2Hint = SocketHints.Inputs.createPointSocketHint("P2", false);

private final SocketHint<opencv_core.Mat> outputHint = SocketHints.Inputs.createMatSocketHint("Output", true);

@Override
public String getName() {
return "Crop";
}

@Override
public String getDescription() {
return "Crop an image";
}

@Override
public Optional<InputStream> getIcon() {
return Optional.of(getClass().getResourceAsStream("/edu/wpi/grip/ui/icons/grip.png"));
}

@Override
public InputSocket<?>[] createInputSockets(EventBus eventBus) {
return new InputSocket<?>[]{
new InputSocket<>(eventBus, inputHint),
new InputSocket<>(eventBus, p1Hint),
new InputSocket<>(eventBus, p2Hint),
};
}

@Override
public OutputSocket<?>[] createOutputSockets(EventBus eventBus) {
return new OutputSocket<?>[]{
new OutputSocket<>(eventBus, outputHint)
};
}

@Override
@SuppressWarnings("unchecked")
public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
final opencv_core.Mat input = ((InputSocket<opencv_core.Mat>) inputs[0]).getValue().get();
final opencv_core.Point p1 = ((InputSocket<opencv_core.Point>) inputs[1]).getValue().get();
final opencv_core.Point p2 = ((InputSocket<opencv_core.Point>) inputs[2]).getValue().get();

final OutputSocket<opencv_core.Mat> outputSocket = (OutputSocket<opencv_core.Mat>) outputs[0];
final opencv_core.Mat output;

opencv_core.Rect rect = new opencv_core.Rect(p1, p2);
output = new opencv_core.Mat(input, rect);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may introduce a memory leak but if you aren't quite sure how to resolve it I can see if I can.


outputSocket.setValue(output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package edu.wpi.grip.core.operations.composite;

import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.*;

import java.io.InputStream;
import java.util.Optional;

/**
* @author Jaxon A Brown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a general practice of not including authorship on class files.

*/
public class NumberThresholdOperation implements Operation {
private final SocketHint<Number> numHint = SocketHints.Inputs.createNumberSpinnerSocketHint("Input", 0);
private final SocketHint<Number> minHint = SocketHints.Inputs.createNumberSpinnerSocketHint("Min", -1);
private final SocketHint<Number> maxHint = SocketHints.Inputs.createNumberSpinnerSocketHint("Max", 1);

private final SocketHint<Boolean> boolHint = SocketHints.Outputs.createBooleanSocketHint("Output", true);

@Override
public String getName() {
return "NumberThreshold";
}

@Override
public String getDescription() {
return "Returns a boolean on weather or not the number is within the given range.";
}

@Override
public Optional<InputStream> getIcon() {
return Optional.of(getClass().getResourceAsStream("/edu/wpi/grip/ui/icons/grip.png"));
}

@Override
public InputSocket<?>[] createInputSockets(EventBus eventBus) {
return new InputSocket<?>[] {
new InputSocket<>(eventBus, numHint),
new InputSocket<>(eventBus, minHint),
new InputSocket<>(eventBus, maxHint),
};
}

@Override
public OutputSocket<?>[] createOutputSockets(EventBus eventBus) {
return new OutputSocket[] {
new OutputSocket<>(eventBus, boolHint)
};
}

@Override
@SuppressWarnings("unchecked")
public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
final Number num = ((InputSocket<Number>) inputs[0]).getValue().get();
final Number min = ((InputSocket<Number>) inputs[1]).getValue().get();
final Number max = ((InputSocket<Number>) inputs[2]).getValue().get();

final OutputSocket<Boolean> outputSocket = (OutputSocket<Boolean>) outputs[0];

Boolean output;
if(min.doubleValue() <= num.doubleValue() && max.doubleValue() >= num.doubleValue()) {
output = true;
} else {
output = false;
}

outputSocket.setValue(output);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could turn this into one line if you wanted.

outputSocket.setValue(min.doubleValue() <= num.doubleValue() && max.doubleValue() >= num.doubleValue());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package edu.wpi.grip.core.operations.composite;

import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.*;
import org.bytedeco.javacpp.opencv_core;

import java.io.InputStream;
import java.util.Optional;

import static org.bytedeco.javacpp.opencv_imgproc.*;

/**
* @author Jaxon A Brown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a general practice of not including authorship on class files.

*/
public class PlaceRectangleOperation implements Operation {
private final SocketHint<opencv_core.Mat> inputHint = SocketHints.Inputs.createMatSocketHint("Input", false);
private final SocketHint<opencv_core.Point> p1Hint = SocketHints.Inputs.createPointSocketHint("P1", false);
private final SocketHint<opencv_core.Point> p2Hint = SocketHints.Inputs.createPointSocketHint("P2", false);

private final SocketHint<opencv_core.Mat> outputHint = SocketHints.Inputs.createMatSocketHint("Output", true);

@Override
public String getName() {
return "PlaceRectangle";
}

@Override
public String getDescription() {
return "Place a red rectangle over the image.";
}

@Override
public Optional<InputStream> getIcon() {
return Optional.of(getClass().getResourceAsStream("/edu/wpi/grip/ui/icons/grip.png"));
}

@Override
public InputSocket<?>[] createInputSockets(EventBus eventBus) {
return new InputSocket<?>[]{
new InputSocket<>(eventBus, inputHint),
new InputSocket<>(eventBus, p1Hint),
new InputSocket<>(eventBus, p2Hint),
};
}

@Override
public OutputSocket<?>[] createOutputSockets(EventBus eventBus) {
return new OutputSocket<?>[]{
new OutputSocket<>(eventBus, outputHint)
};
}

@Override
@SuppressWarnings("unchecked")
public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
final opencv_core.Mat input = ((InputSocket<opencv_core.Mat>) inputs[0]).getValue().get();
final opencv_core.Point p1 = ((InputSocket<opencv_core.Point>) inputs[1]).getValue().get();
final opencv_core.Point p2 = ((InputSocket<opencv_core.Point>) inputs[2]).getValue().get();

final OutputSocket<opencv_core.Mat> outputSocket = (OutputSocket<opencv_core.Mat>) outputs[0];
final opencv_core.Mat output = outputSocket.getValue().get();

input.copyTo(output);
rectangle(output, p1, p2, org.bytedeco.javacpp.helper.opencv_core.AbstractScalar.RED, 2, 1, 0);

outputSocket.setValue(output);
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Jan 04 19:05:21 EST 2016
#Mon Jan 18 10:15:12 EST 2016
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include this file in your pull request.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down