Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Using BackgroundSubtractorMOG2 for images

$
0
0
Hi, I am pretty new to OpenCV and I am stuck at the moment. Since I will have same background in my project, I thought it would be easier to work, if I could remove my background. But first, I have to ask one thing. Can I use BackgroundSubtractorMOG2 for images? Because it is under video analysis/motion analysis title. I read the documentation on opencv.org and looked through countless examples/tutorials but I am still having difficulty understanding how MOG2 works. Quick question: What is *history* that in parameters? So, I have written a simple code. I get a foreground mask. So, what is next step? How can I remove the background and left with my object only? Shouldn't I load my background first, then the actual image, so that MOG2 could do the background subtraction? I am using OpenCV 2.4.11. Thanks in advance. Code: #include #include #include using namespace cv; using namespace std; //global variables int history = 1; float varThreshold = 16; bool bShadowDetection = true; Mat src; //source image Mat fgMaskMOG2; //fg mask generated by MOG2 method Ptr pMOG2; //MOG2 Background subtractor int main(int argc, char* argv[]) { //create GUI windows namedWindow("Source"); namedWindow("FG Mask MOG 2"); src = imread("bluePaper1.png", 1); //create Background Subtractor objects pMOG2 = new BackgroundSubtractorMOG2(history, varThreshold, bShadowDetection); //MOG2 approach pMOG2->setInt("nmixtures", 3); pMOG2->setDouble("fTau", 0.5); pMOG2->operator()(src, fgMaskMOG2); imshow("Source", src); imshow("FG Mask MOG 2", fgMaskMOG2); waitKey(0); return 0; } Source image: ![bluePaper1.png](/upfiles/14367102614818102.png) fgMask that I get from MOG2: ![fgMask.png](/upfiles/1436710576371171.png)

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>