Quantcast

Frame Differencing Problem

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

Frame Differencing Problem

Bar **[]**
Okay, I am doing Frame Differencing for static background subtraction for a multitouch system but I am having difficulties running this code


Basically I am planning to take a static background model (As you see in the if statement) and convert it to grayscale (graybackground) and then subtract that from every frame that i get from camera (grayforeground which is the grayscale of each frame i get from camera). Is this the right method? since the background is static i thought frame differencing would be the best and easiest option to go for


My code make the graybackground well, but after that the program gives me error which i cant fiqure out what it is for few days and Im having a nightmare. I would really appreciate if someone run my code and see what is the problem, cuz i just can't figure out

/////////////////////////////////////////////////////////////////////
#include "stdafx.h" // I have all my opencv library here

int main(int argc, char* argv[])
{
        IplImage* frame;
        IplImage* background=NULL;
        IplImage* graybackground;
        IplImage* foreground=NULL;
        IplImage* grayforeground;
        CvCapture* capture=NULL;
        int height;
        int width;

        cvNamedWindow("Background",1);
        cvNamedWindow("Foreground",1);


        capture = cvCreateCameraCapture(0);
   

  if(!background)
        {
                for(int i=0;i<50;i++){
                frame=cvQueryFrame(capture);
                }

        background=cvCloneImage(frame);
        width  = background->width;
        height  = background->height;
        graybackground=cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );
        cvCvtColor(background,graybackground,CV_BGR2GRAY);
        cvShowImage("Background",graybackground);
        }
        cvWaitKey(5000);

for(;;)
{
        foreground=cvQueryFrame(capture);
        if(!foreground) break;
        if(!grayforeground)
        {
                width  = foreground->width;
                height  = foreground->height;
                grayforeground=cvCreateImage( cvSize( width, height ), IPL_DEPTH_32F, 1 );
        }

        cvCvtColor(foreground,grayforeground,CV_BGR2GRAY);
        cvShowImage("Foreground",grayforeground);


}
}
////////////////////////////////////////////////////////////////////

Loading...