use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class ChecksDenseOpticalFlowBlockPyramid method processImageDontBlowUp.
@Test
public void processImageDontBlowUp() {
DenseOpticalFlowBlockPyramid<T> alg = createAlg(2, 3, 10);
ImagePyramid<T> pyramid = FactoryPyramid.discreteGaussian(new int[] { 1, 2, 4 }, 0, 2, false, ImageType.single(imageType));
GImageMiscOps.fillUniform(image, rand, 0, 200);
pyramid.process(image);
alg.process(pyramid, pyramid);
ImageFlow output = alg.getOpticalFlow();
for (int y = 0; y < output.height; y++) {
for (int x = 0; x < output.width; x++) {
assertTrue(output.get(x, y).isValid());
}
}
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class ExampleDenseOpticalFlow method main.
public static void main(String[] args) {
MediaManager media = DefaultMediaManager.INSTANCE;
// String fileName0 = UtilIO.pathExample("denseflow/dogdance07.png");
// String fileName1 = UtilIO.pathExample("denseflow/dogdance08.png");
String fileName0 = UtilIO.pathExample("denseflow/Urban2_07.png");
String fileName1 = UtilIO.pathExample("denseflow/Urban2_08.png");
// String fileName0 = UtilIO.pathExample("denseflow/Grove2_07.png");
// String fileName1 = UtilIO.pathExample("denseflow/Grove2_09.png");
DenseOpticalFlow<GrayF32> denseFlow = // FactoryDenseOpticalFlow.hornSchunckPyramid(null,GrayF32.class);
FactoryDenseOpticalFlow.broxWarping(null, GrayF32.class);
BufferedImage buff0 = media.openImage(fileName0);
BufferedImage buff1 = media.openImage(fileName1);
GrayF32 full = new GrayF32(buff0.getWidth(), buff0.getHeight());
// Dense optical flow is very computationally expensive. Just process the image at 1/2 resolution
GrayF32 previous = new GrayF32(full.width / 2, full.height / 2);
GrayF32 current = previous.createSameShape();
ImageFlow flow = new ImageFlow(previous.width, previous.height);
ConvertBufferedImage.convertFrom(buff0, full);
new FDistort(full, previous).scaleExt().apply();
ConvertBufferedImage.convertFrom(buff1, full);
new FDistort(full, current).scaleExt().apply();
// compute dense motion
denseFlow.process(previous, current, flow);
// Visualize the results
PanelGridPanel gui = new PanelGridPanel(1, 2);
BufferedImage converted0 = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
BufferedImage converted1 = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
BufferedImage visualized = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
ConvertBufferedImage.convertTo(previous, converted0, true);
ConvertBufferedImage.convertTo(current, converted1, true);
VisualizeOpticalFlow.colorized(flow, 10, visualized);
AnimatePanel animate = new AnimatePanel(150, converted0, converted1);
gui.add(animate);
gui.add(visualized);
animate.start();
ShowImages.showWindow(gui, "Dense Optical Flow", true);
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class VisualizeOpticalFlow method magnitudeAbs.
public static void magnitudeAbs(ImageFlow flowImage, BufferedImage out) {
GrayF32 magnitude = new GrayF32(flowImage.width, flowImage.height);
float max = 0;
for (int y = 0; y < flowImage.height; y++) {
for (int x = 0; x < flowImage.width; x++) {
ImageFlow.D f = flowImage.unsafe_get(x, y);
if (!f.isValid()) {
out.setRGB(x, y, 0xFF);
} else {
float m = Math.max(Math.abs(f.x), Math.abs(f.y));
if (m > max)
max = m;
magnitude.unsafe_set(x, y, m);
}
}
}
PixelMath.multiply(magnitude, 255 / max, magnitude);
ConvertBufferedImage.convertTo(magnitude, out);
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class VisualizeOpticalFlow method magnitudeAbs.
public static void magnitudeAbs(ImageFlow flowImage, float maxValue, BufferedImage out) {
GrayF32 magnitude = new GrayF32(flowImage.width, flowImage.height);
for (int y = 0; y < flowImage.height; y++) {
for (int x = 0; x < flowImage.width; x++) {
ImageFlow.D f = flowImage.unsafe_get(x, y);
if (!f.isValid()) {
out.setRGB(x, y, 0xFF);
} else {
float m = Math.max(Math.abs(f.x), Math.abs(f.y));
magnitude.unsafe_set(x, y, m);
}
}
}
PixelMath.multiply(magnitude, 255 / maxValue, magnitude);
PixelMath.boundImage(magnitude, 0, 255);
ConvertBufferedImage.convertTo(magnitude, out);
}
Aggregations