I am trying to apply MOG background subtraction to an acquired video, stored in .avi format. I have taken the link at here but have changed it.
Im using the CaptureVideo as:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <cvaux.h>
#include <opencv2/video/background_segm.hpp>
#include <stdio.h>
#include <opencv2/video/video.hpp>
using namespace cv;
using namespace std;
Mat frame; //current frame
Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
void processImages(char* firstFrameFilename);
void processVideo(string name);//(char* videoFilename);
string path = "C:\\Users\Suramrit Singh\Documents\Visual Studio 2010\Projects\opencvtest\opencvtest\walk2.avi"
int main()
{
namedWindow("Frame");
namedWindow("FG Mask MOG");
pMOG= new BackgroundSubtractorMOG(); //MOG approach
//processImages("asd1.jpg");--- cant work on single images
processVideo(path);//("tusharwalk2.avi");
destroyAllWindows();
return EXIT_SUCCESS;
}
void processVideo(string name){//(char* videoFilename) {
//create the capture object
VideoCapture capture(path);
printf("Sucess?%d",capture.isOpened());
for(int i=0;i<6000;i++)
{
capture >> frame;
capture.read(frame);
pMOG->operator()(frame, fgMaskMOG); // -----------------creatingproblem----------------------
IplImage* image2=cvCloneImage(&(IplImage)frame);
printf("%d", i);
imshow("FG Mask MOG", fgMaskMOG);
keyboard = waitKey(1);
}
//delete capture object
capture.release();
}
Now if I change it to default cam VideoCapture capture(0), it works, but does not do so with the .avi file path provided and gives the following runtime error:
"Unhandled exception at 0x000007fd7835811c in opencvtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0081eb60.."
Please, I'm a newcomer to image processing and any help will be highly appreciated as I've been stuck at this problem for a few days now and can't seem to figure it out.