Ask Your Question

Revision history [back]

background subtraction

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. i have attached image for your reference, what am i missing to clear that Initial Position of Original object. 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;
}
}

background subtraction

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. i have attached image for your reference, what am i missing to clear that Initial Position of Original object. 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;
}
}