refactored GMG algorithm

This commit is contained in:
Vladislav Vinogradov
2013-05-07 11:02:59 +04:00
parent b8f0d1a0e4
commit 697793090d
7 changed files with 248 additions and 200 deletions

View File

@@ -18,10 +18,10 @@ using namespace cv::gpu;
enum Method
{
FGD_STAT,
MOG,
MOG2,
GMG
GMG,
FGD_STAT
};
int main(int argc, const char** argv)
@@ -29,7 +29,7 @@ int main(int argc, const char** argv)
cv::CommandLineParser cmd(argc, argv,
"{ c camera | | use camera }"
"{ f file | 768x576.avi | input video file }"
"{ m method | mog | method (fgd, mog, mog2, gmg) }"
"{ m method | mog | method (mog, mog2, gmg, fgd) }"
"{ h help | | print help message }");
if (cmd.has("help") || !cmd.check())
@@ -43,18 +43,18 @@ int main(int argc, const char** argv)
string file = cmd.get<string>("file");
string method = cmd.get<string>("method");
if (method != "fgd"
&& method != "mog"
if (method != "mog"
&& method != "mog2"
&& method != "gmg")
&& method != "gmg"
&& method != "fgd")
{
cerr << "Incorrect method" << endl;
return -1;
}
Method m = method == "fgd" ? FGD_STAT :
method == "mog" ? MOG :
Method m = method == "mog" ? MOG :
method == "mog2" ? MOG2 :
method == "fgd" ? FGD_STAT :
GMG;
VideoCapture cap;
@@ -75,11 +75,10 @@ int main(int argc, const char** argv)
GpuMat d_frame(frame);
Ptr<BackgroundSubtractor> mog = gpu::createBackgroundSubtractorMOG();
Ptr<BackgroundSubtractor> mog2 = gpu::createBackgroundSubtractorMOG2();
Ptr<BackgroundSubtractor> gmg = gpu::createBackgroundSubtractorGMG(40);
FGDStatModel fgd_stat;
cv::Ptr<cv::BackgroundSubtractor> mog = cv::gpu::createBackgroundSubtractorMOG();
cv::Ptr<cv::BackgroundSubtractor> mog2 = cv::gpu::createBackgroundSubtractorMOG2();
GMG_GPU gmg;
gmg.numInitializationFrames = 40;
GpuMat d_fgmask;
GpuMat d_fgimg;
@@ -91,10 +90,6 @@ int main(int argc, const char** argv)
switch (m)
{
case FGD_STAT:
fgd_stat.create(d_frame);
break;
case MOG:
mog->apply(d_frame, d_fgmask, 0.01);
break;
@@ -104,7 +99,11 @@ int main(int argc, const char** argv)
break;
case GMG:
gmg.initialize(d_frame.size());
gmg->apply(d_frame, d_fgmask);
break;
case FGD_STAT:
fgd_stat.create(d_frame);
break;
}
@@ -128,12 +127,6 @@ int main(int argc, const char** argv)
//update the model
switch (m)
{
case FGD_STAT:
fgd_stat.update(d_frame);
d_fgmask = fgd_stat.foreground;
d_bgimg = fgd_stat.background;
break;
case MOG:
mog->apply(d_frame, d_fgmask, 0.01);
mog->getBackgroundImage(d_bgimg);
@@ -145,7 +138,13 @@ int main(int argc, const char** argv)
break;
case GMG:
gmg(d_frame, d_fgmask);
gmg->apply(d_frame, d_fgmask);
break;
case FGD_STAT:
fgd_stat.update(d_frame);
d_fgmask = fgd_stat.foreground;
d_bgimg = fgd_stat.background;
break;
}