Random Svg to visualize Video tracking- crashes all the time - can you help?
in
Core Library Questions
•
2 years ago
I`m working on a patch right now to visualize movement with randomized svgs.
Once I can make it work it crashes - can you help me to find the mistake?
Thanks!!
Kat
import processing.video.*;
String[] svgname = {"11.svg", "12.svg", "14.svg"};
PShape[] kbS;
Capture video;
float valRed= 0;
float valGreen= 0;
float valBlue= 0;
int brightestX =0;
int brightestY =0;
int x = 0, y = 0;
void setup() {
size(800, 600);
background (0);
kbS = new PShape[svgname.length];
video = new Capture(this, width, height, 5);
stroke(5);
smooth();
strokeWeight(1);
smooth();
}
void draw() {
valRed = random (255);
valGreen = random (255);
valBlue = random (255);
if (video.available()) {
video.read();
float brightestValue = 0;
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
int pixelValue = video.pixels[index];
float pixelBrightness = brightness(pixelValue);
if (pixelBrightness > (brightestValue)) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
if ((brightestX>10)) {
for (int s = 0; s < svgname.length; s++){
kbS[s] = loadShape(svgname[s]);
PShape kbRan = kbS[int(random(kbS.length))];
shape(kbRan, brightestY*1.33, brightestX*0.75, 100, 100);
kbRan.disableStyle();
fill(valRed, valGreen, valBlue);
}
if (keyPressed == true) {
save ("lf.tif");
}
}
}
}
Once I can make it work it crashes - can you help me to find the mistake?
Thanks!!
Kat
import processing.video.*;
String[] svgname = {"11.svg", "12.svg", "14.svg"};
PShape[] kbS;
Capture video;
float valRed= 0;
float valGreen= 0;
float valBlue= 0;
int brightestX =0;
int brightestY =0;
int x = 0, y = 0;
void setup() {
size(800, 600);
background (0);
kbS = new PShape[svgname.length];
video = new Capture(this, width, height, 5);
stroke(5);
smooth();
strokeWeight(1);
smooth();
}
void draw() {
valRed = random (255);
valGreen = random (255);
valBlue = random (255);
if (video.available()) {
video.read();
float brightestValue = 0;
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
int pixelValue = video.pixels[index];
float pixelBrightness = brightness(pixelValue);
if (pixelBrightness > (brightestValue)) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
if ((brightestX>10)) {
for (int s = 0; s < svgname.length; s++){
kbS[s] = loadShape(svgname[s]);
PShape kbRan = kbS[int(random(kbS.length))];
shape(kbRan, brightestY*1.33, brightestX*0.75, 100, 100);
kbRan.disableStyle();
fill(valRed, valGreen, valBlue);
}
if (keyPressed == true) {
save ("lf.tif");
}
}
}
}
1