Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The correct code should be as follow:

//You should include correct hpp file

include "opencv2/core/core.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/video/background_segm.hpp"

include "opencv2/imgproc/imgproc.hpp"

include "vector"

using namespace cv;

using namespace std;

int main(int argc, char *argv[])

{

Mat frame;

Mat copyframe; 

Mat back;

Mat fore;

VideoCapture cap;
//open video
cap.open("test.avi");

//Background Model
BackgroundSubtractorMOG2 bg;
vector<vector<Point> > contours;
namedWindow("Input");
namedWindow("Frame");
namedWindow("Foreground");
namedWindow("Background");
for(;;)
{
    //read frame
    if(!cap.read(frame))
    {
        return 0;
    }
    imshow("Input",frame);
    //get foreground
    bg(frame,fore,0.01);
    imshow("Foreground",fore);
    //get background
    bg.getBackgroundImage(back);
    //erode image
    erode(fore,fore,Mat());
    //dilate image
    dilate(fore,fore,Mat());
    //find contours
    findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
    //draw contours to frame
    drawContours(frame,contours,-1,Scalar(0,0,255),2);
    imshow("Frame",frame);
    imshow("Background",back);

    if(waitKey(33) >= 0)
    {
        break;
    }

}
cap.release();
return 0;

}

Hope can help you.

The correct code should be as follow:

//You should include correct hpp file

include "opencv2/core/core.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/video/background_segm.hpp"

include "opencv2/imgproc/imgproc.hpp"

include "vector"

file

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "vector"

using namespace cv;

cv; using namespace std;

std; int main(int argc, char *argv[])

{

*argv[])
{
Mat frame;
Mat copyframe;
Mat back;
Mat fore;
VideoCapture cap;
//open video
cap.open("test.avi");
//Background Model
BackgroundSubtractorMOG2 bg;
vector<vector<Point> > contours;
namedWindow("Input");
namedWindow("Frame");
namedWindow("Foreground");
namedWindow("Background");
for(;;)
{
//read frame
if(!cap.read(frame))
{
return 0;
}
imshow("Input",frame);
//get foreground
bg(frame,fore,0.01);
imshow("Foreground",fore);
//get background
bg.getBackgroundImage(back);
//erode image
erode(fore,fore,Mat());
//dilate image
dilate(fore,fore,Mat());
//find contours
findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
//draw contours to frame
drawContours(frame,contours,-1,Scalar(0,0,255),2);
imshow("Frame",frame);
imshow("Background",back);
if(waitKey(33) >= 0)
{
break;
}
}
cap.release();
return 0;
}

}

Hope can help you.

The correct code should be as follow:

//You should include correct hpp file

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "vector"

using namespace cv;
using namespace std;

int main(int argc, char *argv[])

{
  Mat frame;

Mat copyframe; 

 Mat back;
  Mat fore;
  VideoCapture cap;
 //open video
 cap.open("test.avi");

 //Background Model
 BackgroundSubtractorMOG2 bg;
 vector<vector<Point> > contours;
 namedWindow("Input");
 namedWindow("Frame");
 namedWindow("Foreground");
 namedWindow("Background");
 for(;;)
 {
     //read frame
     if(!cap.read(frame))
     {
         return 0;
     }
     imshow("Input",frame);
     //get foreground
     bg(frame,fore,0.01);
     imshow("Foreground",fore);
     //get background
     bg.getBackgroundImage(back);
     //erode image
     erode(fore,fore,Mat());
     //dilate image
     dilate(fore,fore,Mat());
     //find contours
     findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
     //draw contours to frame
     drawContours(frame,contours,-1,Scalar(0,0,255),2);
     imshow("Frame",frame);
     imshow("Background",back);

     if(waitKey(33) >= 0)
     {
         break;
     }

 }
 cap.release();
 return 0;
 }

Hope can help you.

The correct code should be as follow:

//You should include correct hpp file

file
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "vector"
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat frame;
Mat back;
Mat fore;
VideoCapture cap;
//open video
cap.open("test.avi");
//Background Model
BackgroundSubtractorMOG2 bg;
vector<vector<Point> > contours;
namedWindow("Input");
namedWindow("Frame");
namedWindow("Foreground");
namedWindow("Background");
for(;;)
{
//read frame
if(!cap.read(frame))
{
return 0;
}
imshow("Input",frame);
//get foreground
bg(frame,fore,0.01);
imshow("Foreground",fore);
//get background
bg.getBackgroundImage(back);
//erode image
erode(fore,fore,Mat());
//dilate image
dilate(fore,fore,Mat());
//find contours
findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
//draw contours to frame
drawContours(frame,contours,-1,Scalar(0,0,255),2);
imshow("Frame",frame);
imshow("Background",back);
if(waitKey(33) >= 0)
{
break;
}
}
cap.release();
return 0;
}

Hope can help you.