我无法合并处理草图 使用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);
}
但是当我尝试将它与我当前的代码合并时,我遇到了问题。我当前的草图包括来自实时网络摄像头Feed的色彩跟踪。它不应该"显示"网络摄像头正在录制什么,但它应该显示交互。
//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;
}
我认为我遇到的问题是我不知道我应该改变的术语&#34;画布&#34;因为....或者如果这甚至是问题.... 任何帮助都会很棒,谢谢! -K
答案 0 :(得分:0)
您的代码存在以下几个问题:
server.sendImage(canvas);
此行:server.sendImage(canvas);
应在视频处理和绘图结束时调用,而不是在您抓取新帧后直接调用。
您可以欺骗并使用处理的get()功能来获取屏幕截图&#39;在您绘制了所有内容之后的当前帧,并将其发送给Siphon。
这样的事情:
//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();
}
这对于使用Siphon发送帧非常有用。 您应该仔细检查您的跟踪代码是否按预期工作。 目前还不清楚你想要实现的目标......在彩色跟踪区域周围绘制一些椭圆?