"Problem using cvAbsDiff" ver 2.4.2
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;
}
}
add a comment