help
hello all, new to c code : this is for a school project in GameArtDesign.
general idea is: store image from a webcam,the compare all following images form the webcam with original if there is a change then change pixels to other color ( exp white )
my general idea was store the first image in an array, take next image and compare pixels with the original, if there is a big change (>33,3%) then change pixels to white. or else show present pixel. simple idea.But my knowlegde of C is not enough to get thru the errors. I based the webcam routine on an example in a tutorial. Help is most welcome.
greets
the code :
// Step 1. Import the video library
int a = 1; // make 'a' trigger for the first webcam image
import processing.video.*;
// Step 2. Declare a Capture object
Capture video;
void setup() {
size(640,480);
delay ( 1 );
// Step 3. Initialize Capture object via Constructor
video = new Capture(this, 640, 480, 10);
background(0);
}
void draw() {
// Check to see if a new frame is available
if (video.available()) {
// If so, read it.
video.read(); }
loadPixels();
video.loadPixels();
for (int x = 0; x < video.width; x++ ) {
for (int y = 0; y < video.height; y++ ) {
// calculate the 1D location from a 2D grid
int loc = x + y * video.width;
// variables
float r, g, b, dr, dg, db, dt;
float (loc)= ro, go, bo; // vairabels in an array
//store pixels r g b
r = red (video.pixels [loc] ) ;
g = green (video.pixels [loc] ) ;
b = blue (video.pixels [loc] ) ;
// if a = 1 then store the results from the first webcam screen in ro(=original screen)
if ( a > 0 ) { // this is the first image from webcam
ro[loc] = r; //store original display in an array ro
go[loc] = g; // go
bo[loc] = b; } // bo
if (loc >307199) { a = 0; } // make 'a' zero if all the first webcampixels are stored in array.= width*height
// detect a difference that is big enough to trigger a change
dr = abs (( ro [loc] - r)/255); // difference red max = 1
dg = abs (( go [loc] - g)/255); // " green
db = abs (( bo [loc] - b)/255); // " blue
dt = dr + dg + db; // sum diff red, green and blue max = 3
if (dt < 1 ) { color c = color (r,g,b); } // if diff is less then 1 then show the present pic in webcam.
else {color c = color(255,255,255);} // if diff more then 1 then show white pixels where changes are in the webcam. more then 33% diff
pixels[loc] = c ;
}
updatePixels ();
}}