We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Creating pixelBlobs (Read 583 times)
Creating pixelBlobs
Mar 28th, 2009, 4:38pm
 
 So I'm pursuing a project that requires 2 video cameras as 2 seperate inputs.  Which I am aiming to do through processing only, no JMyron, etc.. as there are more complications with using 2 webcams.
 
 I'm trying to create my own pixelblobs, using code from Daniel Shiffmans Learning Processing book, and adding to it.

 I want to tell the program, to find the 1st pixel that is black and the last pixel that is black and draw a gray square about 5 x 5 pixels at each of these constantly refreshing locations.  

 I then wish to have it constantly find the average of these 2 locations and draw a small red square there.  This position will be used as the
'motion' cursor for other parts of my project.  

 My problem, is that I don't know how to tell it to read through the black pixels, and stop at the 1st one - so I can then have it draw a square here..   I'm having trouble thinking up an algorithm for it..  

 Here is the code for the basic 'simple motion detection'..  without the addition of what I need..  

 any ideas would be much appreciated - THX A BUNCH Wink

here is the code:

import processing.video.*;

Capture video;
//previous frame
PImage prevFrame;
//how different must a pixel be to be a motion pixel
float threshold = 100;

void setup(){
 size(320,240);
 video = new Capture(this,width,height,30);
 //Create an empty image with the same size video aperture
 prevFrame = createImage(video.width,video.height,30);//30 !? does what
}

Re: Creating pixelBlobs
Reply #1 - Mar 28th, 2009, 4:42pm
 
here is the other part of the code as I couldn't post in all in the same window

void test(){
   if(video.available()){
   //save previous frame for motion detection
   prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height);

   prevFrame.updatePixels();//this line and the line above are where the magic
   // happened for prevFrame, where it wen't from a PImage to taking on the pixels
   // from the video read ( copy ).
   video.read();
 }
 
 loadPixels();
 video.loadPixels();
 prevFrame.loadPixels();
 
 //loop through pixels
 for(int x = 0; x < video.width; x++){
   for(int y = 0; y < video.height; y++){
     int loc = x + y*video.width; // Step 1 what is the 1D pixel location
     color current = video.pixels[loc]; // Step 2 what is the current color
     color previous = prevFrame.pixels[loc]; // Step 3 what is the previous color
     // Step 4 - Compare colors :     Previous VS. Current
    float r1 = red(current);  float g1 = green(current);  float b1 = blue(current);
    float r2 = red(previous);  float g2 = green(previous);  float b2 = blue(previous);
   
    float diff = dist(r1,g1,b1,r2,g2,b2);
    //Step 5 How different are the colors
    if (diff > threshold){
    pixels[loc] = color(0);
   } else {
    pixels[loc] = color(255);
   }
 }
}
updatePixels();
}
Page Index Toggle Pages: 1