From c4e271c2dc09c287a1940b3e57b93742bc9abf03 Mon Sep 17 00:00:00 2001 From: Arne Baeyens Date: Sat, 22 Aug 2026 19:12:05 +0200 Subject: [PATCH] imgwarp add perf tests where src img much smaller then dst img + transparent border As the existing perf tests don't cover this use case well. Did not do the CONSTANT border type because for that use case the source image is usually projected over about the whole of the destination image so our ROI optimization wouldn't deliver much user value there. Signed-off-by: Arne Baeyens --- modules/imgproc/perf/perf_warp.cpp | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index cb4c32c905..91c24e4699 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -16,6 +16,8 @@ typedef TestBaseWithParam< tuple > TestWar typedef TestBaseWithParam< tuple > TestWarpPerspective; typedef TestBaseWithParam< tuple > TestWarpPerspectiveNear_t; typedef TestBaseWithParam< tuple > TestRemap; +typedef TestBaseWithParam< tuple > TestWarpAffineSmallSrc; +typedef TestBaseWithParam< tuple > TestWarpPerspectiveSmallSrc; void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode, bool relative = false ); @@ -307,4 +309,61 @@ PERF_TEST(Transform, getPerspectiveTransform_QR_1000) SANITY_CHECK_NOTHING(); } +PERF_TEST_P( TestWarpAffineSmallSrc, WarpAffine_SmallSrc, + Combine( + Values(CV_8UC1, CV_8UC4), + Values( Size(512, 512) ), + InterType::all() + ) +) +{ + const Size szSrc(64, 64); + const int dataType = get<0>(GetParam()); + const Size sz = get<1>(GetParam()); + const int interType = get<2>(GetParam()); + const int borderMode = BORDER_TRANSPARENT; + + Mat src(szSrc, dataType), dst(sz, dataType, Scalar::all(0)); + cvtest::fillGradient(src); + + const double offset = (sz.width - szSrc.width) / 2.0; + const Mat warpMat = (Mat_(2, 3) << 1, 0, offset, + 0, 1, offset); + declare.in(src).out(dst); + + TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode ); + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P( TestWarpPerspectiveSmallSrc, WarpPerspective_SmallSrc, + Combine( + Values(CV_8UC1, CV_8UC4), + Values( Size(512, 512) ), + InterType::all() + ) +) +{ + const Size szSrc(64, 64); + const int dataType = get<0>(GetParam()); + const Size sz = get<1>(GetParam()); + const int interType = get<2>(GetParam()); + const int borderMode = BORDER_TRANSPARENT; + + Mat src(szSrc, dataType), dst(sz, dataType, Scalar::all(0)); + cvtest::fillGradient(src); + + const float w = (float)szSrc.width, h = (float)szSrc.height; + const float off = (sz.width - szSrc.width) / 2.0f; + const Point2f sp[] = { Point2f(0, 0), Point2f(w, 0), Point2f(0, h), Point2f(w, h) }; + const Point2f dp[] = { Point2f(off, off), Point2f(off + w, off), + Point2f(off, off + h), Point2f(off + w, off + h) }; + const Mat warpMat = getPerspectiveTransform(sp, dp); + declare.in(src).out(dst); + + TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode ); + + SANITY_CHECK_NOTHING(); +} + } // namespace