I am using following code for background subtraction. I am giving it path of video, video runs successfully but at the end it gives Debug Assertion Failed error.
I am using following code in Microsoft Visual Studio to solve a problem of Computer Vision with opencv.
#include<opencv2/opencv.hpp>
#include<iostream>
#include<string>
#include<vector>
#include "opencv2/video/background_segm.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat frame;
Mat back;
Mat fore;
VideoCapture cap;
cap.open("H:/competition.avi");
BackgroundSubtractorMOG2 bg(100,16,true);
bg.set("nmixtures",3);
vector<vector<Point> > contours;
namedWindow("Frame");
namedWindow("Background");
for(;;)
{
cap >> frame;
if(!frame.empty())
{
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
erode(fore,fore,Mat());
dilate(fore,fore,Mat());
findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
drawContours(frame,contours,-1,Scalar(0,0,255),2);
imshow("Frame",frame);
imshow("Background",back);
if(waitKey(30) >= 0) break;
}
else
break;
}
return 0;
}