background subtraction

asked 2016-03-04 00:05:02 -0500

GANESH PRASAATH L gravatar image

updated 2016-03-04 00:05:51 -0500

i have tried below example to subtract Image's background, its working well and updates position of the object but for the first time i mean when camera starts if i move an object from its initial position to some other position, its initial position Blob is not getting erased. Here's my code:

#include < iostream>
#include < opencv2\opencv.hpp>
#include < opencv2/core/core.hpp>
#include < opencv2/highgui/highgui.hpp>
#include < opencv2/video/background_segm.hpp>

using namespace cv;
using namespace std;

int main()
{
//global variables
Mat frame; //current frame
Mat resizeF;
Mat fgMaskMOG; //fg mask generated by MOG method
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
Mat fgMaskGMG; //fg mask fg mask generated by MOG2 method
Ptr< BackgroundSubtractor> pMOG; //MOG Background subtractor
Ptr< BackgroundSubtractor> pMOG2; //MOG2 Background subtractor
Ptr< BackgroundSubtractorGMG> pGMG; //MOG2 Background subtractor
pMOG = new BackgroundSubtractorMOG();
pMOG2 = new BackgroundSubtractorMOG2();
pGMG = new BackgroundSubtractorGMG();
char fileName[100] = "F:/Project/ShopAssistant2cor.mpg"; 
VideoCapture stream1(fileName);
Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(1,1) );

while (true) {
Mat cameraFrame;
if(!(stream1.read(frame))) 
break;

Mat resizeF=frame;
pMOG->operator()(resizeF, fgMaskMOG);
pMOG2->operator()(resizeF, fgMaskMOG2);
pGMG->operator()(resizeF, fgMaskGMG);

imshow("Origin", resizeF);
imshow("MOG", fgMaskMOG);
imshow("MOG2", fgMaskMOG2);
imshow("GMG", fgMaskGMG);
if (waitKey(30) >= 0)
break;
}
}
edit retag flag offensive close merge delete

Comments

1

Have you try this sample ?

LBerger gravatar imageLBerger ( 2016-03-04 02:35:09 -0500 )edit

thanks working on it

GANESH PRASAATH L gravatar imageGANESH PRASAATH L ( 2016-03-04 03:20:04 -0500 )edit