1 | initial version |
The correct code should be as follow:
//You should include correct hpp file
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.
2 | No.2 Revision |
The correct code should be as follow:
#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 {
}
Hope can help you.
3 | No.3 Revision |
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.
4 | No.4 Revision |
The correct code should be as follow:
//You should include correct hpp
Hope can help you.