From d044ac1c66c4325911cb843b4eb42929a45d1b9f Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 18 Jul 2018 15:03:51 +0300 Subject: [PATCH] imgproc(getPerspectiveTransform): add solveMethod parameter drop compatibility workaround via runtime parameter --- modules/imgproc/include/opencv2/imgproc.hpp | 10 ++++++---- modules/imgproc/perf/perf_warp.cpp | 19 +++++++++++++++++++ modules/imgproc/src/imgwarp.cpp | 10 ++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index b03deba..e32a41a 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -2359,9 +2359,6 @@ coordinate origin is assumed to be the top-left corner). */ CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale ); -//! returns 3x3 perspective transformation for the corresponding 4 point pairs. -CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] ); - /** @brief Calculates an affine transform from three pairs of the corresponding points. The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that: @@ -2404,10 +2401,15 @@ where @param src Coordinates of quadrangle vertices in the source image. @param dst Coordinates of the corresponding quadrangle vertices in the destination image. +@param solveMethod method passed to cv::solve (#DecompTypes) @sa findHomography, warpPerspective, perspectiveTransform */ -CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst ); +CV_EXPORTS_W Mat getPerspectiveTransform(InputArray src, InputArray dst, int solveMethod = DECOMP_LU); + +/** @overload */ +CV_EXPORTS Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod = DECOMP_LU); + CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index b51e9ae..cb974e9 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -290,4 +290,23 @@ PERF_TEST(Transform, getPerspectiveTransform_1000) SANITY_CHECK_NOTHING(); } +PERF_TEST(Transform, getPerspectiveTransform_QR_1000) +{ + unsigned int size = 8; + Mat source(1, size/2, CV_32FC2); + Mat destination(1, size/2, CV_32FC2); + Mat transformCoefficient; + + declare.in(source, destination, WARMUP_RNG); + + PERF_SAMPLE_BEGIN() + for (int i = 0; i < 1000; i++) + { + transformCoefficient = getPerspectiveTransform(source, destination, DECOMP_QR); + } + PERF_SAMPLE_END() + + SANITY_CHECK_NOTHING(); +} + } // namespace diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index ad090fd..7c8388b 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -3039,7 +3039,7 @@ cv::Mat cv::getRotationMatrix2D( Point2f center, double angle, double scale ) * where: * cij - matrix coefficients, c22 = 1 */ -cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] ) +cv::Mat cv::getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod) { CV_INSTRUMENT_REGION() @@ -3062,9 +3062,7 @@ cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] ) b[i+4] = dst[i].y; } - static int param_IMGPROC_GETPERSPECTIVETRANSFORM_SOLVE_METHOD = - (int)utils::getConfigurationParameterSizeT("OPENCV_IMGPROC_GETPERSPECTIVETRANSFORM_SOLVE_METHOD", (size_t)DECOMP_LU); - solve(A, B, X, param_IMGPROC_GETPERSPECTIVETRANSFORM_SOLVE_METHOD); + solve(A, B, X, solveMethod); M.ptr()[8] = 1.; return M; @@ -3153,11 +3151,11 @@ void cv::invertAffineTransform(InputArray _matM, OutputArray __iM) CV_Error( CV_StsUnsupportedFormat, "" ); } -cv::Mat cv::getPerspectiveTransform(InputArray _src, InputArray _dst) +cv::Mat cv::getPerspectiveTransform(InputArray _src, InputArray _dst, int solveMethod) { Mat src = _src.getMat(), dst = _dst.getMat(); CV_Assert(src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4); - return getPerspectiveTransform((const Point2f*)src.data, (const Point2f*)dst.data); + return getPerspectiveTransform((const Point2f*)src.data, (const Point2f*)dst.data, solveMethod); } cv::Mat cv::getAffineTransform(InputArray _src, InputArray _dst) -- 2.7.4