diff --git a/src/main/java/ch/bildspur/realsense/stream/VideoRSStream.java b/src/main/java/ch/bildspur/realsense/stream/VideoRSStream.java index 1e17d9f..e92c28e 100644 --- a/src/main/java/ch/bildspur/realsense/stream/VideoRSStream.java +++ b/src/main/java/ch/bildspur/realsense/stream/VideoRSStream.java @@ -27,6 +27,12 @@ public PImage getImage() { } public void copyPixels(VideoFrame frame) { + + // check if image has been changed by filters + if(frame.getWidth() != image.width || frame.getHeight() != image.height) { + image = new PImage(frame.getWidth(), frame.getHeight(), PConstants.RGB); + } + switch (frame.getProfile().getFormat()) { case Rgb8: copyRGB8(frame); diff --git a/src/test/java/ch/bildspur/realsense/test/DecimationFilterTest.java b/src/test/java/ch/bildspur/realsense/test/DecimationFilterTest.java new file mode 100644 index 0000000..b9e7046 --- /dev/null +++ b/src/test/java/ch/bildspur/realsense/test/DecimationFilterTest.java @@ -0,0 +1,69 @@ +package ch.bildspur.realsense.test; + + +import ch.bildspur.realsense.RealSenseCamera; +import ch.bildspur.realsense.type.ColorScheme; +import processing.core.PApplet; +import processing.opengl.PJOGL; + +/** + * Created by cansik on 21.03.17. + */ +public class DecimationFilterTest extends PApplet { + public final static int OUTPUT_WIDTH = 1280; + public final static int OUTPUT_HEIGHT = 500; + + public final static int VIEW_WIDTH = 640; + public final static int VIEW_HEIGHT = 480; + + public final static int FRAME_RATE = 30; + + RealSenseCamera camera = new RealSenseCamera(this); + + public static void main(String... args) { + DecimationFilterTest sketch = new DecimationFilterTest(); + sketch.runSketch(); + } + + public void settings() { + size(OUTPUT_WIDTH, OUTPUT_HEIGHT, FX2D); + PJOGL.profile = 1; + } + + public void setup() { + frameRate(FRAME_RATE); + + if(camera.isDeviceAvailable()) { + println("Camera found!"); + } + else { + println("No camera available!"); + exit(); + } + + camera.enableDepthStream(); + camera.enableColorStream(); + + camera.enableColorizer(ColorScheme.Classic); + camera.addDecimationFilter(7); + + camera.start(); + } + + public void draw() { + // clear screen + background(55); + + camera.readFrames(); + + // show both streams + image(camera.getDepthImage(), 0, 0, VIEW_WIDTH, VIEW_HEIGHT); + image(camera.getColorImage(), VIEW_WIDTH, 0, VIEW_WIDTH, VIEW_HEIGHT); + + fill(255, 255, 255); + textAlign(LEFT, CENTER); + text("Depth Stream", 20, VIEW_HEIGHT + 8); + text("Color Stream", VIEW_WIDTH + 20, VIEW_HEIGHT + 8); + surface.setTitle("RealSense Processing - FPS: " + Math.round(frameRate)); + } +}