Skip to content

Instantly share code, notes, and snippets.

@JLLeitschuh
Created March 31, 2016 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLLeitschuh/0a6c2ca53aad6ae0a633810d6136537b to your computer and use it in GitHub Desktop.
Save JLLeitschuh/0a6c2ca53aad6ae0a633810d6136537b to your computer and use it in GitHub Desktop.
package edu.wpi.grip.core.operations.composite;
import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.Operation;
import edu.wpi.grip.core.sockets.InputSocket;
import edu.wpi.grip.core.sockets.OutputSocket;
import edu.wpi.grip.core.sockets.SocketHints;
import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacpp.opencv_core.Mat;
import java.util.Optional;
public class ThresholdMoving implements Operation {
@Override
public String getName() {
return "Threshold Moving";
}
@Override
public String getDescription() {
return "";
}
@Override
public InputSocket<?>[] createInputSockets(EventBus eventBus) {
return new InputSocket<?>[] {
new InputSocket<>(eventBus, SocketHints.Inputs.createMatSocketHint("image", false))
};
}
@Override
public OutputSocket<?>[] createOutputSockets(EventBus eventBus) {
return new OutputSocket<?>[]{
new OutputSocket<>(eventBus, SocketHints.Outputs.createMatSocketHint("moved"))
};
}
@Override
public Optional<?> createData() {
return Optional.of(new Mat());
}
@Override
public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs, Optional<?> data) {
final Mat input = ((InputSocket<Mat>) inputs[0]).getValue().get();
final OutputSocket<Mat> outputSocket = (OutputSocket<Mat>) outputs[0];
final Mat lastImage = (Mat) data.get();
if(!lastImage.empty()) {
opencv_core.absdiff(input, lastImage, outputSocket.getValue().get());
}
input.copyTo(lastImage);
outputSocket.setValue(outputSocket.getValue().get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment