From 2492c299f36d1c6a140f716f99b2293c6e02a27f Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Fri, 14 Apr 2017 13:35:07 +0300 Subject: [PATCH] Extended set of existing performance test to OpenVX HAL suitable execution modes --- modules/core/perf/perf_lut.cpp | 26 +++++++ modules/features2d/perf/perf_fast.cpp | 23 ++++++ modules/imgproc/perf/perf_accumulate.cpp | 96 ++++++++++++++++++++++++ modules/imgproc/perf/perf_filter2d.cpp | 27 +++++++ modules/imgproc/perf/perf_pyramids.cpp | 21 ++++++ modules/imgproc/perf/perf_warp.cpp | 68 +++++++++++++++++ modules/video/perf/perf_optflowpyrlk.cpp | 52 +++++++++++++ 7 files changed, 313 insertions(+) create mode 100644 modules/core/perf/perf_lut.cpp create mode 100644 modules/imgproc/perf/perf_accumulate.cpp diff --git a/modules/core/perf/perf_lut.cpp b/modules/core/perf/perf_lut.cpp new file mode 100644 index 0000000000..50ef04592c --- /dev/null +++ b/modules/core/perf/perf_lut.cpp @@ -0,0 +1,26 @@ +#include "perf_precomp.hpp" + +using namespace std; +using namespace cv; +using namespace perf; + +typedef perf::TestBaseWithParam SizePrm; + +PERF_TEST_P( SizePrm, LUT, + testing::Values(szQVGA, szVGA, sz1080p) + ) +{ + Size sz = GetParam(); + + int maxValue = 255; + + Mat src(sz, CV_8UC1); + randu(src, 0, maxValue); + Mat lut(1, 256, CV_8UC1); + randu(lut, 0, maxValue); + Mat dst(sz, CV_8UC1); + + TEST_CYCLE() LUT(src, lut, dst); + + SANITY_CHECK(dst, 0.1); +} diff --git a/modules/features2d/perf/perf_fast.cpp b/modules/features2d/perf/perf_fast.cpp index f706364004..709ae8296e 100644 --- a/modules/features2d/perf/perf_fast.cpp +++ b/modules/features2d/perf/perf_fast.cpp @@ -38,3 +38,26 @@ PERF_TEST_P(fast, detect, testing::Combine( SANITY_CHECK_KEYPOINTS(points); } + +PERF_TEST_P(fast, detect_ovx, testing::Combine( + testing::Values(FAST_IMAGES), + FastType::all() +)) +{ + string filename = getDataPath(get<0>(GetParam())); + int type = get<1>(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + + if (frame.empty()) + FAIL() << "Unable to load source image " << filename; + + declare.in(frame); + + Ptr fd = FastFeatureDetector::create(20, false, type); + ASSERT_FALSE(fd.empty()); + vector points; + + TEST_CYCLE() fd->detect(frame, points); + + SANITY_CHECK_KEYPOINTS(points); +} diff --git a/modules/imgproc/perf/perf_accumulate.cpp b/modules/imgproc/perf/perf_accumulate.cpp new file mode 100644 index 0000000000..fe2111ae88 --- /dev/null +++ b/modules/imgproc/perf/perf_accumulate.cpp @@ -0,0 +1,96 @@ +#include "perf_precomp.hpp" + +using namespace std; +using namespace cv; +using namespace perf; +using std::tr1::get; + +#ifdef HAVE_OPENVX +PERF_TEST_P(Size_MatType, Accumulate, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_16SC1, CV_32FC1) + ) +) +#else +PERF_TEST_P( Size_MatType, Accumulate, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_32FC1) + ) + ) +#endif +{ + Size sz = get<0>(GetParam()); + int dstType = get<1>(GetParam()); + + Mat src(sz, CV_8UC1); + Mat dst(sz, dstType); + + declare.time(100); + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() accumulate(src, dst); + + SANITY_CHECK(dst); +} + +#ifdef HAVE_OPENVX +PERF_TEST_P(Size_MatType, AccumulateSquare, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_16SC1, CV_32FC1) + ) +) +#else +PERF_TEST_P( Size_MatType, AccumulateSquare, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_32FC1) + ) + ) +#endif +{ + Size sz = get<0>(GetParam()); + int dstType = get<1>(GetParam()); + + Mat src(sz, CV_8UC1); + Mat dst(sz, dstType); + + declare.time(100); + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() accumulateSquare(src, dst); + + SANITY_CHECK(dst); +} + +#ifdef HAVE_OPENVX +PERF_TEST_P(Size_MatType, AccumulateWeighted, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_8UC1, CV_32FC1) + ) +) +#else +PERF_TEST_P( Size_MatType, AccumulateWeighted, + testing::Combine( + testing::Values(::perf::szODD, ::perf::szQVGA, ::perf::szVGA, ::perf::sz1080p), + testing::Values(CV_32FC1) + ) + ) +#endif +{ + Size sz = get<0>(GetParam()); + int dstType = get<1>(GetParam()); + + Mat src(sz, CV_8UC1); + Mat dst(sz, dstType); + + declare.time(100); + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() accumulateWeighted(src, dst, 0.314); + + SANITY_CHECK(dst); +} diff --git a/modules/imgproc/perf/perf_filter2d.cpp b/modules/imgproc/perf/perf_filter2d.cpp index 1eec745560..44c8d32cdb 100644 --- a/modules/imgproc/perf/perf_filter2d.cpp +++ b/modules/imgproc/perf/perf_filter2d.cpp @@ -42,6 +42,33 @@ PERF_TEST_P( TestFilter2d, Filter2d, SANITY_CHECK(dst, 1); } +PERF_TEST_P(TestFilter2d, Filter2d_ovx, + Combine( + Values(Size(320, 240), sz1080p), + Values(3, 5), + Values(BORDER_CONSTANT, BORDER_REPLICATE) + ) +) +{ + Size sz; + int borderMode, kSize; + sz = get<0>(GetParam()); + kSize = get<1>(GetParam()); + borderMode = get<2>(GetParam()); + + Mat src(sz, CV_8UC1); + Mat dst(sz, CV_16SC1); + + Mat kernel(kSize, kSize, CV_16SC1); + randu(kernel, -3, 10); + + declare.in(src, WARMUP_RNG).out(dst).time(20); + + TEST_CYCLE() filter2D(src, dst, CV_16SC1, kernel, Point(kSize / 2, kSize / 2), 0., borderMode); + + SANITY_CHECK(dst, 1); +} + PERF_TEST_P( Image_KernelSize, GaborFilter2d, Combine( Values("stitching/a1.png", "cv/shared/pic5.png"), diff --git a/modules/imgproc/perf/perf_pyramids.cpp b/modules/imgproc/perf/perf_pyramids.cpp index e23af8eade..6b5b7592b7 100644 --- a/modules/imgproc/perf/perf_pyramids.cpp +++ b/modules/imgproc/perf/perf_pyramids.cpp @@ -27,6 +27,27 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( SANITY_CHECK(dst, eps, error_type); } +PERF_TEST_P(Size_MatType, pyrDown_ovx, testing::Combine( + testing::Values(sz1080p, sz720p, szVGA, szQVGA, szODD), + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4, CV_32FC1, CV_32FC3, CV_32FC4) +) +) +{ + Size sz = get<0>(GetParam()); + int matType = get<1>(GetParam()); + const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; + perf::ERROR_TYPE error_type = CV_MAT_DEPTH(matType) <= CV_32S ? ERROR_ABSOLUTE : ERROR_RELATIVE; + + Mat src(sz, matType); + Mat dst((sz.height + 1) / 2, (sz.width + 1) / 2, matType); + + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() pyrDown(src, dst, cv::Size(), BORDER_REPLICATE); + + SANITY_CHECK(dst, eps, error_type); +} + PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( testing::Values(sz720p, szVGA, szQVGA, szODD), testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4, CV_32FC1, CV_32FC3, CV_32FC4) diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index 146528b6bb..dda5552d1e 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -50,6 +50,36 @@ PERF_TEST_P( TestWarpAffine, WarpAffine, #endif } +PERF_TEST_P(TestWarpAffine, WarpAffine_ovx, + Combine( + Values(szVGA, sz720p, sz1080p), + InterType::all(), + BorderMode::all() + ) +) +{ + Size sz, szSrc(512, 512); + int borderMode, interType; + sz = get<0>(GetParam()); + interType = get<1>(GetParam()); + borderMode = get<2>(GetParam()); + Scalar borderColor = Scalar::all(150); + + Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1); + cvtest::fillGradient(src); + if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1); + Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2); + declare.in(src).out(dst); + + TEST_CYCLE() warpAffine(src, dst, warpMat, sz, interType, borderMode, borderColor); + +#ifdef ANDROID + SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10); +#else + SANITY_CHECK(dst, 1); +#endif +} + PERF_TEST_P( TestWarpPerspective, WarpPerspective, Combine( Values( szVGA, sz720p, sz1080p ), @@ -88,6 +118,44 @@ PERF_TEST_P( TestWarpPerspective, WarpPerspective, #endif } +PERF_TEST_P(TestWarpPerspective, WarpPerspective_ovx, + Combine( + Values(szVGA, sz720p, sz1080p), + InterType::all(), + BorderMode::all() + ) +) +{ + Size sz, szSrc(512, 512); + int borderMode, interType; + sz = get<0>(GetParam()); + interType = get<1>(GetParam()); + borderMode = get<2>(GetParam()); + Scalar borderColor = Scalar::all(150); + + Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1); + cvtest::fillGradient(src); + if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1); + Mat rotMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2); + Mat warpMat(3, 3, CV_64FC1); + for (int r = 0; r<2; r++) + for (int c = 0; c<3; c++) + warpMat.at(r, c) = rotMat.at(r, c); + warpMat.at(2, 0) = .3 / sz.width; + warpMat.at(2, 1) = .3 / sz.height; + warpMat.at(2, 2) = 1; + + declare.in(src).out(dst); + + TEST_CYCLE() warpPerspective(src, dst, warpMat, sz, interType, borderMode, borderColor); + +#ifdef ANDROID + SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10); +#else + SANITY_CHECK(dst, 1); +#endif +} + PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear, Combine( Values( Size(640,480), Size(1920,1080), Size(2592,1944) ), diff --git a/modules/video/perf/perf_optflowpyrlk.cpp b/modules/video/perf/perf_optflowpyrlk.cpp index 08ffd04d4d..a17a0f318d 100644 --- a/modules/video/perf/perf_optflowpyrlk.cpp +++ b/modules/video/perf/perf_optflowpyrlk.cpp @@ -97,6 +97,58 @@ PERF_TEST_P(Path_Idx_Cn_NPoints_WSize, OpticalFlowPyrLK_full, testing::Combine( SANITY_CHECK(err, 2); } +typedef tr1::tuple, int> Path_Idx_NPoints_WSize_t; +typedef TestBaseWithParam Path_Idx_NPoints_WSize; + +PERF_TEST_P(Path_Idx_NPoints_WSize, OpticalFlowPyrLK_ovx, testing::Combine( + testing::Values("cv/optflow/frames/VGA_%02d.png", "cv/optflow/frames/720p_%02d.png"), + testing::Range(1, 3), + testing::Values(make_tuple(9, 9), make_tuple(15, 15)), + testing::Values(7, 11) + ) + ) +{ + string filename1 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam()))); + string filename2 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam()) + 1)); + Mat img1 = imread(filename1); + Mat img2 = imread(filename2); + if (img1.empty()) FAIL() << "Unable to load source image " << filename1; + if (img2.empty()) FAIL() << "Unable to load source image " << filename2; + + int nPointsX = min(get<0>(get<2>(GetParam())), img1.cols); + int nPointsY = min(get<1>(get<2>(GetParam())), img1.rows); + int winSize = get<3>(GetParam()); + + int maxLevel = 2; + TermCriteria criteria(TermCriteria::COUNT|TermCriteria::EPS, 7, 0.001); + int flags = 0; + double minEigThreshold = 1e-4; + + Mat frame1, frame2; + cvtColor(img1, frame1, COLOR_BGR2GRAY, 1); + cvtColor(img2, frame2, COLOR_BGR2GRAY, 1); + + vector inPoints; + vector outPoints; + vector status; + + FormTrackingPointsArray(inPoints, frame1.cols, frame1.rows, nPointsX, nPointsY); + outPoints.resize(inPoints.size()); + status.resize(inPoints.size()); + + declare.in(frame1, frame2, inPoints).out(outPoints); + + TEST_CYCLE_N(30) + { + calcOpticalFlowPyrLK(frame1, frame2, inPoints, outPoints, status, cv::noArray(), + Size(winSize, winSize), maxLevel, criteria, + flags, minEigThreshold); + } + + SANITY_CHECK(outPoints, 0.3); + SANITY_CHECK(status); +} + typedef tr1::tuple, int, bool> Path_Idx_Cn_NPoints_WSize_Deriv_t; typedef TestBaseWithParam Path_Idx_Cn_NPoints_WSize_Deriv;