Ask Your Question
0

"Problem using cvAbsDiff" ver 2.4.2

asked 2013-02-21 00:33:49 -0600

updated 2013-02-21 00:40:42 -0600

I am new to OpenCV and facing seemingly very minute problem,Please help me out I get black picture as a result of difference of two frames(Even after I have significant delay between two frames to be differenced)

I am facing no problem with cvAbsDiffS,

Following is the code I have used :

int main(char argc, char* argv[])
{
    int count=0;
    CvCapture* cap;
    cap=cvCaptureFromCAM(0);
    cvNamedWindow("Original");
    cvNamedWindow("diff");
    cvNamedWindow("temp");

IplImage*  frame=cvQueryFrame(cap);
IplImage* gray_frame=cvCreateImage(cvGetSize(frame),8,1);
cvCvtColor(frame,gray_frame,CV_RGB2GRAY);
IplImage*  temp_frame=cvCreateImage(cvGetSize(frame),8,1);
temp_frame=gray_frame;
IplImage*  foreground=cvCreateImage(cvGetSize(frame),8,1);

while(1)
{
    frame=cvQueryFrame(cap);
    cvCvtColor(frame,gray_frame,CV_RGB2GRAY);   
    count++;
    printf("%d\n",count);
    if(count%12==0)
    {
        temp_frame=gray_frame;
    }
    if(count%17==0)
    {   
        cvShowImage("temp",temp_frame);
        cvAbsDiff(gray_frame,temp_frame,foreground);
        //cvThreshold(foreground,foreground,10,255,CV_THRESH_BINARY);
        //cvAbsDiffS(gray_frame,foreground,cvScalar(100));
        cvShowImage("diff",foreground);
    }
    cvShowImage("Original",gray_frame);

    if(cvWaitKey(33)==27)
    break;
}
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-02-21 03:18:01 -0600

temp_frame and gray_frame are pointing to the same memory (temp_frame=gray_frame). You have to copy memory instead.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-21 00:33:49 -0600

Seen: 704 times

Last updated: Feb 21 '13