1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #1151 from jet47:gpubgsegm-refactoring

This commit is contained in:
Andrey Pavlenko
2013-08-05 10:19:59 +04:00
committed by OpenCV Buildbot
19 changed files with 1700 additions and 1769 deletions
+29 -31
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);
FGDStatModel fgd_stat;
MOG_GPU mog;
MOG2_GPU mog2;
GMG_GPU gmg;
gmg.numInitializationFrames = 40;
Ptr<BackgroundSubtractor> mog = gpu::createBackgroundSubtractorMOG();
Ptr<BackgroundSubtractor> mog2 = gpu::createBackgroundSubtractorMOG2();
Ptr<BackgroundSubtractor> gmg = gpu::createBackgroundSubtractorGMG(40);
Ptr<BackgroundSubtractor> fgd = gpu::createBackgroundSubtractorFGD();
GpuMat d_fgmask;
GpuMat d_fgimg;
@@ -91,20 +90,20 @@ int main(int argc, const char** argv)
switch (m)
{
case FGD_STAT:
fgd_stat.create(d_frame);
break;
case MOG:
mog(d_frame, d_fgmask, 0.01f);
mog->apply(d_frame, d_fgmask, 0.01);
break;
case MOG2:
mog2(d_frame, d_fgmask);
mog2->apply(d_frame, d_fgmask);
break;
case GMG:
gmg.initialize(d_frame.size());
gmg->apply(d_frame, d_fgmask);
break;
case FGD_STAT:
fgd->apply(d_frame, d_fgmask);
break;
}
@@ -128,24 +127,23 @@ 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(d_frame, d_fgmask, 0.01f);
mog.getBackgroundImage(d_bgimg);
mog->apply(d_frame, d_fgmask, 0.01);
mog->getBackgroundImage(d_bgimg);
break;
case MOG2:
mog2(d_frame, d_fgmask);
mog2.getBackgroundImage(d_bgimg);
mog2->apply(d_frame, d_fgmask);
mog2->getBackgroundImage(d_bgimg);
break;
case GMG:
gmg(d_frame, d_fgmask);
gmg->apply(d_frame, d_fgmask);
break;
case FGD_STAT:
fgd->apply(d_frame, d_fgmask);
fgd->getBackgroundImage(d_bgimg);
break;
}
+16 -14
View File
@@ -1271,14 +1271,14 @@ TEST(FGDStatModel)
{
const std::string inputFile = abspath("768x576.avi");
cv::VideoCapture cap(inputFile);
VideoCapture cap(inputFile);
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
cv::Mat frame;
Mat frame;
cap >> frame;
IplImage ipl_frame = frame;
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
while (!TestSystem::instance().stop())
{
@@ -1297,8 +1297,10 @@ TEST(FGDStatModel)
cap >> frame;
cv::gpu::GpuMat d_frame(frame);
cv::gpu::FGDStatModel d_model(d_frame);
gpu::GpuMat d_frame(frame), d_fgmask;
Ptr<BackgroundSubtractor> d_fgd = gpu::createBackgroundSubtractorFGD();
d_fgd->apply(d_frame, d_fgmask);
while (!TestSystem::instance().stop())
{
@@ -1307,7 +1309,7 @@ TEST(FGDStatModel)
TestSystem::instance().gpuOn();
d_model.update(d_frame);
d_fgd->apply(d_frame, d_fgmask);
TestSystem::instance().gpuOff();
}
@@ -1346,10 +1348,10 @@ TEST(MOG)
cap >> frame;
cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG_GPU d_mog;
cv::Ptr<cv::BackgroundSubtractor> d_mog = cv::gpu::createBackgroundSubtractorMOG();
cv::gpu::GpuMat d_foreground;
d_mog(d_frame, d_foreground, 0.01f);
d_mog->apply(d_frame, d_foreground, 0.01);
while (!TestSystem::instance().stop())
{
@@ -1358,7 +1360,7 @@ TEST(MOG)
TestSystem::instance().gpuOn();
d_mog(d_frame, d_foreground, 0.01f);
d_mog->apply(d_frame, d_foreground, 0.01);
TestSystem::instance().gpuOff();
}
@@ -1399,13 +1401,13 @@ TEST(MOG2)
cap >> frame;
cv::Ptr<cv::BackgroundSubtractor> d_mog2 = cv::gpu::createBackgroundSubtractorMOG2();
cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat d_foreground;
cv::gpu::GpuMat d_background;
d_mog2(d_frame, d_foreground);
d_mog2.getBackgroundImage(d_background);
d_mog2->apply(d_frame, d_foreground);
d_mog2->getBackgroundImage(d_background);
while (!TestSystem::instance().stop())
{
@@ -1414,8 +1416,8 @@ TEST(MOG2)
TestSystem::instance().gpuOn();
d_mog2(d_frame, d_foreground);
d_mog2.getBackgroundImage(d_background);
d_mog2->apply(d_frame, d_foreground);
d_mog2->getBackgroundImage(d_background);
TestSystem::instance().gpuOff();
}