Hey,
For some weird reason my GSvideo capture mirrors the movement on the webcam.
Is there a way to reverse the X values so that when I move my hand to the right it shows
up with me moving my hand to the right on the screen?
I tried using a reverse method I found on the net, but it reverses the Y values...
Script is below
import codeanticode.gsvideo.*;
public class ArrayHandle
{
public static Object[] reverse(Object[] arr)
{
List<Object> list = Arrays.asList(arr);
Collections.reverse(list);
return list.toArray();
}
}
int numPixels;
int[] backgroundPixels;
int[] currentPixels;
GSCapture cam;
int[] cords = {0};
int[] diffies;
int framer = 0;
int presenceSum = 0;
void setup() {
size(640, 480);
cam = new GSCapture(this, width, height);
numPixels = cam.width * cam.height;
backgroundPixels = new int[numPixels];
currentPixels = new int[numPixels];
loadPixels();
}
void draw() {
if (cam.available() == true) {
cam.read();
cam.loadPixels();
arraycopy(cam.pixels, currentPixels);
// currentPixels = reverse(currentPixels);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int loc = x + y * width;
color currColor = currentPixels[loc];
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
color bkgdColor = backgroundPixels[loc];
int bkgdR = (bkgdColor >> 16) & 0xFF;
int bkgdG = (bkgdColor >> 8) & 0xFF;
int bkgdB = bkgdColor & 0xFF;
int diffR = abs(currR - bkgdR);
int diffG = abs(currG - bkgdG);
int diffB = abs(currB - bkgdB);
presenceSum += diffR + diffG + diffB;
if (currG == bkgdG) {pixels[loc] = color(255);
} else {pixels[loc] = color(0);}
}
}
}
updatePixels();
rect(10, 10, presenceSum * 0.000005, 20);
//abs what is abs in trig?
//beginShape();
//vertex(50, 60);
//vertex(100, 200);
//endShape();
//dist() computes the distance between previous value and current value
// map() will map input to a set range mouseX, 60, 180 etc.
if (framer > 5 ) {
arraycopy(cam.pixels, backgroundPixels);
// backgroundPixels = reverse(backgroundPixels);
framer = framer - 5;
presenceSum = 0;
}
else {
framer++;}
if(Arrays.equals(currentPixels, backgroundPixels)) { // no test right now
}
else { // no test right now
}
cam.updatePixels();
// color currColor = video.pixels[i];
// image(cam, x in box, y in box);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
// set(160, 100, cam);
}
For some weird reason my GSvideo capture mirrors the movement on the webcam.
Is there a way to reverse the X values so that when I move my hand to the right it shows
up with me moving my hand to the right on the screen?
I tried using a reverse method I found on the net, but it reverses the Y values...
Script is below
import codeanticode.gsvideo.*;
public class ArrayHandle
{
public static Object[] reverse(Object[] arr)
{
List<Object> list = Arrays.asList(arr);
Collections.reverse(list);
return list.toArray();
}
}
int numPixels;
int[] backgroundPixels;
int[] currentPixels;
GSCapture cam;
int[] cords = {0};
int[] diffies;
int framer = 0;
int presenceSum = 0;
void setup() {
size(640, 480);
cam = new GSCapture(this, width, height);
numPixels = cam.width * cam.height;
backgroundPixels = new int[numPixels];
currentPixels = new int[numPixels];
loadPixels();
}
void draw() {
if (cam.available() == true) {
cam.read();
cam.loadPixels();
arraycopy(cam.pixels, currentPixels);
// currentPixels = reverse(currentPixels);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int loc = x + y * width;
color currColor = currentPixels[loc];
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
color bkgdColor = backgroundPixels[loc];
int bkgdR = (bkgdColor >> 16) & 0xFF;
int bkgdG = (bkgdColor >> 8) & 0xFF;
int bkgdB = bkgdColor & 0xFF;
int diffR = abs(currR - bkgdR);
int diffG = abs(currG - bkgdG);
int diffB = abs(currB - bkgdB);
presenceSum += diffR + diffG + diffB;
if (currG == bkgdG) {pixels[loc] = color(255);
} else {pixels[loc] = color(0);}
}
}
}
updatePixels();
rect(10, 10, presenceSum * 0.000005, 20);
//abs what is abs in trig?
//beginShape();
//vertex(50, 60);
//vertex(100, 200);
//endShape();
//dist() computes the distance between previous value and current value
// map() will map input to a set range mouseX, 60, 180 etc.
if (framer > 5 ) {
arraycopy(cam.pixels, backgroundPixels);
// backgroundPixels = reverse(backgroundPixels);
framer = framer - 5;
presenceSum = 0;
}
else {
framer++;}
if(Arrays.equals(currentPixels, backgroundPixels)) { // no test right now
}
else { // no test right now
}
cam.updatePixels();
// color currColor = video.pixels[i];
// image(cam, x in box, y in box);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
// set(160, 100, cam);
}
1