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

Blend video cam with background image

$
0
0
I must have missed something...


  1. import processing.opengl.*;
  2. import codeanticode.glgraphics.*;
  3. import codeanticode.gsvideo.*;
  4. GSCapture cam;
  5. GLTexture bottomLayer, topLayer, resultLayer;
  6. GLTextureFilter blendFilter;
  7. ScalarParam opacity;

  8. class ScalarParam {
  9.   float value;
  10.   float minValue;
  11.   float maxValue;
  12.   float step;
  13.   ScalarParam(float v,float mn, float mx, float s) {
  14.     value = v;
  15.     minValue = mn;
  16.     maxValue = mx;
  17.     step = s;
  18.   }
  19.   void Increment() {
  20.     value += step;
  21.     if (value > maxValue) value=maxValue;
  22.   }
  23.   void Decrement() {
  24.     value -= step;
  25.     if (value < minValue) value=minValue;
  26.   }
  27. }

  28. void setup()
  29. {
  30.   size(640, 480, GLConstants.GLGRAPHICS);
  31.   cam = new GSCapture(this, 640, 480);
  32.   blendFilter = new GLTextureFilter(this, "BlendDifference.xml");
  33.   opacity = new ScalarParam(1.0,0.0,1.0,0.01);
  34.   bottomLayer = new GLTexture(this, "background.jpg");
  35.   topLayer = new GLTexture(this);
  36.   cam.setPixelDest(topLayer);    
  37.   cam.start();
  38.   resultLayer = new GLTexture(this, topLayer.width,topLayer.height);
  39. }

  40. void draw()
  41. {
  42.     blendFilter.setParameterValue("Opacity", opacity.value);
  43.     blendFilter.apply(new GLTexture[] {bottomLayer, topLayer}, resultLayer);
  44.     resultLayer.render(0, 0);
  45.     //image(resultLayer, 0, 0);
  46. }

  47. void keyPressed()
  48. {
  49.   if (key == CODED) {
  50.     if (keyCode == UP) opacity.Increment();
  51.     else if (keyCode == DOWN) opacity.Decrement();
  52.   }
  53. }

  54. void captureEvent(GSCapture cam) {
  55.   cam.read();
  56. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles