//--------------------------------------------------------------
void ofApp::update(){
    
    // Grab the camera feed
    // and check for new frames
    
    grabber.update();
    if(grabber.isFrameNew()){
        
        // Get pixel data and
        // pre-process the image
        
        rgb.setFromPixels(grabber.getPixels(), grabber.getWidth(), grabber.getHeight());
        rgb.mirror(false, true);
        
        if(dilate) rgb.dilate();
        if(erode) rgb.erode();
        if(blur) rgb.blur(33);
        
        // Convert to grayscale
        
        grayscale = rgb;
        
        // Get difference
        
        difference.absDiff(background, grayscale);
        difference.threshold(threshold);
        
        // Find blobs - input, min_size, max_size, how many?, find holes?
        
        contour.findContours(difference, 1000, grabber.getWidth()*grabber.getHeight(), 1, false);
        
        
        // Background learning
        // Mix the grayscale image with background
        // to get a smoother transfer (trails)
        /*
        unsigned char *gray = grayscale.getPixels();
        unsigned char *bg = background.getPixels();
        for(int i=0; i<grabber.width*grabber.height; i++){
            
            bg[i] *= 0.9;
            bg[i] += gray[i]*0.1;
            
        }
        
        background = bg;
        */
        
    }
    
    updateFlock();

}
예제 #2
0
FlockWidget::FlockWidget(QWidget *parent) : QWidget(parent)
{
    flockTimer = new QTimer(this);
    connect(flockTimer,SIGNAL(timeout()), this, SLOT(updateFlock()));
    flockTimer->start(FRAME_TIME);

    attractionFactor = ATT_FACTOR_DEFAULT;
    distanceFactor = DIST_FACTOR_DEFAULT;
    speedFactor = SPEED_FACTOR_DEFAULT;
    jitterFactor = JITTER_DEFAULT;
    paranoiaFactor = PARANOIA_DEFAULT;
    aggressionFactor = AGG_DEFAULT;
}