Commit 487ff4f3 authored by Andrey Pavlenko's avatar Andrey Pavlenko Committed by OpenCV Buildbot

Merge pull request #1151 from jet47:gpubgsegm-refactoring

parents 4ed9b1ca 77373751
...@@ -6,4 +6,4 @@ set(the_description "GPU-accelerated Background Segmentation") ...@@ -6,4 +6,4 @@ set(the_description "GPU-accelerated Background Segmentation")
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations) ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
ocv_define_module(gpubgsegm opencv_video opencv_imgproc opencv_legacy opencv_gpuarithm opencv_gpufilters opencv_gpuimgproc) ocv_define_module(gpubgsegm opencv_video OPTIONAL opencv_legacy opencv_imgproc opencv_gpuarithm opencv_gpufilters opencv_gpuimgproc)
...@@ -41,7 +41,14 @@ ...@@ -41,7 +41,14 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#include "opencv2/legacy.hpp"
#ifdef HAVE_OPENCV_LEGACY
# include "opencv2/legacy.hpp"
#endif
#ifdef HAVE_OPENCV_GPUIMGPROC
# include "opencv2/gpuimgproc.hpp"
#endif
using namespace std; using namespace std;
using namespace testing; using namespace testing;
...@@ -59,6 +66,13 @@ using namespace perf; ...@@ -59,6 +66,13 @@ using namespace perf;
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
#endif #endif
//////////////////////////////////////////////////////
// FGDStatModel
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
#ifdef HAVE_OPENCV_LEGACY
namespace cv namespace cv
{ {
template<> void Ptr<CvBGStatModel>::delete_obj() template<> void Ptr<CvBGStatModel>::delete_obj()
...@@ -67,10 +81,7 @@ namespace cv ...@@ -67,10 +81,7 @@ namespace cv
} }
} }
////////////////////////////////////////////////////// #endif
// FGDStatModel
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
DEF_PARAM_TEST_1(Video, string); DEF_PARAM_TEST_1(Video, string);
...@@ -90,10 +101,10 @@ PERF_TEST_P(Video, FGDStatModel, ...@@ -90,10 +101,10 @@ PERF_TEST_P(Video, FGDStatModel,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame), foreground;
cv::gpu::FGDStatModel d_model(4); cv::Ptr<cv::gpu::BackgroundSubtractorFGD> d_fgd = cv::gpu::createBackgroundSubtractorFGD();
d_model.create(d_frame); d_fgd->apply(d_frame, foreground);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
...@@ -103,18 +114,22 @@ PERF_TEST_P(Video, FGDStatModel, ...@@ -103,18 +114,22 @@ PERF_TEST_P(Video, FGDStatModel,
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
d_model.update(d_frame); d_fgd->apply(d_frame, foreground);
stopTimer(); stopTimer();
} }
const cv::gpu::GpuMat background = d_model.background; GPU_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE);
const cv::gpu::GpuMat foreground = d_model.foreground;
#ifdef HAVE_OPENCV_GPUIMGPROC
cv::gpu::GpuMat background3, background;
d_fgd->getBackgroundImage(background3);
cv::gpu::cvtColor(background3, background, cv::COLOR_BGR2BGRA);
GPU_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE); GPU_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE);
GPU_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE); #endif
} }
else else
{ {
#ifdef HAVE_OPENCV_LEGACY
IplImage ipl_frame = frame; IplImage ipl_frame = frame;
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame)); cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
...@@ -135,6 +150,9 @@ PERF_TEST_P(Video, FGDStatModel, ...@@ -135,6 +150,9 @@ PERF_TEST_P(Video, FGDStatModel,
CPU_SANITY_CHECK(background); CPU_SANITY_CHECK(background);
CPU_SANITY_CHECK(foreground); CPU_SANITY_CHECK(foreground);
#else
FAIL_NO_CPU();
#endif
} }
} }
...@@ -176,11 +194,12 @@ PERF_TEST_P(Video_Cn_LearningRate, MOG, ...@@ -176,11 +194,12 @@ PERF_TEST_P(Video_Cn_LearningRate, MOG,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
cv::Ptr<cv::BackgroundSubtractor> d_mog = cv::gpu::createBackgroundSubtractorMOG();
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG_GPU d_mog;
cv::gpu::GpuMat foreground; cv::gpu::GpuMat foreground;
d_mog(d_frame, foreground, learningRate); d_mog->apply(d_frame, foreground, learningRate);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
...@@ -200,7 +219,7 @@ PERF_TEST_P(Video_Cn_LearningRate, MOG, ...@@ -200,7 +219,7 @@ PERF_TEST_P(Video_Cn_LearningRate, MOG,
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
d_mog(d_frame, foreground, learningRate); d_mog->apply(d_frame, foreground, learningRate);
stopTimer(); stopTimer();
} }
...@@ -273,13 +292,13 @@ PERF_TEST_P(Video_Cn, MOG2, ...@@ -273,13 +292,13 @@ PERF_TEST_P(Video_Cn, MOG2,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
cv::gpu::MOG2_GPU d_mog2; cv::Ptr<cv::BackgroundSubtractorMOG2> d_mog2 = cv::gpu::createBackgroundSubtractorMOG2();
d_mog2.bShadowDetection = false; d_mog2->setDetectShadows(false);
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::GpuMat foreground; cv::gpu::GpuMat foreground;
d_mog2(d_frame, foreground); d_mog2->apply(d_frame, foreground);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
...@@ -299,7 +318,7 @@ PERF_TEST_P(Video_Cn, MOG2, ...@@ -299,7 +318,7 @@ PERF_TEST_P(Video_Cn, MOG2,
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
d_mog2(d_frame, foreground); d_mog2->apply(d_frame, foreground);
stopTimer(); stopTimer();
} }
...@@ -307,8 +326,8 @@ PERF_TEST_P(Video_Cn, MOG2, ...@@ -307,8 +326,8 @@ PERF_TEST_P(Video_Cn, MOG2,
} }
else else
{ {
cv::Ptr<cv::BackgroundSubtractor> mog2 = cv::createBackgroundSubtractorMOG2(); cv::Ptr<cv::BackgroundSubtractorMOG2> mog2 = cv::createBackgroundSubtractorMOG2();
mog2->set("detectShadows", false); mog2->setDetectShadows(false);
cv::Mat foreground; cv::Mat foreground;
...@@ -359,8 +378,9 @@ PERF_TEST_P(Video_Cn, MOG2GetBackgroundImage, ...@@ -359,8 +378,9 @@ PERF_TEST_P(Video_Cn, MOG2GetBackgroundImage,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
cv::Ptr<cv::BackgroundSubtractor> d_mog2 = cv::gpu::createBackgroundSubtractorMOG2();
cv::gpu::GpuMat d_frame; cv::gpu::GpuMat d_frame;
cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat d_foreground; cv::gpu::GpuMat d_foreground;
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
...@@ -380,12 +400,12 @@ PERF_TEST_P(Video_Cn, MOG2GetBackgroundImage, ...@@ -380,12 +400,12 @@ PERF_TEST_P(Video_Cn, MOG2GetBackgroundImage,
d_frame.upload(frame); d_frame.upload(frame);
d_mog2(d_frame, d_foreground); d_mog2->apply(d_frame, d_foreground);
} }
cv::gpu::GpuMat background; cv::gpu::GpuMat background;
TEST_CYCLE() d_mog2.getBackgroundImage(background); TEST_CYCLE() d_mog2->getBackgroundImage(background);
GPU_SANITY_CHECK(background, 1); GPU_SANITY_CHECK(background, 1);
} }
...@@ -460,10 +480,10 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG, ...@@ -460,10 +480,10 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG,
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::GpuMat foreground; cv::gpu::GpuMat foreground;
cv::gpu::GMG_GPU d_gmg; cv::Ptr<cv::BackgroundSubtractorGMG> d_gmg = cv::gpu::createBackgroundSubtractorGMG();
d_gmg.maxFeatures = maxFeatures; d_gmg->setMaxFeatures(maxFeatures);
d_gmg(d_frame, foreground); d_gmg->apply(d_frame, foreground);
for (int i = 0; i < 150; ++i) for (int i = 0; i < 150; ++i)
{ {
...@@ -488,7 +508,7 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG, ...@@ -488,7 +508,7 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG,
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
d_gmg(d_frame, foreground); d_gmg->apply(d_frame, foreground);
stopTimer(); stopTimer();
} }
...@@ -499,9 +519,8 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG, ...@@ -499,9 +519,8 @@ PERF_TEST_P(Video_Cn_MaxFeatures, GMG,
cv::Mat foreground; cv::Mat foreground;
cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0));
cv::Ptr<cv::BackgroundSubtractor> gmg = cv::createBackgroundSubtractorGMG(); cv::Ptr<cv::BackgroundSubtractorGMG> gmg = cv::createBackgroundSubtractorGMG();
gmg->set("maxFeatures", maxFeatures); gmg->setMaxFeatures(maxFeatures);
//gmg.initialize(frame.size(), 0.0, 255.0);
gmg->apply(frame, foreground); gmg->apply(frame, foreground);
......
...@@ -57,6 +57,8 @@ ...@@ -57,6 +57,8 @@
#include "opencv2/gpubgsegm.hpp" #include "opencv2/gpubgsegm.hpp"
#include "opencv2/video.hpp" #include "opencv2/video.hpp"
#include "opencv2/opencv_modules.hpp"
#ifdef GTEST_CREATE_SHARED_LIBRARY #ifdef GTEST_CREATE_SHARED_LIBRARY
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
#endif #endif
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
using namespace cv::gpu; using namespace cv::gpu;
using namespace cv::gpu::cudev; using namespace cv::gpu::cudev;
namespace bgfg namespace fgd
{ {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// calcDiffHistogram // calcDiffHistogram
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include "opencv2/core/gpu_types.hpp" #include "opencv2/core/gpu_types.hpp"
namespace bgfg namespace fgd
{ {
struct BGPixelStat struct BGPixelStat
{ {
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
#include "opencv2/core/cuda/limits.hpp" #include "opencv2/core/cuda/limits.hpp"
namespace cv { namespace gpu { namespace cudev { namespace cv { namespace gpu { namespace cudev {
namespace bgfg_gmg namespace gmg
{ {
__constant__ int c_width; __constant__ int c_width;
__constant__ int c_height; __constant__ int c_height;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -46,10 +46,21 @@ ...@@ -46,10 +46,21 @@
#include <limits> #include <limits>
#include "opencv2/gpubgsegm.hpp" #include "opencv2/gpubgsegm.hpp"
#include "opencv2/gpuarithm.hpp"
#include "opencv2/gpufilters.hpp"
#include "opencv2/gpuimgproc.hpp"
#include "opencv2/core/private.gpu.hpp" #include "opencv2/core/private.gpu.hpp"
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_GPUARITHM
# include "opencv2/gpuarithm.hpp"
#endif
#ifdef HAVE_OPENCV_GPUFILTERS
# include "opencv2/gpufilters.hpp"
#endif
#ifdef HAVE_OPENCV_GPUIMGPROC
# include "opencv2/gpuimgproc.hpp"
#endif
#endif /* __OPENCV_PRECOMP_H__ */ #endif /* __OPENCV_PRECOMP_H__ */
...@@ -41,7 +41,10 @@ ...@@ -41,7 +41,10 @@
//M*/ //M*/
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/legacy.hpp"
#ifdef HAVE_OPENCV_LEGACY
# include "opencv2/legacy.hpp"
#endif
#ifdef HAVE_CUDA #ifdef HAVE_CUDA
...@@ -62,7 +65,7 @@ using namespace cvtest; ...@@ -62,7 +65,7 @@ using namespace cvtest;
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// FGDStatModel // FGDStatModel
#if BUILD_WITH_VIDEO_INPUT_SUPPORT #if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined(HAVE_OPENCV_LEGACY)
namespace cv namespace cv
{ {
...@@ -72,11 +75,10 @@ namespace cv ...@@ -72,11 +75,10 @@ namespace cv
} }
} }
PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels) PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
std::string inputFile; std::string inputFile;
int out_cn;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -84,8 +86,6 @@ PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels) ...@@ -84,8 +86,6 @@ PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels)
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1); inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
out_cn = GET_PARAM(2);
} }
}; };
...@@ -102,15 +102,10 @@ GPU_TEST_P(FGDStatModel, Update) ...@@ -102,15 +102,10 @@ GPU_TEST_P(FGDStatModel, Update)
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame)); cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::FGDStatModel d_model(out_cn); cv::Ptr<cv::gpu::BackgroundSubtractorFGD> d_fgd = cv::gpu::createBackgroundSubtractorFGD();
d_model.create(d_frame); cv::gpu::GpuMat d_foreground, d_background;
std::vector< std::vector<cv::Point> > foreground_regions;
cv::Mat h_background; d_fgd->apply(d_frame, d_foreground);
cv::Mat h_foreground;
cv::Mat h_background3;
cv::Mat backgroundDiff;
cv::Mat foregroundDiff;
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
{ {
...@@ -121,32 +116,23 @@ GPU_TEST_P(FGDStatModel, Update) ...@@ -121,32 +116,23 @@ GPU_TEST_P(FGDStatModel, Update)
int gold_count = cvUpdateBGStatModel(&ipl_frame, model); int gold_count = cvUpdateBGStatModel(&ipl_frame, model);
d_frame.upload(frame); d_frame.upload(frame);
d_fgd->apply(d_frame, d_foreground);
int count = d_model.update(d_frame); d_fgd->getBackgroundImage(d_background);
d_fgd->getForegroundRegions(foreground_regions);
ASSERT_EQ(gold_count, count); int count = (int) foreground_regions.size();
cv::Mat gold_background = cv::cvarrToMat(model->background); cv::Mat gold_background = cv::cvarrToMat(model->background);
cv::Mat gold_foreground = cv::cvarrToMat(model->foreground); cv::Mat gold_foreground = cv::cvarrToMat(model->foreground);
if (out_cn == 3) ASSERT_MAT_NEAR(gold_background, d_background, 1.0);
d_model.background.download(h_background3); ASSERT_MAT_NEAR(gold_foreground, d_foreground, 0.0);
else ASSERT_EQ(gold_count, count);
{
d_model.background.download(h_background);
cv::cvtColor(h_background, h_background3, cv::COLOR_BGRA2BGR);
}
d_model.foreground.download(h_foreground);
ASSERT_MAT_NEAR(gold_background, h_background3, 1.0);
ASSERT_MAT_NEAR(gold_foreground, h_foreground, 0.0);
} }
} }
INSTANTIATE_TEST_CASE_P(GPU_BgSegm, FGDStatModel, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_BgSegm, FGDStatModel, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
testing::Values(std::string("768x576.avi")), testing::Values(std::string("768x576.avi"))));
testing::Values(Channels(3), Channels(4))));
#endif #endif
...@@ -193,7 +179,7 @@ GPU_TEST_P(MOG, Update) ...@@ -193,7 +179,7 @@ GPU_TEST_P(MOG, Update)
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
cv::gpu::MOG_GPU mog; cv::Ptr<cv::BackgroundSubtractorMOG> mog = cv::gpu::createBackgroundSubtractorMOG();
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi); cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
cv::Ptr<cv::BackgroundSubtractorMOG> mog_gold = cv::createBackgroundSubtractorMOG(); cv::Ptr<cv::BackgroundSubtractorMOG> mog_gold = cv::createBackgroundSubtractorMOG();
...@@ -211,7 +197,7 @@ GPU_TEST_P(MOG, Update) ...@@ -211,7 +197,7 @@ GPU_TEST_P(MOG, Update)
cv::swap(temp, frame); cv::swap(temp, frame);
} }
mog(loadMat(frame, useRoi), foreground, (float)learningRate); mog->apply(loadMat(frame, useRoi), foreground, learningRate);
mog_gold->apply(frame, foreground_gold, learningRate); mog_gold->apply(frame, foreground_gold, learningRate);
...@@ -267,8 +253,8 @@ GPU_TEST_P(MOG2, Update) ...@@ -267,8 +253,8 @@ GPU_TEST_P(MOG2, Update)
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
cv::gpu::MOG2_GPU mog2; cv::Ptr<cv::BackgroundSubtractorMOG2> mog2 = cv::gpu::createBackgroundSubtractorMOG2();
mog2.bShadowDetection = detectShadow; mog2->setDetectShadows(detectShadow);
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi); cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2(); cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2();
...@@ -287,7 +273,7 @@ GPU_TEST_P(MOG2, Update) ...@@ -287,7 +273,7 @@ GPU_TEST_P(MOG2, Update)
cv::swap(temp, frame); cv::swap(temp, frame);
} }
mog2(loadMat(frame, useRoi), foreground); mog2->apply(loadMat(frame, useRoi), foreground);
mog2_gold->apply(frame, foreground_gold); mog2_gold->apply(frame, foreground_gold);
...@@ -312,8 +298,8 @@ GPU_TEST_P(MOG2, getBackgroundImage) ...@@ -312,8 +298,8 @@ GPU_TEST_P(MOG2, getBackgroundImage)
cv::Mat frame; cv::Mat frame;
cv::gpu::MOG2_GPU mog2; cv::Ptr<cv::BackgroundSubtractorMOG2> mog2 = cv::gpu::createBackgroundSubtractorMOG2();
mog2.bShadowDetection = detectShadow; mog2->setDetectShadows(detectShadow);
cv::gpu::GpuMat foreground; cv::gpu::GpuMat foreground;
cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2(); cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2();
...@@ -325,13 +311,13 @@ GPU_TEST_P(MOG2, getBackgroundImage) ...@@ -325,13 +311,13 @@ GPU_TEST_P(MOG2, getBackgroundImage)
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
mog2(loadMat(frame, useRoi), foreground); mog2->apply(loadMat(frame, useRoi), foreground);
mog2_gold->apply(frame, foreground_gold); mog2_gold->apply(frame, foreground_gold);
} }
cv::gpu::GpuMat background = createMat(frame.size(), frame.type(), useRoi); cv::gpu::GpuMat background = createMat(frame.size(), frame.type(), useRoi);
mog2.getBackgroundImage(background); mog2->getBackgroundImage(background);
cv::Mat background_gold; cv::Mat background_gold;
mog2_gold->getBackgroundImage(background_gold); mog2_gold->getBackgroundImage(background_gold);
...@@ -372,16 +358,15 @@ GPU_TEST_P(GMG, Accuracy) ...@@ -372,16 +358,15 @@ GPU_TEST_P(GMG, Accuracy)
cv::Mat frame = randomMat(size, type, 0, 100); cv::Mat frame = randomMat(size, type, 0, 100);
cv::gpu::GpuMat d_frame = loadMat(frame, useRoi); cv::gpu::GpuMat d_frame = loadMat(frame, useRoi);
cv::gpu::GMG_GPU gmg; cv::Ptr<cv::BackgroundSubtractorGMG> gmg = cv::gpu::createBackgroundSubtractorGMG();
gmg.numInitializationFrames = 5; gmg->setNumFrames(5);
gmg.smoothingRadius = 0; gmg->setSmoothingRadius(0);
gmg.initialize(d_frame.size(), 0, 255);
cv::gpu::GpuMat d_fgmask = createMat(size, CV_8UC1, useRoi); cv::gpu::GpuMat d_fgmask = createMat(size, CV_8UC1, useRoi);
for (int i = 0; i < gmg.numInitializationFrames; ++i) for (int i = 0; i < gmg->getNumFrames(); ++i)
{ {
gmg(d_frame, d_fgmask); gmg->apply(d_frame, d_fgmask);
// fgmask should be entirely background during training // fgmask should be entirely background during training
ASSERT_MAT_NEAR(zeros, d_fgmask, 0); ASSERT_MAT_NEAR(zeros, d_fgmask, 0);
...@@ -389,7 +374,7 @@ GPU_TEST_P(GMG, Accuracy) ...@@ -389,7 +374,7 @@ GPU_TEST_P(GMG, Accuracy)
frame = randomMat(size, type, 160, 255); frame = randomMat(size, type, 160, 255);
d_frame = loadMat(frame, useRoi); d_frame = loadMat(frame, useRoi);
gmg(d_frame, d_fgmask); gmg->apply(d_frame, d_fgmask);
// now fgmask should be entirely foreground // now fgmask should be entirely foreground
ASSERT_MAT_NEAR(fullfg, d_fgmask, 0); ASSERT_MAT_NEAR(fullfg, d_fgmask, 0);
......
...@@ -59,4 +59,6 @@ ...@@ -59,4 +59,6 @@
#include "opencv2/gpubgsegm.hpp" #include "opencv2/gpubgsegm.hpp"
#include "opencv2/video.hpp" #include "opencv2/video.hpp"
#include "opencv2/opencv_modules.hpp"
#endif #endif
...@@ -18,10 +18,10 @@ using namespace cv::gpu; ...@@ -18,10 +18,10 @@ using namespace cv::gpu;
enum Method enum Method
{ {
FGD_STAT,
MOG, MOG,
MOG2, MOG2,
GMG GMG,
FGD_STAT
}; };
int main(int argc, const char** argv) int main(int argc, const char** argv)
...@@ -29,7 +29,7 @@ int main(int argc, const char** argv) ...@@ -29,7 +29,7 @@ int main(int argc, const char** argv)
cv::CommandLineParser cmd(argc, argv, cv::CommandLineParser cmd(argc, argv,
"{ c camera | | use camera }" "{ c camera | | use camera }"
"{ f file | 768x576.avi | input video file }" "{ 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 }"); "{ h help | | print help message }");
if (cmd.has("help") || !cmd.check()) if (cmd.has("help") || !cmd.check())
...@@ -43,18 +43,18 @@ int main(int argc, const char** argv) ...@@ -43,18 +43,18 @@ int main(int argc, const char** argv)
string file = cmd.get<string>("file"); string file = cmd.get<string>("file");
string method = cmd.get<string>("method"); string method = cmd.get<string>("method");
if (method != "fgd" if (method != "mog"
&& method != "mog"
&& method != "mog2" && method != "mog2"
&& method != "gmg") && method != "gmg"
&& method != "fgd")
{ {
cerr << "Incorrect method" << endl; cerr << "Incorrect method" << endl;
return -1; return -1;
} }
Method m = method == "fgd" ? FGD_STAT : Method m = method == "mog" ? MOG :
method == "mog" ? MOG :
method == "mog2" ? MOG2 : method == "mog2" ? MOG2 :
method == "fgd" ? FGD_STAT :
GMG; GMG;
VideoCapture cap; VideoCapture cap;
...@@ -75,11 +75,10 @@ int main(int argc, const char** argv) ...@@ -75,11 +75,10 @@ int main(int argc, const char** argv)
GpuMat d_frame(frame); GpuMat d_frame(frame);
FGDStatModel fgd_stat; Ptr<BackgroundSubtractor> mog = gpu::createBackgroundSubtractorMOG();
MOG_GPU mog; Ptr<BackgroundSubtractor> mog2 = gpu::createBackgroundSubtractorMOG2();
MOG2_GPU mog2; Ptr<BackgroundSubtractor> gmg = gpu::createBackgroundSubtractorGMG(40);
GMG_GPU gmg; Ptr<BackgroundSubtractor> fgd = gpu::createBackgroundSubtractorFGD();
gmg.numInitializationFrames = 40;
GpuMat d_fgmask; GpuMat d_fgmask;
GpuMat d_fgimg; GpuMat d_fgimg;
...@@ -91,20 +90,20 @@ int main(int argc, const char** argv) ...@@ -91,20 +90,20 @@ int main(int argc, const char** argv)
switch (m) switch (m)
{ {
case FGD_STAT:
fgd_stat.create(d_frame);
break;
case MOG: case MOG:
mog(d_frame, d_fgmask, 0.01f); mog->apply(d_frame, d_fgmask, 0.01);
break; break;
case MOG2: case MOG2:
mog2(d_frame, d_fgmask); mog2->apply(d_frame, d_fgmask);
break; break;
case GMG: case GMG:
gmg.initialize(d_frame.size()); gmg->apply(d_frame, d_fgmask);
break;
case FGD_STAT:
fgd->apply(d_frame, d_fgmask);
break; break;
} }
...@@ -128,24 +127,23 @@ int main(int argc, const char** argv) ...@@ -128,24 +127,23 @@ int main(int argc, const char** argv)
//update the model //update the model
switch (m) switch (m)
{ {
case FGD_STAT:
fgd_stat.update(d_frame);
d_fgmask = fgd_stat.foreground;
d_bgimg = fgd_stat.background;
break;
case MOG: case MOG:
mog(d_frame, d_fgmask, 0.01f); mog->apply(d_frame, d_fgmask, 0.01);
mog.getBackgroundImage(d_bgimg); mog->getBackgroundImage(d_bgimg);
break; break;
case MOG2: case MOG2:
mog2(d_frame, d_fgmask); mog2->apply(d_frame, d_fgmask);
mog2.getBackgroundImage(d_bgimg); mog2->getBackgroundImage(d_bgimg);
break; break;
case GMG: 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; break;
} }
......
...@@ -1271,14 +1271,14 @@ TEST(FGDStatModel) ...@@ -1271,14 +1271,14 @@ TEST(FGDStatModel)
{ {
const std::string inputFile = abspath("768x576.avi"); 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"); if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
cv::Mat frame; Mat frame;
cap >> frame; cap >> frame;
IplImage ipl_frame = frame; IplImage ipl_frame = frame;
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame)); Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
while (!TestSystem::instance().stop()) while (!TestSystem::instance().stop())
{ {
...@@ -1297,8 +1297,10 @@ TEST(FGDStatModel) ...@@ -1297,8 +1297,10 @@ TEST(FGDStatModel)
cap >> frame; cap >> frame;
cv::gpu::GpuMat d_frame(frame); gpu::GpuMat d_frame(frame), d_fgmask;
cv::gpu::FGDStatModel d_model(d_frame); Ptr<BackgroundSubtractor> d_fgd = gpu::createBackgroundSubtractorFGD();
d_fgd->apply(d_frame, d_fgmask);
while (!TestSystem::instance().stop()) while (!TestSystem::instance().stop())
{ {
...@@ -1307,7 +1309,7 @@ TEST(FGDStatModel) ...@@ -1307,7 +1309,7 @@ TEST(FGDStatModel)
TestSystem::instance().gpuOn(); TestSystem::instance().gpuOn();
d_model.update(d_frame); d_fgd->apply(d_frame, d_fgmask);
TestSystem::instance().gpuOff(); TestSystem::instance().gpuOff();
} }
...@@ -1346,10 +1348,10 @@ TEST(MOG) ...@@ -1346,10 +1348,10 @@ TEST(MOG)
cap >> frame; cap >> frame;
cv::gpu::GpuMat d_frame(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; 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()) while (!TestSystem::instance().stop())
{ {
...@@ -1358,7 +1360,7 @@ TEST(MOG) ...@@ -1358,7 +1360,7 @@ TEST(MOG)
TestSystem::instance().gpuOn(); TestSystem::instance().gpuOn();
d_mog(d_frame, d_foreground, 0.01f); d_mog->apply(d_frame, d_foreground, 0.01);
TestSystem::instance().gpuOff(); TestSystem::instance().gpuOff();
} }
...@@ -1399,13 +1401,13 @@ TEST(MOG2) ...@@ -1399,13 +1401,13 @@ TEST(MOG2)
cap >> frame; cap >> frame;
cv::Ptr<cv::BackgroundSubtractor> d_mog2 = cv::gpu::createBackgroundSubtractorMOG2();
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat d_foreground; cv::gpu::GpuMat d_foreground;
cv::gpu::GpuMat d_background; cv::gpu::GpuMat d_background;
d_mog2(d_frame, d_foreground); d_mog2->apply(d_frame, d_foreground);
d_mog2.getBackgroundImage(d_background); d_mog2->getBackgroundImage(d_background);
while (!TestSystem::instance().stop()) while (!TestSystem::instance().stop())
{ {
...@@ -1414,8 +1416,8 @@ TEST(MOG2) ...@@ -1414,8 +1416,8 @@ TEST(MOG2)
TestSystem::instance().gpuOn(); TestSystem::instance().gpuOn();
d_mog2(d_frame, d_foreground); d_mog2->apply(d_frame, d_foreground);
d_mog2.getBackgroundImage(d_background); d_mog2->getBackgroundImage(d_background);
TestSystem::instance().gpuOff(); TestSystem::instance().gpuOff();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment