提交 3a4353f0 编写于 作者: V Vladislav Vinogradov

added FGDStatModel, MOG and MOG2 to gpu performance sample

上级 ed8b6c79
......@@ -5,6 +5,7 @@
#include "opencv2/video/video.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "performance.h"
using namespace std;
......@@ -1249,3 +1250,166 @@ TEST(FarnebackOpticalFlow)
}}}
}
namespace cv
{
template<> void Ptr<CvBGStatModel>::delete_obj()
{
cvReleaseBGStatModel(&obj);
}
}
TEST(FGDStatModel)
{
const std::string inputFile = abspath("768x576.avi");
cv::VideoCapture cap(inputFile);
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
cv::Mat frame;
cap >> frame;
IplImage ipl_frame = frame;
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
while (!TestSystem::instance().stop())
{
cap >> frame;
ipl_frame = frame;
TestSystem::instance().cpuOn();
cvUpdateBGStatModel(&ipl_frame, model);
TestSystem::instance().cpuOff();
}
TestSystem::instance().cpuComplete();
cap.open(inputFile);
cap >> frame;
cv::gpu::GpuMat d_frame(frame);
cv::gpu::FGDStatModel d_model(d_frame);
while (!TestSystem::instance().stop())
{
cap >> frame;
d_frame.upload(frame);
TestSystem::instance().gpuOn();
d_model.update(d_frame);
TestSystem::instance().gpuOff();
}
TestSystem::instance().gpuComplete();
}
TEST(MOG)
{
const std::string inputFile = abspath("768x576.avi");
cv::VideoCapture cap(inputFile);
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
cv::Mat frame;
cap >> frame;
cv::BackgroundSubtractorMOG mog;
cv::Mat foreground;
mog(frame, foreground, 0.01);
while (!TestSystem::instance().stop())
{
cap >> frame;
TestSystem::instance().cpuOn();
mog(frame, foreground, 0.01);
TestSystem::instance().cpuOff();
}
TestSystem::instance().cpuComplete();
cap.open(inputFile);
cap >> frame;
cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG_GPU d_mog;
cv::gpu::GpuMat d_foreground;
d_mog(d_frame, d_foreground, 0.01);
while (!TestSystem::instance().stop())
{
cap >> frame;
d_frame.upload(frame);
TestSystem::instance().gpuOn();
d_mog(d_frame, d_foreground, 0.01);
TestSystem::instance().gpuOff();
}
TestSystem::instance().gpuComplete();
}
TEST(MOG2)
{
const std::string inputFile = abspath("768x576.avi");
cv::VideoCapture cap(inputFile);
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
cv::Mat frame;
cap >> frame;
cv::BackgroundSubtractorMOG2 mog2;
cv::Mat foreground;
cv::Mat background;
mog2(frame, foreground);
mog2.getBackgroundImage(background);
while (!TestSystem::instance().stop())
{
cap >> frame;
TestSystem::instance().cpuOn();
mog2(frame, foreground);
mog2.getBackgroundImage(background);
TestSystem::instance().cpuOff();
}
TestSystem::instance().cpuComplete();
cap.open(inputFile);
cap >> frame;
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);
while (!TestSystem::instance().stop())
{
cap >> frame;
d_frame.upload(frame);
TestSystem::instance().gpuOn();
d_mog2(d_frame, d_foreground);
d_mog2.getBackgroundImage(d_background);
TestSystem::instance().gpuOff();
}
TestSystem::instance().gpuComplete();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册