首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在VDMX中使用信标发送帧

在VDMX中使用信标发送帧
EN

Stack Overflow用户
提问于 2015-12-13 06:42:54
回答 1查看 238关注 0票数 2

我很难将我的处理草图与VDMX合并。

当我运行示例代码时,它运行得很好:

代码语言:javascript
运行
复制
//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);
}

但是,当我试图将它与我的当前代码合并时,我会遇到问题。我目前的素描包括从实时网络摄像头输入的颜色跟踪。它不应该“显示”什么是网络摄像头记录,但它应该显示互动。

代码语言:javascript
运行
复制
//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;
}

我想我的问题是我不知道我该换个“画布”这个词.如果这就是问题所在..。任何帮助都会很好,谢谢!-K

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-14 12:29:52

当前形式的代码有几个问题:

  1. 画布变量从未初始化,也没有使用吸进
  2. 你看完视频后直接打电话给server.sendImage(canvas);

这一行:server.sendImage(canvas);应该在视频处理和绘图结束时调用您所做的,而不是在抓取新帧之后直接调用。

您可以在绘制完所有内容后,使用Processing的得到()函数获取当前帧的“屏幕快照”,并将其发送给Syphon。

就像这样:

代码语言:javascript
运行
复制
//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实例,可以尝试如下所示:

代码语言:javascript
运行
复制
//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();
}

这对于使用信标发送帧非常有用。您应该再次检查您的跟踪代码是否正常工作。还不清楚你试图在一个彩色跟踪区域周围的一些椭圆的achieve...drawing?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34248649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档