4 #include "opencv2/core.hpp"
5 #include "opencv2/core/utility.hpp"
6 #include "opencv2/ocl.hpp"
7 #include "opencv2/highgui.hpp"
11 using namespace cv::ocl;
16 int main(int argc, const char** argv)
19 cv::CommandLineParser cmd(argc, argv,
20 "{ c camera | false | use camera }"
21 "{ f file | 768x576.avi | input video file }"
22 "{ m method | mog | method (mog, mog2) }"
23 "{ h help | false | print help message }");
25 if (cmd.get<bool>("help"))
27 cout << "Usage : bgfg_segm [options]" << endl;
28 cout << "Available options:" << endl;
33 bool useCamera = cmd.get<bool>("camera");
34 string file = cmd.get<string>("file");
35 string method = cmd.get<string>("method");
37 if (method != "mog" && method != "mog2")
39 cerr << "Incorrect method" << endl;
43 int m = method == "mog" ? M_MOG : M_MOG2;
54 cerr << "can not open camera or video file" << endl;
61 oclMat d_frame(frame);
70 d_fgimg.create(d_frame.size(), d_frame.type());
79 mog(d_frame, d_fgmask, 0.01f);
83 mog2(d_frame, d_fgmask);
92 d_frame.upload(frame);
94 int64 start = cv::getTickCount();
100 mog(d_frame, d_fgmask, 0.01f);
101 mog.getBackgroundImage(d_bgimg);
105 mog2(d_frame, d_fgmask);
106 mog2.getBackgroundImage(d_bgimg);
110 double fps = cv::getTickFrequency() / (cv::getTickCount() - start);
111 std::cout << "FPS : " << fps << std::endl;
113 d_fgimg.setTo(Scalar::all(0));
114 d_frame.copyTo(d_fgimg, d_fgmask);
116 d_fgmask.download(fgmask);
117 d_fgimg.download(fgimg);
118 if (!d_bgimg.empty())
119 d_bgimg.download(bgimg);
121 imshow("image", frame);
122 imshow("foreground mask", fgmask);
123 imshow("foreground image", fgimg);
125 imshow("mean background image", bgimg);
127 int key = waitKey(30);