Created
March 31, 2016 19:56
-
-
Save JLLeitschuh/0a6c2ca53aad6ae0a633810d6136537b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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