Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Blend video cam with background image

$
0
0

second attempt with SimpleOpenNI - unsuccessfully


  1. import processing.opengl.*;
  2. import codeanticode.glgraphics.*;
  3. import SimpleOpenNI.*;

  4. GLTexture bottomLayer, topLayer, resultLayer;
  5. GLTextureFilter blendFilter;
  6. ScalarParam opacity;
  7. SimpleOpenNI  context;
  8. PImage img;

  9. void setup()
  10. {
  11.   size(640, 480, GLConstants.GLGRAPHICS);
  12.   context = new SimpleOpenNI(this);
  13.   // mirror is by default enabled
  14.   context.setMirror(true);
  15.   //context.enableRGB(640,480,30);
  16.   //context.enableRGB(1280,1024,15); 
  17.  
  18.   if(context.enableRGB() == false)
  19.   {
  20.      println("Can't open the rgbMap, maybe the camera is not connected or there is no rgbSensor!");
  21.      exit();
  22.      return;
  23.   }
  24.  
  25.   blendFilter = new GLTextureFilter(this, "BlendDifference.xml");
  26.   opacity = new ScalarParam(1.0,0.0,1.0,0.01);
  27.   bottomLayer = new GLTexture(this, "background.jpg");
  28.   topLayer = new GLTexture(this);    
  29.   resultLayer = new GLTexture(this, topLayer.width,topLayer.height);
  30. }

  31. void draw()
  32. {
  33.   background(0);
  34.   noStroke();
  35.   context.update();
  36.   img = context.rgbImage();
  37.   topLayer.putImage(img);
  38.   blendFilter.setParameterValue("Opacity", opacity.value);
  39.   blendFilter.apply(new GLTexture[] {bottomLayer, topLayer}, resultLayer);
  40.   resultLayer.render(0, 0);
  41.   println(frameRate);
  42. }

  43. void keyPressed()
  44. {
  45.   if (key == CODED) {
  46.     if (keyCode == UP) opacity.Increment();
  47.     else if (keyCode == DOWN) opacity.Decrement();
  48.   }
  49. }

  50. class ScalarParam {
  51.   float value;
  52.   float minValue;
  53.   float maxValue;
  54.   float step;
  55.   ScalarParam(float v,float mn, float mx, float s) {
  56.     value = v;
  57.     minValue = mn;
  58.     maxValue = mx;
  59.     step = s;
  60.   }
  61.   void Increment() {
  62.     value += step;
  63.     if (value > maxValue) value=maxValue;
  64.   }
  65.   void Decrement() {
  66.     value -= step;
  67.     if (value < minValue) value=minValue;
  68.   }
  69. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles