problem with setEventHandlerObject()
              in 
             Contributed Library Questions 
              •  
              1 year ago    
            
 
           
             Hi...
            
In my project the movie plays only for once when any movement is there. But again when I make a movement why the movie doesn't play? Should I use loop() method or missing something in movieEvent() ?
            
I am new to processing...
confused
            
            
Any Suggestions???
            
            
here is my code:
 
            
            
            
            
import codeanticode.gsvideo.*;
            
GSMovie movie;
GSCapture cam;
PImage prevFrame;
float threshold=50;
float avgMotion;
float totalMotion;
            
void setup() {
size(800, 600);
background(255);
            
movie = new GSMovie(this, "smoke.mov");
 
            
  
            
cam = new GSCapture(this, width, height);
cam.start();
            
//Reserve space for the previous image storage
prevFrame=createImage(cam.width, cam.height, RGB);
}
            
void movieEvent(GSMovie m) {
m.read();
 
            
            
}
void captureEvent(GSCapture c) {
c.read();
}
            
void draw() {
            
            
//check if there is a video feed available
image(cam, 0, 0);
            
if (cam.available())
{
prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height);
prevFrame.updatePixels();
            
cam.read();
}
            
loadPixels();
cam.loadPixels();
prevFrame.loadPixels();
            
float totalMotion=0;
            
for (int i=0;i<cam.pixels.length;i++) {
color current = cam.pixels[i];
color previous=prevFrame.pixels[i];
            
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);
totalMotion+=diff;
}
float avgMotion=totalMotion/cam.pixels.length;
  
            
            
if(avgMotion!=totalMotion){
if(avgMotion>threshold){
threshold--;
if(threshold==0){
movie.play();
}
movie.play();
}
            
movie.pause();
}
       
            
        
            
      
            
      
            
tint(255, 120);
image(movie,0,0);
            
}
            
            
            
            
            
 
           
 
            
           In my project the movie plays only for once when any movement is there. But again when I make a movement why the movie doesn't play? Should I use loop() method or missing something in movieEvent() ?
I am new to processing...
confused
            Any Suggestions???
here is my code:
import codeanticode.gsvideo.*;
GSMovie movie;
GSCapture cam;
PImage prevFrame;
float threshold=50;
float avgMotion;
float totalMotion;
void setup() {
size(800, 600);
background(255);
movie = new GSMovie(this, "smoke.mov");
cam = new GSCapture(this, width, height);
cam.start();
//Reserve space for the previous image storage
prevFrame=createImage(cam.width, cam.height, RGB);
}
void movieEvent(GSMovie m) {
m.read();
}
void captureEvent(GSCapture c) {
c.read();
}
void draw() {
//check if there is a video feed available
image(cam, 0, 0);
if (cam.available())
{
prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height);
prevFrame.updatePixels();
cam.read();
}
loadPixels();
cam.loadPixels();
prevFrame.loadPixels();
float totalMotion=0;
for (int i=0;i<cam.pixels.length;i++) {
color current = cam.pixels[i];
color previous=prevFrame.pixels[i];
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);
totalMotion+=diff;
}
float avgMotion=totalMotion/cam.pixels.length;
if(avgMotion!=totalMotion){
if(avgMotion>threshold){
threshold--;
if(threshold==0){
movie.play();
}
movie.play();
}
movie.pause();
}
tint(255, 120);
image(movie,0,0);
}
 
              
              1  
            
 
            