5.x: cleanup compatibility code (2021-10)

This commit is contained in:
Alexander Alekhin 2021-10-16 14:24:50 +03:00
parent 7ba26ada12
commit fce4a19d0d
15 changed files with 30 additions and 118 deletions

View File

@ -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

View File

@ -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_<double>(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,

View File

@ -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;

View File

@ -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";

View File

@ -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;

View File

@ -2423,10 +2423,6 @@ public:
UMat(const UMat& m, const Range* ranges);
UMat(const UMat& m, const std::vector<Range>& 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<typename _Tp> 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.

View File

@ -3246,22 +3246,6 @@ const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b)
//////////////////////////////// UMat ////////////////////////////////
template<typename _Tp> 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
{

View File

@ -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;
};

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -324,12 +324,7 @@ void SimpleBlobDetectorImpl::detect(InputArray image, std::vector<cv::KeyPoint>&
{
// 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<Center> > centers;

View File

@ -1883,7 +1883,9 @@ static bool ocl_calcBackProject( InputArrayOfArrays _images, std::vector<int> 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<int> 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))

View File

@ -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::microseconds>
(std::chrono::steady_clock::now() - begin_time).count() <<
"mcs.\nNumber of inliers " << countNonZero(inliers) << "\n";