Revised performance test according to the feedback of the community.

This commit is contained in:
Jin Ma 2013-09-06 13:39:41 +08:00
parent 1366df8250
commit 172242a94e

View File

@ -48,6 +48,8 @@ using namespace perf;
using namespace std; using namespace std;
using namespace cv::ocl; using namespace cv::ocl;
using namespace cv; using namespace cv;
using std::tr1::tuple;
using std::tr1::get;
#if defined(HAVE_XINE) || \ #if defined(HAVE_XINE) || \
defined(HAVE_GSTREAMER) || \ defined(HAVE_GSTREAMER) || \
defined(HAVE_QUICKTIME) || \ defined(HAVE_QUICKTIME) || \
@ -60,6 +62,7 @@ using namespace cv;
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
#endif #endif
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
static void cvtFrameFmt(vector<Mat>& input, vector<Mat>& output, int output_cn) static void cvtFrameFmt(vector<Mat>& input, vector<Mat>& output, int output_cn)
{ {
for(int i = 0; i< (int)(input.size()); i++) for(int i = 0; i< (int)(input.size()); i++)
@ -70,8 +73,8 @@ static void cvtFrameFmt(vector<Mat>& input, vector<Mat>& output, int output_cn)
cvtColor(input[i], output[i], COLOR_RGB2RGBA); cvtColor(input[i], output[i], COLOR_RGB2RGBA);
} }
} }
//prepare data for CPU
static void prepareData(VideoCapture& cap, int cn, vector<Mat>& frame_buffer, vector<oclMat>& frame_buffer_ocl) static void prepareData(VideoCapture& cap, int cn, vector<Mat>& frame_buffer)
{ {
cv::Mat frame; cv::Mat frame;
std::vector<Mat> frame_buffer_init; std::vector<Mat> frame_buffer_init;
@ -87,11 +90,14 @@ static void prepareData(VideoCapture& cap, int cn, vector<Mat>& frame_buffer, ve
cvtFrameFmt(frame_buffer_init, frame_buffer, 1); cvtFrameFmt(frame_buffer_init, frame_buffer, 1);
else else
frame_buffer = frame_buffer_init; frame_buffer = frame_buffer_init;
}
for(int i = 0; i < nFrame; i++) //copy CPU data to GPU
static void prepareData(vector<Mat>& frame_buffer, vector<oclMat>& frame_buffer_ocl)
{
for(int i = 0; i < (int)frame_buffer.size(); i++)
frame_buffer_ocl.push_back(cv::ocl::oclMat(frame_buffer[i])); frame_buffer_ocl.push_back(cv::ocl::oclMat(frame_buffer[i]));
} }
#endif
///////////// MOG //////////////////////// ///////////// MOG ////////////////////////
#if BUILD_WITH_VIDEO_INPUT_SUPPORT #if BUILD_WITH_VIDEO_INPUT_SUPPORT
@ -118,15 +124,16 @@ PERF_TEST_P(VideoMOGFixture, MOG,
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
prepareData(cap, cn, frame_buffer, frame_buffer_ocl); prepareData(cap, cn, frame_buffer);
cv::Mat foreground;
cv::ocl::oclMat foreground_d;
if(RUN_PLAIN_IMPL) if(RUN_PLAIN_IMPL)
{ {
cv::BackgroundSubtractorMOG mog;
cv::Mat foreground;
TEST_CYCLE() TEST_CYCLE()
{ {
cv::BackgroundSubtractorMOG mog;
foreground.release();
for (int i = 0; i < nFrame; i++) for (int i = 0; i < nFrame; i++)
{ {
mog(frame_buffer[i], foreground, learningRate); mog(frame_buffer[i], foreground, learningRate);
@ -135,18 +142,19 @@ PERF_TEST_P(VideoMOGFixture, MOG,
SANITY_CHECK(foreground); SANITY_CHECK(foreground);
}else if(RUN_OCL_IMPL) }else if(RUN_OCL_IMPL)
{ {
cv::ocl::MOG d_mog; prepareData(frame_buffer, frame_buffer_ocl);
cv::ocl::oclMat foreground; CV_Assert((int)(frame_buffer_ocl.size()) == nFrame);
cv::Mat foreground_h;
OCL_TEST_CYCLE() OCL_TEST_CYCLE()
{ {
cv::ocl::MOG d_mog;
foreground_d.release();
for (int i = 0; i < nFrame; ++i) for (int i = 0; i < nFrame; ++i)
{ {
d_mog(frame_buffer_ocl[i], foreground, learningRate); d_mog(frame_buffer_ocl[i], foreground_d, learningRate);
} }
} }
foreground.download(foreground_h); foreground_d.download(foreground);
SANITY_CHECK(foreground_h); SANITY_CHECK(foreground);
}else }else
OCL_PERF_ELSE OCL_PERF_ELSE
} }
@ -173,18 +181,18 @@ PERF_TEST_P(VideoMOG2Fixture, MOG2,
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
prepareData(cap, cn, frame_buffer);
prepareData(cap, cn, frame_buffer, frame_buffer_ocl); cv::Mat foreground;
cv::ocl::oclMat foreground_d;
if(RUN_PLAIN_IMPL) if(RUN_PLAIN_IMPL)
{ {
cv::BackgroundSubtractorMOG2 mog2;
cv::Mat foreground;
mog2.set("detectShadows", false);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::BackgroundSubtractorMOG2 mog2;
mog2.set("detectShadows", false);
foreground.release();
for (int i = 0; i < nFrame; i++) for (int i = 0; i < nFrame; i++)
{ {
mog2(frame_buffer[i], foreground); mog2(frame_buffer[i], foreground);
@ -193,19 +201,19 @@ PERF_TEST_P(VideoMOG2Fixture, MOG2,
SANITY_CHECK(foreground); SANITY_CHECK(foreground);
}else if(RUN_OCL_IMPL) }else if(RUN_OCL_IMPL)
{ {
cv::ocl::MOG2 d_mog2; prepareData(frame_buffer, frame_buffer_ocl);
cv::ocl::oclMat foreground; CV_Assert((int)(frame_buffer_ocl.size()) == nFrame);
cv::Mat foreground_h;
OCL_TEST_CYCLE() OCL_TEST_CYCLE()
{ {
cv::ocl::MOG2 d_mog2;
foreground_d.release();
for (int i = 0; i < nFrame; i++) for (int i = 0; i < nFrame; i++)
{ {
d_mog2(frame_buffer_ocl[i], foreground); d_mog2(frame_buffer_ocl[i], foreground_d);
} }
} }
foreground.download(foreground_h); foreground_d.download(foreground);
SANITY_CHECK(foreground_h); SANITY_CHECK(foreground);
}else }else
OCL_PERF_ELSE OCL_PERF_ELSE
} }
@ -218,7 +226,7 @@ typedef TestBaseWithParam<VideoMOG2ParamType> Video_MOG2GetBackgroundImage;
PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2, PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2,
::testing::Combine(::testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), ::testing::Combine(::testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"),
::testing::Values(1, 3))) ::testing::Values(3)))
{ {
VideoMOG2ParamType params = GetParam(); VideoMOG2ParamType params = GetParam();
@ -232,16 +240,21 @@ PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2,
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
prepareData(cap, cn, frame_buffer, frame_buffer_ocl); prepareData(cap, cn, frame_buffer);
cv::Mat foreground;
cv::Mat background;
cv::ocl::oclMat foreground_d;
cv::ocl::oclMat background_d;
if(RUN_PLAIN_IMPL) if(RUN_PLAIN_IMPL)
{ {
cv::BackgroundSubtractorMOG2 mog2;
cv::Mat foreground;
cv::Mat background;
mog2.set("detectShadows", false);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::BackgroundSubtractorMOG2 mog2;
mog2.set("detectShadows", false);
foreground.release();
background.release();
for (int i = 0; i < nFrame; i++) for (int i = 0; i < nFrame; i++)
{ {
mog2(frame_buffer[i], foreground); mog2(frame_buffer[i], foreground);
@ -251,22 +264,22 @@ PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2,
SANITY_CHECK(background); SANITY_CHECK(background);
}else if(RUN_OCL_IMPL) }else if(RUN_OCL_IMPL)
{ {
cv::ocl::MOG2 d_mog2; prepareData(frame_buffer, frame_buffer_ocl);
cv::ocl::oclMat foreground; CV_Assert((int)(frame_buffer_ocl.size()) == nFrame);
cv::Mat background_h;
cv::ocl::oclMat background;
OCL_TEST_CYCLE() OCL_TEST_CYCLE()
{ {
cv::ocl::MOG2 d_mog2;
foreground_d.release();
background_d.release();
for (int i = 0; i < nFrame; i++) for (int i = 0; i < nFrame; i++)
{ {
d_mog2(frame_buffer_ocl[i], foreground); d_mog2(frame_buffer_ocl[i], foreground_d);
} }
d_mog2.getBackgroundImage(background); d_mog2.getBackgroundImage(background_d);
} }
background.download(background_h); background_d.download(background);
SANITY_CHECK(background_h); SANITY_CHECK(background);
}else }else
OCL_PERF_ELSE OCL_PERF_ELSE
} }
#endif #endif