Hey all
I'm new to Processing but am doing a uni project which needs the image on screen to change depending on the position of a tracking ball which tracks an infrared light captured by my webcam. So far I've been able to get the image to change as the light moves, but I need the previous image to remain on the screen until the new one comes up - at the moment there's a lot of flashing images!
Also, my code is made up of edited code from different sources, and I'm not sure exactly what some of the phrases mean so if anyone can 'translate' for me that would be great! (I've highlighted the ones I mean)
Here's the code so far...
//Import the video library:
import processing.video.*;
Capture myCapture; // copy of the video library
float worldRecord = 2000.0; // initialise the worldrecordint xFound = width/2; // initialise the location of the tracking ball
int yFound = height/2;
boolean goodTrack = false; // whether or not we have something in the image
// that's close enough to our tracked colour
color targetColor = color(255,255,255); // the target colour: white
void setup()
{
// set window size:
size(1260,740);
frameRate(200);
myCapture = new Capture(this, width, height,
300);
}
//this gets called whenever there's a new frame of video available:
void captureEvent(Capture myCapture)
{
// read the myCamera and update the pixel array:
myCapture.read();
// we don't have a pixel that matches our colour yet:
goodTrack = false;
// scan all the pixels looking for a match:
for(int row=0; row<height; row++) {
for(int column=0; column<width; column++) { //for each column
// get the colour of this pixel
// find pixel in linear array using formula: pos = row*rowWidth+column:
color pixelColor = myCapture.pixels[row*width+column];
// calculate the difference between the pixel's color
// and our desired color:
float diff = abs(red(targetColor) - red(pixelColor)) +
abs(green(targetColor) - green(pixelColor)) +
abs(blue(targetColor) - blue(pixelColor))/3;
if (diff<= worldRecord){ // if this is closest to our target color
worldRecord = diff;
yFound = row; // mark the spot for drawing it later
xFound = column;
goodTrack = true;
}
}
}
}
void draw()
{
PImage b;
// draw my camera image on the screen:
image(myCapture, 0, 0);
// if we get a good color match, draw a dot there:
if (goodTrack) {
// fill(targetColor);
// ellipse(xFound, yFound, 15, 15);
if (xFound<30) {
b = loadImage("Image1.jpg");
image(b, 0, 0);
}
if ((xFound>=30)&&(xFound<60)) {
b = loadImage("Image2.jpg");
image(b, 0, 0);
}
if ((xFound>=60)&&(xFound<90)) {
b = loadImage("Image3.jpg");
image(b, 0, 0);
}
if ((xFound>=90)&&(xFound<120)) {
b = loadImage("Image4.jpg");
image(b, 0, 0);
}
if ((xFound>=120)&&(xFound<150)) {
b = loadImage("Image5.jpg");
image(b, 0, 0);
}
if ((xFound>=150)&&(xFound<180)) {
b = loadImage("Image6.jpg");
image(b, 0, 0);
}
if ((xFound>=180)&&(xFound<210)) {
b = loadImage("Image7.jpg");
image(b, 0, 0);
}
if ((xFound>=210)&&(xFound<240)) {
b = loadImage("Image8.jpg");
image(b, 0, 0);
}
if ((xFound>=240)&&(xFound<270)) {
b = loadImage("Image9.jpg");
image(b, 0, 0);
}
if ((xFound>=270)&&(xFound<300)) {
b = loadImage("Image10.jpg");
image(b, 0, 0);
}
if ((xFound>=300)&&(xFound<330)) {
b = loadImage("Image11.jpg");
image(b, 0, 0);
}
if ((xFound>=330)&&(xFound<360)) {
b = loadImage("Image12.jpg");
image(b, 0, 0);
}
if ((xFound>=360)&&(xFound<390)) {
b = loadImage("Image13.jpg");
image(b, 0, 0);
}
if ((xFound>=390)&&(xFound<420)) {
b = loadImage("Image14.jpg");
image(b, 0, 0);
}
if ((xFound>=420)&&(xFound<450)) {
b = loadImage("Image15.jpg");
image(b, 0, 0);
}
if ((xFound>=450)&&(xFound<480)) {
b = loadImage("Image16.jpg");
image(b, 0, 0);
}
if ((xFound>=480)&&(xFound<510)) {
b = loadImage("Image17.jpg");
image(b, 0, 0);
}
if ((xFound>=510)&&(xFound<540)) {
b = loadImage("Image18.jpg");
image(b, 0, 0);
}
if ((xFound>=540)&&(xFound<570)) {
b = loadImage("Image19.jpg");
image(b, 0, 0);
}
if ((xFound>=570)&&(xFound<600)) {
b = loadImage("Image20.jpg");
image(b, 0, 0);
}
if ((xFound>=600)&&(xFound<630)) {
b = loadImage("Image21.jpg");
image(b, 0, 0);
}
if ((xFound>=630)&&(xFound<660)) {
b = loadImage("Image22.jpg");
image(b, 0, 0);
}
if ((xFound>=660)&&(xFound<690)) {
b = loadImage("Image23.jpg");
image(b, 0, 0);
}
if ((xFound>=690)&&(xFound<720)) {
b = loadImage("Image24.jpg");
image(b, 0, 0);
}
if ((xFound>=720)&&(xFound<750)) {
b = loadImage("Image25.jpg");
image(b, 0, 0);
}
if ((xFound>=750)&&(xFound<780)) {
b = loadImage("Image26.jpg");
image(b, 0, 0);
}
if ((xFound>=780)&&(xFound<810)) {
b = loadImage("Image27.jpg");
image(b, 0, 0);
}
if ((xFound>=810)&&(xFound<840)) {
b = loadImage("Image28.jpg");
image(b, 0, 0);
}
if ((xFound>=840)&&(xFound<870)) {
b = loadImage("Image29.jpg");
image(b, 0, 0);
}
if ((xFound>=870)&&(xFound<900)) {
b = loadImage("Image30.jpg");
image(b, 0, 0);
}
}
}
Any help would be greatly appreciated
Thanks
Jo