Exemple #1
0
//--------------------------------------------------------------
void testApp::update(){
    
    vidGrabber.grabFrame();
    
    if(vidGrabber.isFrameNew()){
        pastImg = grayImg;
        
        cameraImg.setFromPixels(vidGrabber.getPixels(), cw, ch);
        grayImg.setFromColorImage(cameraImg);
        
        grayImg.threshold(100);
        grayImg.blurHeavily();
        
        /*
        grayImg.dilate_3x3();
        grayImg.threshold(230);
        grayImg.blurHeavily();
        */
        
        // printf("%p %p\n", pastImg.getCvImage(), grayImg.getCvImage());
        cvCalcOpticalFlowBM(pastImg.getCvImage(), grayImg.getCvImage(), 
            block, shift, max_range, 0, velx, vely);
    }
    
}
void ofCvOpticalFlowBM::calc( ofxCvGrayscaleImage & pastImage,
                              ofxCvGrayscaleImage & currentImage,
                              int size
                            )
{

    cvCalcOpticalFlowBM(pastImage.getCvImage(), currentImage.getCvImage(),
                        block, shift, max_range, 0, vel_x, vel_y);
}
void ofxOpticalFlowBM :: update( unsigned char* pixels, int w, int h, int imageType ) {
  if( w == scalSize.width && h == scalSize.height ) {
    colrImgSml.setFromPixels( pixels, w, h );
    greyImgSml.setFromColorImage( colrImgSml );
    
    
    cvCalcOpticalFlowBM( greyImgPrv.getCvImage(), //Previous image (CvArr *)
                        greyImgSml.getCvImage(), //Current image (CvArr *)
                        blockSize,    //Block size (CvSize)
                        shiftSize,    //Shift size (CvSize)
                        maxRange,     //Max range (CvSize)
                        0,            //Use previous velocity as starting point if not zero (int)
                        opFlowVelX,   //X Velocity (CvArr) 
                        opFlowVelY    //Y Velocity (CvArr) 
                        );
    
    greyImgPrv = greyImgSml;
  }
}