mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Merge pull request #19542 from OrestChura:oc/BGSub_ptest
[G-API]: Performance tests for BackgroundSubtractor * Perf.Tests for BackgroundSubtractor kernel * Fix CI * Addressing comments * Addressing a comment * Test cycle and validation changes * Addressing comment * Added assert
This commit is contained in:
parent
12fa8d8444
commit
c1a57a10a4
@ -26,6 +26,9 @@ class OptFlowLKForPyrPerfTest : public TestPerfParams<tuple<std::string,int,tupl
|
|||||||
class BuildPyr_CalcOptFlow_PipelinePerfTest : public TestPerfParams<tuple<std::string,int,int,bool,
|
class BuildPyr_CalcOptFlow_PipelinePerfTest : public TestPerfParams<tuple<std::string,int,int,bool,
|
||||||
cv::GCompileArgs>> {};
|
cv::GCompileArgs>> {};
|
||||||
|
|
||||||
|
class BackgroundSubtractorPerfTest:
|
||||||
|
public TestPerfParams<tuple<cv::gapi::video::BackgroundSubtractorType, std::string,
|
||||||
|
bool, double, std::size_t, cv::GCompileArgs, CompareMats>> {};
|
||||||
} // opencv_test
|
} // opencv_test
|
||||||
|
|
||||||
#endif // OPENCV_GAPI_VIDEO_PERF_TESTS_HPP
|
#endif // OPENCV_GAPI_VIDEO_PERF_TESTS_HPP
|
||||||
|
@ -154,6 +154,95 @@ PERF_TEST_P_(BuildPyr_CalcOptFlow_PipelinePerfTest, TestPerformance)
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef HAVE_OPENCV_VIDEO
|
||||||
|
|
||||||
|
PERF_TEST_P_(BackgroundSubtractorPerfTest, TestPerformance)
|
||||||
|
{
|
||||||
|
namespace gvideo = cv::gapi::video;
|
||||||
|
initTestDataPath();
|
||||||
|
|
||||||
|
gvideo::BackgroundSubtractorType opType;
|
||||||
|
std::string filePath = "";
|
||||||
|
bool detectShadows = false;
|
||||||
|
double learningRate = -1.;
|
||||||
|
std::size_t testNumFrames = 0;
|
||||||
|
cv::GCompileArgs compileArgs;
|
||||||
|
CompareMats cmpF;
|
||||||
|
|
||||||
|
std::tie(opType, filePath, detectShadows, learningRate, testNumFrames,
|
||||||
|
compileArgs, cmpF) = GetParam();
|
||||||
|
|
||||||
|
const int histLength = 500;
|
||||||
|
double thr = -1;
|
||||||
|
switch (opType)
|
||||||
|
{
|
||||||
|
case gvideo::TYPE_BS_MOG2:
|
||||||
|
{
|
||||||
|
thr = 16.;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case gvideo::TYPE_BS_KNN:
|
||||||
|
{
|
||||||
|
thr = 400.;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
FAIL() << "unsupported type of BackgroundSubtractor";
|
||||||
|
}
|
||||||
|
const gvideo::BackgroundSubtractorParams bsp(opType, histLength, thr, detectShadows,
|
||||||
|
learningRate);
|
||||||
|
|
||||||
|
// Retrieving frames
|
||||||
|
std::vector<cv::Mat> frames;
|
||||||
|
frames.reserve(testNumFrames);
|
||||||
|
{
|
||||||
|
cv::Mat frame;
|
||||||
|
cv::VideoCapture cap;
|
||||||
|
if (!cap.open(findDataFile(filePath)))
|
||||||
|
throw SkipTestException("Video file can not be opened");
|
||||||
|
for (std::size_t i = 0; i < testNumFrames && cap.read(frame); i++)
|
||||||
|
{
|
||||||
|
frames.push_back(frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GAPI_Assert(testNumFrames == frames.size() && "Can't read required number of frames");
|
||||||
|
|
||||||
|
// G-API graph declaration
|
||||||
|
cv::GMat in;
|
||||||
|
cv::GMat out = cv::gapi::BackgroundSubtractor(in, bsp);
|
||||||
|
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||||
|
auto cc = c.compile(cv::descr_of(frames[0]), std::move(compileArgs));
|
||||||
|
|
||||||
|
cv::Mat gapiForeground;
|
||||||
|
TEST_CYCLE()
|
||||||
|
{
|
||||||
|
cc.prepareForNewStream();
|
||||||
|
for (size_t i = 0; i < testNumFrames; i++)
|
||||||
|
{
|
||||||
|
cc(cv::gin(frames[i]), cv::gout(gapiForeground));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenCV Background Subtractor declaration
|
||||||
|
cv::Ptr<cv::BackgroundSubtractor> pOCVBackSub;
|
||||||
|
if (opType == gvideo::TYPE_BS_MOG2)
|
||||||
|
pOCVBackSub = cv::createBackgroundSubtractorMOG2(histLength, thr, detectShadows);
|
||||||
|
else if (opType == gvideo::TYPE_BS_KNN)
|
||||||
|
pOCVBackSub = cv::createBackgroundSubtractorKNN(histLength, thr, detectShadows);
|
||||||
|
cv::Mat ocvForeground;
|
||||||
|
for (size_t i = 0; i < testNumFrames; i++)
|
||||||
|
{
|
||||||
|
pOCVBackSub->apply(frames[i], ocvForeground, learningRate);
|
||||||
|
}
|
||||||
|
// Validation
|
||||||
|
EXPECT_TRUE(cmpF(gapiForeground, ocvForeground));
|
||||||
|
SANITY_CHECK_NOTHING();
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // HAVE_OPENCV_VIDEO
|
||||||
|
|
||||||
} // opencv_test
|
} // opencv_test
|
||||||
|
|
||||||
#endif // OPENCV_GAPI_VIDEO_PERF_TESTS_INL_HPP
|
#endif // OPENCV_GAPI_VIDEO_PERF_TESTS_INL_HPP
|
||||||
|
@ -70,7 +70,7 @@ INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(OptFlowLKForPyrPerfTestCPU), OptFlowLKF
|
|||||||
Values(cv::TermCriteria(cv::TermCriteria::COUNT |
|
Values(cv::TermCriteria(cv::TermCriteria::COUNT |
|
||||||
cv::TermCriteria::EPS,
|
cv::TermCriteria::EPS,
|
||||||
30, 0.01)),
|
30, 0.01)),
|
||||||
Values(true, false),
|
testing::Bool(),
|
||||||
Values(cv::compile_args(VIDEO_CPU))));
|
Values(cv::compile_args(VIDEO_CPU))));
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(OptFlowLKInternalPerfTestCPU),
|
INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(OptFlowLKInternalPerfTestCPU),
|
||||||
@ -90,7 +90,7 @@ INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BuildPyr_CalcOptFlow_PipelinePerfTestCP
|
|||||||
Combine(Values("cv/optflow/frames/1080p_%02d.png"),
|
Combine(Values("cv/optflow/frames/1080p_%02d.png"),
|
||||||
Values(7, 11),
|
Values(7, 11),
|
||||||
Values(1000),
|
Values(1000),
|
||||||
Values(true, false),
|
testing::Bool(),
|
||||||
Values(cv::compile_args(VIDEO_CPU))));
|
Values(cv::compile_args(VIDEO_CPU))));
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BuildPyr_CalcOptFlow_PipelineInternalTestPerfCPU),
|
INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BuildPyr_CalcOptFlow_PipelineInternalTestPerfCPU),
|
||||||
@ -100,4 +100,15 @@ INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BuildPyr_CalcOptFlow_PipelineInternalTe
|
|||||||
Values(3),
|
Values(3),
|
||||||
Values(true),
|
Values(true),
|
||||||
Values(cv::compile_args(VIDEO_CPU))));
|
Values(cv::compile_args(VIDEO_CPU))));
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BackgroundSubtractorPerfTestCPU),
|
||||||
|
BackgroundSubtractorPerfTest,
|
||||||
|
Combine(Values(cv::gapi::video::TYPE_BS_MOG2,
|
||||||
|
cv::gapi::video::TYPE_BS_KNN),
|
||||||
|
Values("cv/video/768x576.avi", "cv/video/1920x1080.avi"),
|
||||||
|
testing::Bool(),
|
||||||
|
Values(0., 0.5, 1.),
|
||||||
|
Values(5),
|
||||||
|
Values(cv::compile_args(VIDEO_CPU)),
|
||||||
|
Values(AbsExact().to_compare_obj())));
|
||||||
} // opencv_test
|
} // opencv_test
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#endif // HAVE_OPENCV_VIDEO
|
#endif // HAVE_OPENCV_VIDEO
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace opencv_test
|
namespace opencv_test
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
@ -128,6 +127,54 @@ struct OptFlowLKTestParams
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void compareOutputPyramids(const BuildOpticalFlowPyramidTestOutput& outGAPI,
|
||||||
|
const BuildOpticalFlowPyramidTestOutput& outOCV)
|
||||||
|
{
|
||||||
|
GAPI_Assert(outGAPI.maxLevel == outOCV.maxLevel);
|
||||||
|
GAPI_Assert(outOCV.maxLevel >= 0);
|
||||||
|
const size_t maxLevel = static_cast<size_t>(outOCV.maxLevel);
|
||||||
|
for (size_t i = 0; i <= maxLevel; i++)
|
||||||
|
{
|
||||||
|
EXPECT_TRUE(AbsExact().to_compare_f()(outGAPI.pyramid[i], outOCV.pyramid[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Elem>
|
||||||
|
inline bool compareVectorsAbsExactForOptFlow(const std::vector<Elem>& outGAPI,
|
||||||
|
const std::vector<Elem>& outOCV)
|
||||||
|
{
|
||||||
|
return AbsExactVector<Elem>().to_compare_f()(outGAPI, outOCV);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void compareOutputsOptFlow(const OptFlowLKTestOutput& outGAPI,
|
||||||
|
const OptFlowLKTestOutput& outOCV)
|
||||||
|
{
|
||||||
|
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.nextPoints, outOCV.nextPoints));
|
||||||
|
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.statuses, outOCV.statuses));
|
||||||
|
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.errors, outOCV.errors));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const cv::TermCriteria& criteria)
|
||||||
|
{
|
||||||
|
os << "{";
|
||||||
|
switch (criteria.type) {
|
||||||
|
case cv::TermCriteria::COUNT:
|
||||||
|
os << "COUNT; ";
|
||||||
|
break;
|
||||||
|
case cv::TermCriteria::EPS:
|
||||||
|
os << "EPS; ";
|
||||||
|
break;
|
||||||
|
case cv::TermCriteria::COUNT | cv::TermCriteria::EPS:
|
||||||
|
os << "COUNT | EPS; ";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
os << "TypeUndefined; ";
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
return os << criteria.maxCount << "; " << criteria.epsilon <<"}";
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OPENCV_VIDEO
|
#ifdef HAVE_OPENCV_VIDEO
|
||||||
|
|
||||||
inline GComputation runOCVnGAPIBuildOptFlowPyramid(TestFunctional& testInst,
|
inline GComputation runOCVnGAPIBuildOptFlowPyramid(TestFunctional& testInst,
|
||||||
@ -390,54 +437,24 @@ inline GComputation runOCVnGAPIOptFlowPipeline(TestFunctional&,
|
|||||||
|
|
||||||
#endif // HAVE_OPENCV_VIDEO
|
#endif // HAVE_OPENCV_VIDEO
|
||||||
|
|
||||||
inline void compareOutputPyramids(const BuildOpticalFlowPyramidTestOutput& outGAPI,
|
|
||||||
const BuildOpticalFlowPyramidTestOutput& outOCV)
|
|
||||||
{
|
|
||||||
GAPI_Assert(outGAPI.maxLevel == outOCV.maxLevel);
|
|
||||||
GAPI_Assert(outOCV.maxLevel >= 0);
|
|
||||||
size_t maxLevel = static_cast<size_t>(outOCV.maxLevel);
|
|
||||||
for (size_t i = 0; i <= maxLevel; i++)
|
|
||||||
{
|
|
||||||
EXPECT_TRUE(AbsExact().to_compare_f()(outGAPI.pyramid[i], outOCV.pyramid[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Elem>
|
|
||||||
inline bool compareVectorsAbsExactForOptFlow(std::vector<Elem> outGAPI, std::vector<Elem> outOCV)
|
|
||||||
{
|
|
||||||
return AbsExactVector<Elem>().to_compare_f()(outGAPI, outOCV);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void compareOutputsOptFlow(const OptFlowLKTestOutput& outGAPI,
|
|
||||||
const OptFlowLKTestOutput& outOCV)
|
|
||||||
{
|
|
||||||
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.nextPoints, outOCV.nextPoints));
|
|
||||||
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.statuses, outOCV.statuses));
|
|
||||||
EXPECT_TRUE(compareVectorsAbsExactForOptFlow(outGAPI.errors, outOCV.errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os, const cv::TermCriteria& criteria)
|
|
||||||
{
|
|
||||||
os << "{";
|
|
||||||
switch (criteria.type) {
|
|
||||||
case cv::TermCriteria::COUNT:
|
|
||||||
os << "COUNT; ";
|
|
||||||
break;
|
|
||||||
case cv::TermCriteria::EPS:
|
|
||||||
os << "EPS; ";
|
|
||||||
break;
|
|
||||||
case cv::TermCriteria::COUNT | cv::TermCriteria::EPS:
|
|
||||||
os << "COUNT | EPS; ";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
os << "TypeUndefined; ";
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
return os << criteria.maxCount << "; " << criteria.epsilon <<"}";
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace opencv_test
|
} // namespace opencv_test
|
||||||
|
|
||||||
|
// Note: namespace must match the namespace of the type of the printed object
|
||||||
|
namespace cv { namespace gapi { namespace video
|
||||||
|
{
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const BackgroundSubtractorType op)
|
||||||
|
{
|
||||||
|
#define CASE(v) case BackgroundSubtractorType::v: os << #v; break
|
||||||
|
switch (op)
|
||||||
|
{
|
||||||
|
CASE(TYPE_BS_MOG2);
|
||||||
|
CASE(TYPE_BS_KNN);
|
||||||
|
default: GAPI_Assert(false && "unknown BackgroundSubtractor type");
|
||||||
|
}
|
||||||
|
#undef CASE
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
}}} // namespace cv::gapi::video
|
||||||
|
|
||||||
#endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP
|
#endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP
|
||||||
|
@ -111,7 +111,7 @@ TEST_P(BackgroundSubtractorTest, AccuracyTest)
|
|||||||
auto gapiBackSub = c.compileStreaming(getCompileArgs());
|
auto gapiBackSub = c.compileStreaming(getCompileArgs());
|
||||||
|
|
||||||
// Testing G-API Background Substractor in streaming mode
|
// Testing G-API Background Substractor in streaming mode
|
||||||
auto path = findDataFile("cv/video/768x576.avi");
|
const auto path = findDataFile(filePath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
gapiBackSub.setSource(gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(path));
|
gapiBackSub.setSource(gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(path));
|
||||||
|
@ -107,7 +107,7 @@ INSTANTIATE_TEST_CASE_MACRO_P(WITH_VIDEO(BackgroundSubtractorTestCPU),
|
|||||||
std::make_tuple(cv::gapi::video::TYPE_BS_KNN, 400),
|
std::make_tuple(cv::gapi::video::TYPE_BS_KNN, 400),
|
||||||
std::make_tuple(cv::gapi::video::TYPE_BS_KNN, 200)),
|
std::make_tuple(cv::gapi::video::TYPE_BS_KNN, 200)),
|
||||||
Values(500, 50),
|
Values(500, 50),
|
||||||
Values(true, false),
|
testing::Bool(),
|
||||||
Values(-1, 0, 0.5, 1),
|
Values(-1, 0, 0.5, 1),
|
||||||
Values("cv/video/768x576.avi"),
|
Values("cv/video/768x576.avi"),
|
||||||
Values(3)));
|
Values(3)));
|
||||||
|
Loading…
Reference in New Issue
Block a user