为 VDMX 使用虹吸发送帧

Using Syphon Send Frames for VDMX

我在合并处理草图时遇到问题 与 VDMX。

当我 运行 示例代码时,它工作正常:

//Syphon Library - EXAMPLE Send Frames

import codeanticode.syphon.*;

PGraphics canvas;
SyphonServer server;

void setup() {
  size(400,400, P3D);
  canvas = createGraphics(400, 400, P3D);

  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");
}

void draw() {
  canvas.beginDraw();
  canvas.background(127);
  canvas.lights();
  canvas.translate(width/2, height/2);
  canvas.rotateX(frameCount * 0.01);
  canvas.rotateY(frameCount * 0.01);  
  canvas.box(150);
  canvas.endDraw();
  image(canvas, 0, 0);
  server.sendImage(canvas);
}

但是当我尝试将它与我当前的代码合并时,我遇到了问题。我当前的草图包括来自实时网络摄像头的颜色跟踪。它不应该 "show" 网络摄像头正在录制什么,但它应该显示交互。

//Final Project
//Krisia Ayala _ Prof.David Rios
//This sketch is supposed to merge all the codes in one.

import codeanticode.syphon.*;
import processing.video.*;

//Send Sketch to Syphon

Capture video;
long rs;
int num = 57, frames=10;
float theta;
PGraphics canvas;
SyphonServer server;

void setup() {
  size(640, 480);
  rs = (long) random(34);
  video = new Capture(this, width, height, 15);
  video.start();
  noStroke();
  smooth();
  frameRate(15); //ellipses
  smooth();
  background(255);
  server = new SyphonServer(this, "Processing Syphon");
  String [] animas = {
  };
}

void draw() {
  if (video.available()) {
    video.read();
    server.sendImage(canvas);
    //image(video, 0, 0, width, height);
    //color tracking
    int colorX = 0; // X-coordinate of the closest in color video pixel
    int colorY = 0; // Y-coordinate of the closest in color video pixel
    float closestColor = 500; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
    // Search for the closest in color pixel: For each row of pixels in the video image and
    // for each pixel in the yth row, compute each pixel's index in the video

    video.loadPixels();
    int index = 0;
    for (int y = 0; y < video.height; y++) {
      for (int x = 0; x < video.width; x++) {
        // Get the color stored in the pixel
        color pixelValue = video.pixels[index];
        // Determine the color of the pixel
        float colorProximity = abs(red(pixelValue)-27)+abs(green(pixelValue)-162)+abs(blue(pixelValue)-181);
        if (colorProximity < closestColor) {
          closestColor = colorProximity;
          closestColor=closestColor-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
          colorY = y;
          colorX = x;
        }
        index++;
      }
    }  

    //tracking
    smooth();
   // rect(0, 0, width+2, height+2);
   // ellipse(0, 0, width-4, height-4);
    fill(255);
    randomSeed(rs);
    for (int i=0; i<num; i++) {
      float x = random(790);
      float y2=20;
      float y = random(height/2-y2, height/2+y2);
      float offSet = map(x, 0, width, 0, TWO_PI);
      float d=70;
      float varY = map(sin(theta+offSet), -1, 1, -d, d);
      float varX = map(sin(theta+offSet*3), -1, 1, -d*2, d*2);
      float sz = 1;
      ellipse(colorX, colorY, 1, 2);
    }
//    theta+= TWO_PI/frames+120/2 ; 
//    if (frameCount>120 && frameCount<frames+120) saveFrame("image-###.gif");


   // noStroke();
   // fill(0, 0, 0, 128);
    //ellipse(colorX, colorY, 60, 40);

   // ellipse(colorX, colorY, 10, 10);
   // stroke(120);
    //process - white ellipse followed by a line: https://gyazo.com/d7d2c11c856dfdfddccd5816207ef859


     fill(0, 50);
  rect(0, 0, width+2, height+2);
  //ellipse(0, 0, width-4, height-4);
  fill(34, 255);
  randomSeed(rs);
  for (int i=0; i<num; i++) {
    float x = random(7809);
    float y2=20;
    float y = random(height/2-y2, height/2+y2);
    float offSet = map(x, 0, width, 0, TWO_PI*3);
    float d=90;
    float varY = map(sin(theta+offSet), -1, 1, -d, d);
    float varX = map(sin(theta+offSet*2), -1, 1, -d*2, d*2);
    float sz = 1;
   ellipse(colorX+varX, colorY+varY, sz, sz);
   ellipse(colorX+varX+2, colorY+varY, TWO_PI, sz);
  }
  //theta+= TWO_PI/frames;

  }
  theta+= TWO_PI/frames;
    theta+= TWO_PI+2/frames;
}

我认为我遇到的问题是我不知道我应该将 "canvas" 更改为...的术语。或者如果这就是问题... 任何帮助都会很棒,谢谢! -K

您的代码在当前形式下存在几个问题:

  1. canvas 变量从未被初始化,也未被使用 to draw into
  2. 您在阅读视频帧后直接调用 server.sendImage(canvas);

这一行:server.sendImage(canvas); 应该在您进行的视频处理和绘制结束时调用,而不是在您抓取新帧后立即调用。

您可以作弊并使用 Processing 的 get() 函数在绘制完所有内容后获取当前帧的 'screenshot',并将其发送给 Syphon。

像这样:

//Final Project
//Krisia Ayala _ Prof.David Rios
//This sketch is supposed to merge all the codes in one.

import codeanticode.syphon.*;
import processing.video.*;

//Send Sketch to Syphon

Capture video;
long rs;
int num = 57, frames=10;
float theta;
PGraphics canvas;
SyphonServer server;

void setup() {
  size(640, 480, P2D);
  rs = (long) random(34);
  video = new Capture(this, width, height, 15);
  video.start();
  noStroke();
  smooth();
  frameRate(15); //ellipses
  smooth();
  background(255);
  server = new SyphonServer(this, "Processing Syphon");
  String [] animas = {
  };
}

void draw() {
  //color tracking
  int colorX = 0; // X-coordinate of the closest in color video pixel
  int colorY = 0; // Y-coordinate of the closest in color video pixel
  float closestColor = 500; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
  // Search for the closest in color pixel: For each row of pixels in the video image and
  // for each pixel in the yth row, compute each pixel's index in the video
  video.loadPixels();
  int index = 0;
  for (int y = 0; y < video.height; y++) {
    for (int x = 0; x < video.width; x++) {
      // Get the color stored in the pixel
      color pixelValue = video.pixels[index];
      // Determine the color of the pixel
      float colorProximity = abs(red(pixelValue)-27)+abs(green(pixelValue)-162)+abs(blue(pixelValue)-181);
      if (colorProximity < closestColor) {
        closestColor = colorProximity;
        closestColor=closestColor-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
        colorY = y;
        colorX = x;
      }
      index++;
    }
  }  

  //tracking
  smooth();
  // rect(0, 0, width+2, height+2);
  // ellipse(0, 0, width-4, height-4);
  fill(255);
  randomSeed(rs);
  for (int i=0; i<num; i++) {
    float x = random(790);
    float y2=20;
    float y = random(height/2-y2, height/2+y2);
    float offSet = map(x, 0, width, 0, TWO_PI);
    float d=70;
    float varY = map(sin(theta+offSet), -1, 1, -d, d);
    float varX = map(sin(theta+offSet*3), -1, 1, -d*2, d*2);
    float sz = 1;
    ellipse(colorX, colorY, 1, 2);
  }

  fill(0, 50);
  rect(0, 0, width+2, height+2);
  fill(34, 255);
  randomSeed(rs);
  for (int i=0; i<num; i++) {
    float x = random(7809);
    float y2=20;
    float y = random(height/2-y2, height/2+y2);
    float offSet = map(x, 0, width, 0, TWO_PI*3);
    float d=90;
    float varY = map(sin(theta+offSet), -1, 1, -d, d);
    float varX = map(sin(theta+offSet*2), -1, 1, -d*2, d*2);
    float sz = 1;
    ellipse(colorX+varX, colorY+varY, sz, sz);
    ellipse(colorX+varX+2, colorY+varY, TWO_PI, sz);
  }

  theta+= TWO_PI/frames;
  theta+= TWO_PI+2/frames;

  //send a screenshot from Processing to Syhpn
  server.sendImage(get());
}
void captureEvent(Capture c) {
  c.read();
}

如果你想使用 canvas PGraphics 实例,你可以尝试这样的事情:

//Final Project
//Krisia Ayala _ Prof.David Rios
//This sketch is supposed to merge all the codes in one.

import codeanticode.syphon.*;
import processing.video.*;

//Send Sketch to Syphon

Capture video;
long rs;
int num = 57, frames=10;
float theta;
PGraphics canvas;
SyphonServer server;

void setup() {
  size(640, 480, P2D);
  rs = (long) random(34);
  video = new Capture(this, width, height, 15);
  video.start();
  noStroke();
  smooth();
  frameRate(15); //ellipses
  smooth();
  background(255);
  server = new SyphonServer(this, "Processing Syphon");
  String [] animas = {
  };
  //initialize the canvas
  canvas = createGraphics(width,height,P2D);
}

void draw() {
  //color tracking
  int colorX = 0; // X-coordinate of the closest in color video pixel
  int colorY = 0; // Y-coordinate of the closest in color video pixel
  float closestColor = 500; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
  // Search for the closest in color pixel: For each row of pixels in the video image and
  // for each pixel in the yth row, compute each pixel's index in the video
  video.loadPixels();
  int index = 0;
  for (int y = 0; y < video.height; y++) {
    for (int x = 0; x < video.width; x++) {
      // Get the color stored in the pixel
      color pixelValue = video.pixels[index];
      // Determine the color of the pixel
      float colorProximity = abs(red(pixelValue)-27)+abs(green(pixelValue)-162)+abs(blue(pixelValue)-181);
      if (colorProximity < closestColor) {
        closestColor = colorProximity;
        closestColor=closestColor-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
        colorY = y;
        colorX = x;
      }
      index++;
    }
  }  

  //tracking
  canvas.beginDraw();
  canvas.smooth();
  // rect(0, 0, width+2, height+2);
  // ellipse(0, 0, width-4, height-4);
  canvas.fill(255);
  randomSeed(rs);
  for (int i=0; i<num; i++) {
    float x = random(790);
    float y2=20;
    float y = random(height/2-y2, height/2+y2);
    float offSet = map(x, 0, width, 0, TWO_PI);
    float d=70;
    float varY = map(sin(theta+offSet), -1, 1, -d, d);
    float varX = map(sin(theta+offSet*3), -1, 1, -d*2, d*2);
    float sz = 1;
    canvas.ellipse(colorX, colorY, 1, 2);
  }

  canvas.fill(0, 50);
  canvas.rect(0, 0, width+2, height+2);
  canvas.fill(34, 255);
  randomSeed(rs);
  for (int i=0; i<num; i++) {
    float x = random(7809);
    float y2=20;
    float y = random(height/2-y2, height/2+y2);
    float offSet = map(x, 0, width, 0, TWO_PI*3);
    float d=90;
    float varY = map(sin(theta+offSet), -1, 1, -d, d);
    float varX = map(sin(theta+offSet*2), -1, 1, -d*2, d*2);
    float sz = 1;
    canvas.ellipse(colorX+varX, colorY+varY, sz, sz);
    canvas.ellipse(colorX+varX+2, colorY+varY, TWO_PI, sz);
  }
  canvas.endDraw();

  theta+= TWO_PI/frames;
  theta+= TWO_PI+2/frames;

  //render canvas in processing
  image(canvas,0,0);
  //send canvas to Syphon
  server.sendImage(canvas);
}
void captureEvent(Capture c) {
  c.read();
}

这对于使用 Syphon 发送帧很有用。 您应该仔细检查您的跟踪代码是否按预期工作。 不清楚您要实现的目标...在颜色跟踪区域周围绘制一些椭圆?