Error reading video using VideoCapture while applying MOG
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.
what do you want with that IplImage there ? throw it out ! (use frame.clone() if that's what you wanted)
also your path contains single backslashes. always a bad idea. replace them with either a '/' or with '\\'
Sorry about that, it was for something I was trying earlier! Ive tried both using '/' and a '\', still get the same error.
you want either
capture >> frame;
or
capture.read(frame);
not both. also, if the video is finished, you get empty frames from the capture, so throw in a :
and again, please kill that line with the useless(and wrong) IplImage
Yes, it seems I am getting empty frames from the capture even in the first iteration. Why would this be happening? Already removed the useless line
Also, I seem to be getting: Bad flag (Unrecognized or unsupported array type)
another way telling you it's empty/invalid (that's probably from imshow())