#include "opencv/cvaux.h"
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "ctype.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
CvCapture* capture = 0;
capture = cvCaptureFromAVI( "pool.avi" );
if( !capture )
{
fprintf(stderr,"Could not initialize...\n");
return -1;
}
IplImage* videoFrame = NULL;
videoFrame = cvQueryFrame(capture);
if(!videoFrame)
{
printf("Bad frame \n");
exit(0);
}
cvNamedWindow("BG", 1);
cvNamedWindow("FG", 1);
CvFGDStatModelParams* params = new CvFGDStatModelParams;
params->Lcc=64;
params->N1cc=25;
params->N2cc=40;
params->is_obj_without_holes=TRUE;
params->perform_morphing=1;
params->alpha1=0.1;
params->alpha2=0.005;
params->alpha3=0.1;
params->delta=2;
params->T=0.9;
params->minArea=15;
CvBGStatModel* bgModel = cvCreateFGDStatModel(videoFrame ,params);
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 25;
int frameW = 640;
int frameH = 480;
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),
fps,cvSize(frameW,frameH),isColor);
int key=-1;
while(key != 'q')
{
videoFrame = cvQueryFrame(capture);
if( !videoFrame )
{
break;}
cvUpdateBGStatModel(videoFrame,bgModel);
cvShowImage("BG", bgModel->background);
cvShowImage("FG", bgModel->foreground);
cvWriteFrame(writer,bgModel->foreground);
key = cvWaitKey(10);
}
cvDestroyWindow("BG");
cvDestroyWindow("FG");
cvWaitKey(0);
cvReleaseBGStatModel( &bgModel );
cvReleaseCapture(&capture);
cvReleaseVideoWriter(&writer);
return 0;
}
I am using opencv2.3.1 and visual studio 2010
I am trying to implement the FGD algorithm for background subtraction / foreground highlighting.
I have already successfully implemented the MOG algorithm. Then I just change the function and parameter from MOG to FGD.
The project was successfully compiled in the visual studio, but in the function: cvShowImage ("BG", bgModel-> background); it gives the following error:
Unhandled exception at 0x000007feef085d09 in hello_opencv_231.exe: 0xC0000005: location of access violation record 0xfffffffcc40b40e0.
I don’t know what it is ... any ideas?
Thank you for your help!
source
share