Sunday, November 30, 2008

Calculate activity level base on differenceImage() in JMyron

The code below use the function differenceImage in JMyron to calculate activity level.
(Skeleton based on Rijk's contriubution)



import JMyron.*;

JMyron m;//a camera object

int numPixels;


void setup(){
size(320,240);
m = new JMyron();//make a new instance of the object
m.start(width,height);//start a capture at 320x240

// m.findGlobs(0);//disable the intelligence to speed up frame rate
println("Myron " + m.version());
numPixels = width * height;
// Create an array to store the previously captured frame
previousFrame = new int[numPixels];
currentFrame=new int[numPixels];
// m.adaptivity(0.5);
}


void draw(){
//count of non-black image (base on the differenceImage array)
int nonBlackCount=0;
m.update();//update the camera view
loadPixels();
int[] diffFrame = m.differenceImage(); //get the current image of the camera
for (int i=0; i<diffFrame.length; i++){
pixels[i]=diffFrame[i];
if((red(diffFrame[i])!=0)&&(green(diffFrame[i])!=0)&&(blue(diffFrame[i]))!=0){
nonBlackCount++;
}
}
}


void mousePressed(){
}

public void stop(){
m.stop();//stop the object
super.stop();
}


No comments: