need help for background extraction

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

need help for background extraction

umeshnarayanan
i am new to openCv

need some bit of opencv code for

background extraction

(simple averaging (moving average window) of pixels to get the background)

but i have some other type of background extraction code(C++ code)
but its bit difficult to understand

#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include <stdio.h>

//this is a sample for foreground detection functions


int main(int argc, char** argv)
{
       
       
IplImage* tmp_frame = NULL;
IplImage* sourse = NULL;
CvCapture* capt = NULL;

      CvFont font; //initialize the font
      cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,1.0, 1.0, 0, 1, CV_AA);
      CvPoint pt1 = cvPoint(20,190);

//if( argc < 2 )
//{
// printf("please specify video file name \n");
// exit(0);
// }

//cap = cvCaptureFromFile(argv[1]);

capt = cvCaptureFromFile("yellow.avi"); // capture frme form file
tmp_frame = cvQueryFrame(capt);
sourse = cvQueryFrame(capt);

if(!tmp_frame)
        {
                printf("bad video \n");
                exit(0);
        }

cvNamedWindow("Sourse", 1);
cvNamedWindow("BackGround", 1);
cvMoveWindow("BackGround",350, 0);
cvNamedWindow("ForeGround", 1);
cvMoveWindow("ForeGround", 750, 0);

// this portion is bit complcated ,need more understanding

//create BG model
CvBGStatModel* bg_model;

bg_model =cvCreateGaussianBGModel( tmp_frame );

for( int fr = 1;tmp_frame; tmp_frame = cvQueryFrame(capt), fr++ )
{

double t = (double)cvGetTickCount();

cvUpdateBGStatModel( tmp_frame, bg_model );

t = (double)cvGetTickCount() - t;


printf( "%.1f\n", t/(cvGetTickFrequency()*1000.) );


cvPutText(sourse,"sourse Video", pt1, &font,CV_RGB(255, 255, 255));
cvShowImage("Sourse",sourse );

cvPutText(bg_model->background,"Background", pt1, &font,CV_RGB(255,
255, 255));

cvShowImage("BackGround", bg_model->background);

cvPutText(bg_model->foreground,"ForeGround", pt1, &font,CV_RGB(255,
255, 255));  

cvShowImage("ForeGround", bg_model->foreground);

//int k = cvWaitKey(20);

cvWaitKey(20);

//if( k == 27 ) break;
//printf("frame# %d \r", fr);
}

cvReleaseBGStatModel(&bg_model);
cvReleaseCapture(&capt);

return 0;
}


please help me...............