Skip to content

Commit

Permalink
Merge pull request #560 from JLLeitschuh/feat/thresholdMoving
Browse files Browse the repository at this point in the history
Adds an operation to threshold the moving parts of an image
  • Loading branch information
JLLeitschuh committed Apr 21, 2016
2 parents 69bb1bb + f4d6c1e commit 18a7a4a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class Operations {
NormalizeOperation::new,
WatershedOperation::new,
SwitchOperation::new,
ValveOperation::new
ValveOperation::new,
ThresholdMoving::new
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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 org.bytedeco.javacpp.opencv_core.Size;

import java.util.Optional;

import static edu.wpi.grip.core.Operation.Category.IMAGE_PROCESSING;

/**
* Finds the absolute difference between the current image and the previous image.
*/
public class ThresholdMoving implements Operation {


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

@Override
public String getDescription() {
return "Thresholds off parts of the image that have moved or changed between the previous and next image.";
}

@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 Category getCategory() {
return IMAGE_PROCESSING;
}

@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();

final Size lastSize = lastImage.size();
final Size inputSize = input.size();
if (!lastImage.empty() && lastSize.height() == inputSize.height() && lastSize.width() == inputSize.width()) {
opencv_core.absdiff(input, lastImage, outputSocket.getValue().get());
}
input.copyTo(lastImage);
outputSocket.setValue(outputSocket.getValue().get());
}
}

0 comments on commit 18a7a4a

Please sign in to comment.