added FGDStatModel, MOG and MOG2 to gpu performance sample
authorVladislav Vinogradov <no@email>
Mon, 25 Jun 2012 11:46:45 +0000 (11:46 +0000)
committerVladislav Vinogradov <no@email>
Mon, 25 Jun 2012 11:46:45 +0000 (11:46 +0000)
samples/gpu/performance/tests.cpp

index ae16f6d..aefd957 100644 (file)
@@ -5,6 +5,7 @@
 #include "opencv2/video/video.hpp"\r
 #include "opencv2/gpu/gpu.hpp"\r
 #include "opencv2/nonfree/nonfree.hpp"\r
+#include "opencv2/legacy/legacy.hpp"\r
 #include "performance.h"\r
 \r
 using namespace std;\r
@@ -1249,3 +1250,166 @@ TEST(FarnebackOpticalFlow)
 \r
     }}}\r
 }\r
+\r
+namespace cv\r
+{\r
+    template<> void Ptr<CvBGStatModel>::delete_obj()\r
+    {\r
+        cvReleaseBGStatModel(&obj);\r
+    }\r
+}\r
+\r
+TEST(FGDStatModel)\r
+{\r
+    const std::string inputFile = abspath("768x576.avi");\r
+\r
+    cv::VideoCapture cap(inputFile);\r
+    if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");\r
+\r
+    cv::Mat frame;\r
+    cap >> frame;\r
+\r
+    IplImage ipl_frame = frame;\r
+    cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+        ipl_frame = frame;\r
+\r
+        TestSystem::instance().cpuOn();\r
+\r
+        cvUpdateBGStatModel(&ipl_frame, model);\r
+\r
+        TestSystem::instance().cpuOff();\r
+    }\r
+    TestSystem::instance().cpuComplete();\r
+\r
+    cap.open(inputFile);\r
+\r
+    cap >> frame;\r
+\r
+    cv::gpu::GpuMat d_frame(frame);\r
+    cv::gpu::FGDStatModel d_model(d_frame);\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+        d_frame.upload(frame);\r
+\r
+        TestSystem::instance().gpuOn();\r
+\r
+        d_model.update(d_frame);\r
+\r
+        TestSystem::instance().gpuOff();\r
+    }\r
+    TestSystem::instance().gpuComplete();\r
+}\r
+\r
+TEST(MOG)\r
+{\r
+    const std::string inputFile = abspath("768x576.avi");\r
+\r
+    cv::VideoCapture cap(inputFile);\r
+    if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");\r
+\r
+    cv::Mat frame;\r
+    cap >> frame;\r
+\r
+    cv::BackgroundSubtractorMOG mog;\r
+    cv::Mat foreground;\r
+\r
+    mog(frame, foreground, 0.01);\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+\r
+        TestSystem::instance().cpuOn();\r
+\r
+        mog(frame, foreground, 0.01);\r
+\r
+        TestSystem::instance().cpuOff();\r
+    }\r
+    TestSystem::instance().cpuComplete();\r
+\r
+    cap.open(inputFile);\r
+\r
+    cap >> frame;\r
+\r
+    cv::gpu::GpuMat d_frame(frame);\r
+    cv::gpu::MOG_GPU d_mog;\r
+    cv::gpu::GpuMat d_foreground;\r
+\r
+    d_mog(d_frame, d_foreground, 0.01);\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+        d_frame.upload(frame);\r
+\r
+        TestSystem::instance().gpuOn();\r
+\r
+        d_mog(d_frame, d_foreground, 0.01);\r
+\r
+        TestSystem::instance().gpuOff();\r
+    }\r
+    TestSystem::instance().gpuComplete();\r
+}\r
+\r
+TEST(MOG2)\r
+{\r
+    const std::string inputFile = abspath("768x576.avi");\r
+\r
+    cv::VideoCapture cap(inputFile);\r
+    if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");\r
+\r
+    cv::Mat frame;\r
+    cap >> frame;\r
+\r
+    cv::BackgroundSubtractorMOG2 mog2;\r
+    cv::Mat foreground;\r
+    cv::Mat background;\r
+\r
+    mog2(frame, foreground);\r
+    mog2.getBackgroundImage(background);\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+\r
+        TestSystem::instance().cpuOn();\r
+\r
+        mog2(frame, foreground);\r
+        mog2.getBackgroundImage(background);\r
+\r
+        TestSystem::instance().cpuOff();\r
+    }\r
+    TestSystem::instance().cpuComplete();\r
+\r
+    cap.open(inputFile);\r
+\r
+    cap >> frame;\r
+\r
+    cv::gpu::GpuMat d_frame(frame);\r
+    cv::gpu::MOG2_GPU d_mog2;\r
+    cv::gpu::GpuMat d_foreground;\r
+    cv::gpu::GpuMat d_background;\r
+\r
+    d_mog2(d_frame, d_foreground);\r
+    d_mog2.getBackgroundImage(d_background);\r
+\r
+    while (!TestSystem::instance().stop())\r
+    {\r
+        cap >> frame;\r
+        d_frame.upload(frame);\r
+\r
+        TestSystem::instance().gpuOn();\r
+\r
+        d_mog2(d_frame, d_foreground);\r
+        d_mog2.getBackgroundImage(d_background);\r
+\r
+        TestSystem::instance().gpuOff();\r
+    }\r
+    TestSystem::instance().gpuComplete();\r
+}\r