From fce4a19d0d9576bf78b86c7f22684eda58e6d9c8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 16 Oct 2021 14:24:50 +0300 Subject: [PATCH] 5.x: cleanup compatibility code (2021-10) --- modules/3d/include/opencv2/3d.hpp | 18 ----------- modules/3d/src/five-point.cpp | 18 +---------- modules/3d/test/test_fundam.cpp | 2 +- modules/3d/test/test_usac.cpp | 2 +- modules/calib/test/test_cameracalibration.cpp | 4 +-- modules/core/include/opencv2/core/mat.hpp | 31 ++++++------------- modules/core/include/opencv2/core/mat.inl.hpp | 16 ---------- modules/core/include/opencv2/core/ocl.hpp | 7 +---- modules/core/src/ocl.cpp | 25 ++------------- modules/core/src/ocl_disabled.impl.hpp | 2 +- modules/core/src/va_intel.cpp | 2 +- .../dnn/src/int8layers/quantization_utils.cpp | 6 ++-- modules/features2d/src/blobdetector.cpp | 5 --- modules/imgproc/src/histogram.cpp | 8 +++-- samples/cpp/essential_mat_reconstr.cpp | 2 +- 15 files changed, 30 insertions(+), 118 deletions(-) diff --git a/modules/3d/include/opencv2/3d.hpp b/modules/3d/include/opencv2/3d.hpp index 82ba5e2cdb..4c7aea7f28 100644 --- a/modules/3d/include/opencv2/3d.hpp +++ b/modules/3d/include/opencv2/3d.hpp @@ -1476,15 +1476,6 @@ Mat findEssentialMat( int maxIters = 1000, OutputArray mask = noArray() ); -/** @overload */ -CV_EXPORTS -Mat findEssentialMat( - InputArray points1, InputArray points2, - InputArray cameraMatrix, int method, - double prob, double threshold, - OutputArray mask -); // TODO remove from OpenCV 5.0 - /** @overload @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should be floating-point (single or double precision). @@ -1524,15 +1515,6 @@ Mat findEssentialMat( OutputArray mask = noArray() ); -/** @overload */ -CV_EXPORTS -Mat findEssentialMat( - InputArray points1, InputArray points2, - double focal, Point2d pp, - int method, double prob, - double threshold, OutputArray mask -); // TODO remove from OpenCV 5.0 - /** @brief Calculates an essential matrix from the corresponding points in two images from potentially two different cameras. @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should diff --git a/modules/3d/src/five-point.cpp b/modules/3d/src/five-point.cpp index 746df74423..a0bec4d7f6 100644 --- a/modules/3d/src/five-point.cpp +++ b/modules/3d/src/five-point.cpp @@ -420,7 +420,7 @@ static Mat findEssentialMat_( InputArray _points1, InputArray _points2, transform(_points1, _pointsTransformed1, affine); transform(_points2, _pointsTransformed2, affine); - return findEssentialMat(_pointsTransformed1, _pointsTransformed2, cm0, method, prob, threshold, _mask); + return findEssentialMat(_pointsTransformed1, _pointsTransformed2, cm0, method, prob, threshold, 1000/*maxIters*/, _mask); } @@ -477,13 +477,6 @@ Mat findEssentialMat( InputArray _points1, InputArray _points2, InputArray _came return E; } -Mat findEssentialMat( InputArray _points1, InputArray _points2, InputArray _cameraMatrix, - int method, double prob, double threshold, - OutputArray _mask) -{ - return findEssentialMat(_points1, _points2, _cameraMatrix, method, prob, threshold, 1000, _mask); -} - Mat findEssentialMat( InputArray _points1, InputArray _points2, double focal, Point2d pp, int method, double prob, double threshold, int maxIters, OutputArray _mask) { @@ -493,15 +486,6 @@ Mat findEssentialMat( InputArray _points1, InputArray _points2, double focal, Po return findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, maxIters, _mask); } -Mat findEssentialMat( InputArray _points1, InputArray _points2, double focal, Point2d pp, - int method, double prob, double threshold, OutputArray _mask) -{ - CV_INSTRUMENT_REGION(); - - Mat cameraMatrix = (Mat_(3,3) << focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1); - return findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, 1000, _mask); -} - Mat findEssentialMat( InputArray _points1, InputArray _points2, InputArray cameraMatrix1, InputArray distCoeffs1, InputArray cameraMatrix2, InputArray distCoeffs2, diff --git a/modules/3d/test/test_fundam.cpp b/modules/3d/test/test_fundam.cpp index 92d383f1a2..925b5429a2 100644 --- a/modules/3d/test/test_fundam.cpp +++ b/modules/3d/test/test_fundam.cpp @@ -1267,7 +1267,7 @@ void CV_EssentialMatTest::run_func() RNG& rng = ts->get_rng(); Mat E, mask1(test_mat[TEMP][1]); - E = cv::findEssentialMat( _input0, _input1, focal, pp, method, 0.99, MAX(sigma*3, 0.0001), mask1 ); + E = cv::findEssentialMat( _input0, _input1, focal, pp, method, 0.99, MAX(sigma*3, 0.0001), 1000/*maxIters*/, mask1 ); if (E.rows > 3) { int count = E.rows / 3; diff --git a/modules/3d/test/test_usac.cpp b/modules/3d/test/test_usac.cpp index 6e6d8cecf3..4058d12a1d 100644 --- a/modules/3d/test/test_usac.cpp +++ b/modules/3d/test/test_usac.cpp @@ -315,7 +315,7 @@ TEST(usac_Essential, accuracy) { for (auto flag : flags) { cv::Mat mask, E; try { - E = cv::findEssentialMat(pts1, pts2, K1, flag, conf, thr, mask); + E = cv::findEssentialMat(pts1, pts2, K1, flag, conf, thr, 1000/*maxIters*/, mask); } catch (cv::Exception &e) { if (e.code != cv::Error::StsNotImplemented) FAIL() << "Essential matrix estimation failed!\n"; diff --git a/modules/calib/test/test_cameracalibration.cpp b/modules/calib/test/test_cameracalibration.cpp index 60a4f91414..c5608faaef 100644 --- a/modules/calib/test/test_cameracalibration.cpp +++ b/modules/calib/test/test_cameracalibration.cpp @@ -2182,7 +2182,7 @@ TEST(CV_RecoverPoseTest, regression_15341) } // Check pose when camera matrices are the same. - E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask); + E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, 1000/*maxIters*/, mask); E2 = findEssentialMat(points1, points2, cameraMatrix, zeroDistCoeffs, cameraMatrix, zeroDistCoeffs, RANSAC, 0.999, 1.0, mask); EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) << "Two big difference between the same essential matrices computed using different functions with same cameras, testcase " << testcase; @@ -2221,7 +2221,7 @@ TEST(CV_RecoverPoseTest, regression_15341) } // Check pose when camera matrices are the same. - E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask); + E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, 1000/*maxIters*/, mask); E2 = findEssentialMat(points1, points2, cameraMatrix, zeroDistCoeffs, cameraMatrix, zeroDistCoeffs, RANSAC, 0.999, 1.0, mask); EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) << "Two big difference between the same essential matrices computed using different functions with same cameras, testcase " << testcase; diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 93a2bc1bda..e39f229f6e 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -2423,10 +2423,6 @@ public: UMat(const UMat& m, const Range* ranges); UMat(const UMat& m, const std::vector& ranges); - // FIXIT copyData=false is not implemented, drop this in favor of cv::Mat (OpenCV 5.0) - //! builds matrix from std::vector with or without copying the data - template explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); - //! destructor - calls release() ~UMat(); //! assignment operators @@ -2450,8 +2446,7 @@ public: //! <0 - a diagonal from the lower half) UMat diag(int d=0) const; //! constructs a square diagonal matrix which main diagonal is vector "d" - CV_NODISCARD_STD static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + CV_NODISCARD_STD static UMat diag(const UMat& d, UMatUsageFlags usageFlags = USAGE_DEFAULT); //! returns deep copy of the matrix, i.e. the data is copied CV_NODISCARD_STD UMat clone() const; @@ -2485,22 +2480,14 @@ public: double dot(InputArray m) const; //! Matlab-style matrix initialization - CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); - CV_NODISCARD_STD static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload - CV_NODISCARD_STD static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat zeros(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat ones(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat eye(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); //! allocates new matrix data unless the matrix already has specified size and type. // previous data is unreferenced if needed. diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 886b82c6a0..c6db72f267 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -3246,22 +3246,6 @@ const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) //////////////////////////////// UMat //////////////////////////////// -template inline -UMat::UMat(const std::vector<_Tp>& vec, bool copyData) -: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), -cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) -{ - if(vec.empty()) - return; - if( !copyData ) - { - // !!!TODO!!! - CV_Error(Error::StsNotImplemented, ""); - } - else - Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); -} - inline UMat UMat::row(int y) const { diff --git a/modules/core/include/opencv2/core/ocl.hpp b/modules/core/include/opencv2/core/ocl.hpp index 4503fa00dd..86ee63048b 100644 --- a/modules/core/include/opencv2/core/ocl.hpp +++ b/modules/core/include/opencv2/core/ocl.hpp @@ -274,11 +274,7 @@ public: /** Get thread-local OpenCL context (initialize if necessary) */ -#if 0 // OpenCV 5.0 static Context& getDefault(); -#else - static Context& getDefault(bool initialize = true); -#endif /** @returns cl_context value */ void* ptr() const; @@ -320,8 +316,7 @@ public: struct Impl; inline Impl* getImpl() const { return (Impl*)p; } inline bool empty() const { return !p; } -// TODO OpenCV 5.0 -//protected: +protected: Impl* p; }; diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 8e545f6293..b902a571b0 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2985,7 +2985,7 @@ Device& Context::device(size_t idx) const return !p || idx >= p->devices.size() ? dummy : p->devices[idx]; } -Context& Context::getDefault(bool initialize) +Context& Context::getDefault() { auto& c = OpenCLExecutionContext::getCurrent(); if (!c.empty()) @@ -2994,7 +2994,6 @@ Context& Context::getDefault(bool initialize) return ctx; } - CV_UNUSED(initialize); static Context dummy; return dummy; } @@ -3864,18 +3863,6 @@ bool Kernel::run_(int dims, size_t _globalsize[], size_t _localsize[], } -static bool isRaiseErrorOnReuseAsyncKernel() -{ - static bool initialized = false; - static bool value = false; - if (!initialized) - { - value = cv::utils::getConfigurationParameterBool("OPENCV_OPENCL_RAISE_ERROR_REUSE_ASYNC_KERNEL", false); - initialized = true; - } - return value; -} - bool Kernel::Impl::run(int dims, size_t globalsize[], size_t localsize[], bool sync, int64* timeNS, const Queue& q) { @@ -3889,19 +3876,13 @@ bool Kernel::Impl::run(int dims, size_t globalsize[], size_t localsize[], if (isAsyncRun) { - CV_LOG_ERROR(NULL, "OpenCL kernel can't be reused in async mode: " << name); - if (isRaiseErrorOnReuseAsyncKernel()) - CV_Assert(0); - return false; // OpenCV 5.0: raise error + CV_Error_(Error::StsError, ("OpenCL kernel can't be reused in async mode: %s", name.c_str())); } isAsyncRun = !sync; if (isInProgress) { - CV_LOG_ERROR(NULL, "Previous OpenCL kernel launch is not finished: " << name); - if (isRaiseErrorOnReuseAsyncKernel()) - CV_Assert(0); - return false; // OpenCV 5.0: raise error + CV_Error_(Error::StsError, ("Previous OpenCL kernel launch is not finished: %s", name.c_str())); } #if CV_OPENCL_SYNC_RUN_KERNELS diff --git a/modules/core/src/ocl_disabled.impl.hpp b/modules/core/src/ocl_disabled.impl.hpp index a217979a1e..5149ee1552 100644 --- a/modules/core/src/ocl_disabled.impl.hpp +++ b/modules/core/src/ocl_disabled.impl.hpp @@ -165,7 +165,7 @@ Program Context::getProg(const ProgramSource& prog, const String& buildopt, Stri void Context::unloadProg(Program& prog) { } /* static */ -Context& Context::getDefault(bool initialize) +Context& Context::getDefault() { static Context dummy; return dummy; diff --git a/modules/core/src/va_intel.cpp b/modules/core/src/va_intel.cpp index a7623c37f4..acc502d0f5 100644 --- a/modules/core/src/va_intel.cpp +++ b/modules/core/src/va_intel.cpp @@ -178,7 +178,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop) } # endif // HAVE_VA_INTEL { - Context& ctx = Context::getDefault(true); + Context& ctx = Context::getDefault(); return ctx; } #endif // !HAVE_VA diff --git a/modules/dnn/src/int8layers/quantization_utils.cpp b/modules/dnn/src/int8layers/quantization_utils.cpp index 0346f147ba..d72487639e 100644 --- a/modules/dnn/src/int8layers/quantization_utils.cpp +++ b/modules/dnn/src/int8layers/quantization_utils.cpp @@ -52,9 +52,9 @@ public: if (inputs_.depth() == CV_16S) { - UMat inputFp32(shape(inputs[0]), CV_32F); + UMat inputFp32; convertFp16(inputs[0], inputFp32); - inputFp32.copyTo(inputs[0]); + inputs[0] = inputFp32; // replace } inputs[0].convertTo(outputs[0], CV_8S, 1.f/scale, zeropoint); @@ -118,7 +118,7 @@ public: inputs_.getUMatVector(inputs); outputs_.getUMatVector(outputs); - UMat outputFp32(shape(outputs[0]), CV_32F); + UMat outputFp32; inputs[0].convertTo(outputFp32, CV_32F, scale, -(scale*zeropoint)); if (outputs_.depth() == CV_16S) diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index fb79831807..f40bbf22f9 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -324,12 +324,7 @@ void SimpleBlobDetectorImpl::detect(InputArray image, std::vector& { // https://github.com/opencv/opencv/issues/6667 CV_LOG_ONCE_INFO(NULL, "SimpleBlobDetector: params.minDistBetweenBlobs is ignored for case with single threshold"); -#if 0 // OpenCV 5.0 CV_CheckEQ(params.minRepeatability, 1u, "Incompatible parameters for case with single threshold"); -#else - if (params.minRepeatability != 1) - CV_LOG_WARNING(NULL, "SimpleBlobDetector: params.minRepeatability=" << params.minRepeatability << " is incompatible for case with single threshold. Empty result is expected."); -#endif } std::vector < std::vector
> centers; diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index 048e27aa29..5d05897805 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -1883,7 +1883,9 @@ static bool ocl_calcBackProject( InputArrayOfArrays _images, std::vector ch return false; size_t lsize = 256; - UMat lut(1, (int)lsize, CV_32SC1), hist = _hist.getUMat(), uranges(ranges, true); + UMat lut(1, (int)lsize, CV_32SC1); + UMat hist = _hist.getUMat(); + UMat uranges; Mat(ranges, false).copyTo(uranges); lutk.args(ocl::KernelArg::ReadOnlyNoSize(hist), hist.rows, ocl::KernelArg::PtrWriteOnly(lut), scale, ocl::KernelArg::PtrReadOnly(uranges)); @@ -1919,7 +1921,9 @@ static bool ocl_calcBackProject( InputArrayOfArrays _images, std::vector ch return false; size_t lsize = 256; - UMat lut(1, (int)lsize<<1, CV_32SC1), uranges(ranges, true), hist = _hist.getUMat(); + UMat lut(1, (int)lsize<<1, CV_32SC1); + UMat hist = _hist.getUMat(); + UMat uranges; Mat(ranges, false).copyTo(uranges); lutk1.args(hist.rows, ocl::KernelArg::PtrWriteOnly(lut), (int)0, ocl::KernelArg::PtrReadOnly(uranges), (int)0); if (!lutk1.run(1, &lsize, NULL, false)) diff --git a/samples/cpp/essential_mat_reconstr.cpp b/samples/cpp/essential_mat_reconstr.cpp index b93bdb29d6..5bb19cfbcb 100644 --- a/samples/cpp/essential_mat_reconstr.cpp +++ b/samples/cpp/essential_mat_reconstr.cpp @@ -251,7 +251,7 @@ int main(int args, char** argv) { const int pts_size = (int) pts1.size(); const auto begin_time = std::chrono::steady_clock::now(); // fine essential matrix - const Mat E = findEssentialMat(pts1, pts2, Mat(K), RANSAC, 0.99, 1.0, inliers); + const Mat E = findEssentialMat(pts1, pts2, Mat(K), RANSAC, 0.99, 1.0, 1000/*maxIters*/, inliers); std::cout << "RANSAC essential matrix time " << std::chrono::duration_cast (std::chrono::steady_clock::now() - begin_time).count() << "mcs.\nNumber of inliers " << countNonZero(inliers) << "\n";