2018-01-05 14:50:19 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
2014-08-01 22:11:20 +08:00
|
|
|
#include "../perf_precomp.hpp"
|
2014-01-27 21:32:51 +08:00
|
|
|
#include "opencv2/ts/ocl_perf.hpp"
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL
|
2018-01-05 14:50:19 +08:00
|
|
|
#include "../perf_bgfg_utils.hpp"
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
namespace opencv_test {
|
2014-01-27 21:32:51 +08:00
|
|
|
namespace ocl {
|
|
|
|
|
|
|
|
//////////////////////////// Mog2//////////////////////////
|
|
|
|
|
|
|
|
typedef tuple<string, int> VideoMOG2ParamType;
|
2014-01-29 18:10:36 +08:00
|
|
|
typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_Apply;
|
2014-01-27 21:32:51 +08:00
|
|
|
typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_GetBackgroundImage;
|
|
|
|
|
2018-01-05 14:50:19 +08:00
|
|
|
using namespace opencv_test;
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2021-09-25 14:31:44 +08:00
|
|
|
OCL_PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("cv/video/768x576.avi", "cv/video/1920x1080.avi"), Values(1,3)))
|
2014-01-29 18:10:36 +08:00
|
|
|
{
|
|
|
|
VideoMOG2ParamType params = GetParam();
|
|
|
|
|
|
|
|
const string inputFile = getDataPath(get<0>(params));
|
|
|
|
|
|
|
|
const int cn = get<1>(params);
|
|
|
|
int nFrame = 5;
|
|
|
|
|
|
|
|
vector<Mat> frame_buffer(nFrame);
|
|
|
|
|
|
|
|
cv::VideoCapture cap(inputFile);
|
2018-12-26 20:50:20 +08:00
|
|
|
if (!cap.isOpened())
|
|
|
|
throw SkipTestException("Video file can not be opened");
|
2014-01-29 18:10:36 +08:00
|
|
|
prepareData(cap, cn, frame_buffer);
|
|
|
|
|
|
|
|
UMat u_foreground;
|
|
|
|
|
|
|
|
OCL_TEST_CYCLE()
|
|
|
|
{
|
|
|
|
Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();
|
|
|
|
mog2->setDetectShadows(false);
|
|
|
|
u_foreground.release();
|
|
|
|
for (int i = 0; i < nFrame; i++)
|
|
|
|
{
|
|
|
|
mog2->apply(frame_buffer[i], u_foreground);
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 14:50:19 +08:00
|
|
|
SANITY_CHECK_NOTHING();
|
2014-01-29 18:10:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 14:50:19 +08:00
|
|
|
OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Values(
|
2021-09-25 14:31:44 +08:00
|
|
|
std::make_pair<string, int>("cv/video/768x576.avi", 5),
|
|
|
|
std::make_pair<string, int>("cv/video/1920x1080.avi", 5)))
|
2014-01-27 21:32:51 +08:00
|
|
|
{
|
|
|
|
VideoMOG2ParamType params = GetParam();
|
|
|
|
|
|
|
|
const string inputFile = getDataPath(get<0>(params));
|
|
|
|
|
2018-01-05 14:50:19 +08:00
|
|
|
const int cn = 3;
|
|
|
|
const int skipFrames = get<1>(params);
|
|
|
|
int nFrame = 10;
|
2014-01-27 21:32:51 +08:00
|
|
|
|
|
|
|
vector<Mat> frame_buffer(nFrame);
|
|
|
|
|
|
|
|
cv::VideoCapture cap(inputFile);
|
2018-12-26 20:50:20 +08:00
|
|
|
if (!cap.isOpened())
|
|
|
|
throw SkipTestException("Video file can not be opened");
|
2018-01-05 14:50:19 +08:00
|
|
|
prepareData(cap, cn, frame_buffer, skipFrames);
|
2014-01-27 21:32:51 +08:00
|
|
|
|
|
|
|
UMat u_foreground, u_background;
|
|
|
|
|
|
|
|
OCL_TEST_CYCLE()
|
|
|
|
{
|
|
|
|
Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();
|
|
|
|
mog2->setDetectShadows(false);
|
|
|
|
u_foreground.release();
|
|
|
|
u_background.release();
|
|
|
|
for (int i = 0; i < nFrame; i++)
|
|
|
|
{
|
|
|
|
mog2->apply(frame_buffer[i], u_foreground);
|
|
|
|
}
|
|
|
|
mog2->getBackgroundImage(u_background);
|
|
|
|
}
|
2018-01-05 14:50:19 +08:00
|
|
|
#ifdef DEBUG_BGFG
|
|
|
|
imwrite(format("fg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_foreground.getMat(ACCESS_READ));
|
|
|
|
imwrite(format("bg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_background.getMat(ACCESS_READ));
|
|
|
|
#endif
|
2017-12-21 23:14:10 +08:00
|
|
|
SANITY_CHECK_NOTHING();
|
2014-01-27 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
}}// namespace opencv_test::ocl
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#endif
|