vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:11:13 +08:00
commit 12022378a3
3872 changed files with 2513409 additions and 0 deletions
+182
View File
@@ -0,0 +1,182 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_TEST_INTERPOLATION_HPP__
#define __OPENCV_TEST_INTERPOLATION_HPP__
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
template <typename T> T readVal(const cv::Mat& src, int y, int x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
if (border_type == cv::BORDER_CONSTANT)
return (y >= 0 && y < src.rows && x >= 0 && x < src.cols) ? src.at<T>(y, x * src.channels() + c) : cv::saturate_cast<T>(borderVal.val[c]);
return src.at<T>(cv::borderInterpolate(y, src.rows, border_type), cv::borderInterpolate(x, src.cols, border_type) * src.channels() + c);
}
template <typename T> struct NearestInterpolator
{
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
return readVal<T>(src, int(y), int(x), c, border_type, borderVal);
}
};
template <typename T> struct LinearInterpolator
{
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
int x1 = cvFloor(x);
int y1 = cvFloor(y);
int x2 = x1 + 1;
int y2 = y1 + 1;
float res = 0;
res += readVal<T>(src, y1, x1, c, border_type, borderVal) * ((x2 - x) * (y2 - y));
res += readVal<T>(src, y1, x2, c, border_type, borderVal) * ((x - x1) * (y2 - y));
res += readVal<T>(src, y2, x1, c, border_type, borderVal) * ((x2 - x) * (y - y1));
res += readVal<T>(src, y2, x2, c, border_type, borderVal) * ((x - x1) * (y - y1));
return cv::saturate_cast<T>(res);
}
};
template <typename T> struct CubicInterpolator
{
static float bicubicCoeff(float x_)
{
float x = fabsf(x_);
if (x <= 1.0f)
{
return x * x * (1.5f * x - 2.5f) + 1.0f;
}
else if (x < 2.0f)
{
return x * (x * (-0.5f * x + 2.5f) - 4.0f) + 2.0f;
}
else
{
return 0.0f;
}
}
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
const float xmin = ceilf(x - 2.0f);
const float xmax = floorf(x + 2.0f);
const float ymin = ceilf(y - 2.0f);
const float ymax = floorf(y + 2.0f);
float sum = 0.0f;
float wsum = 0.0f;
for (float cy = ymin; cy <= ymax; cy += 1.0f)
{
for (float cx = xmin; cx <= xmax; cx += 1.0f)
{
const float w = bicubicCoeff(x - cx) * bicubicCoeff(y - cy);
sum += w * readVal<T>(src, (int) floorf(cy), (int) floorf(cx), c, border_type, borderVal);
wsum += w;
}
}
float res = (!wsum)? 0 : sum / wsum;
return cv::saturate_cast<T>(res);
}
};
template <typename T> struct LanczosInterpolator
{
static constexpr int A = 4;
static float lanczosCoeff(float x_)
{
float x = fabsf(x_);
if (x == 0.0f)
return 1.0f;
if (x >= A)
return 0.0f;
float pi_x = CV_PI * x;
return sinf(pi_x) * sinf(pi_x / A) / (pi_x * pi_x / A);
}
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
const int xmin = (int) floorf(x) - A + 1;
const int xmax = (int) floorf(x) + A;
const int ymin = (int) floorf(y) - A + 1;
const int ymax = (int) floorf(y) + A;
float sum = 0.0f;
float wsum = 0.0f;
for (int cy = ymin; cy <= ymax; ++cy)
{
float wy = lanczosCoeff(y - cy);
if (wy == 0.0f)
continue;
for (int cx = xmin; cx <= xmax; ++cx)
{
float wx = lanczosCoeff(x - cx);
if (wx == 0.0f)
continue;
const float w = wy * wx;
sum += w * readVal<T>(src, cy, cx, c, border_type, borderVal);
wsum += w;
}
}
float res = (!wsum)? 0 : sum / wsum;
return cv::saturate_cast<T>(res);
}
};
#endif // __OPENCV_TEST_INTERPOLATION_HPP__
+155
View File
@@ -0,0 +1,155 @@
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
///////////////////////////////////////////////////////////////////
// Gold implementation
namespace
{
template <typename T>
void resizeLanczosImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
{
const int cn = src.channels();
cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy));
dst.create(dsize, src.type());
float ifx = static_cast<float>(1.0 / fx);
float ify = static_cast<float>(1.0 / fy);
// OpenCV CPU resize uses center-aligned coordinate mapping: (x + 0.5) * fx - 0.5
// Since fx and fy here are scale factors, and ifx = 1.0 / fx, ify = 1.0 / fy,
// the center-aligned mapping becomes: (x + 0.5) / fx - 0.5 = (x + 0.5) * ifx - 0.5
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
for (int c = 0; c < cn; ++c)
{
float src_x = (static_cast<float>(x) + 0.5f) * ifx - 0.5f;
float src_y = (static_cast<float>(y) + 0.5f) * ify - 0.5f;
dst.at<T>(y, x * cn + c) = LanczosInterpolator<T>::getValue(src, src_y, src_x, c, cv::BORDER_REPLICATE);
}
}
}
}
void resizeLanczosGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
{
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy);
static const func_t lanczos_funcs[] =
{
resizeLanczosImpl<unsigned char>,
resizeLanczosImpl<signed char>,
resizeLanczosImpl<unsigned short>,
resizeLanczosImpl<short>,
resizeLanczosImpl<int>,
resizeLanczosImpl<float>
};
lanczos_funcs[src.depth()](src, dst, fx, fy);
}
}
///////////////////////////////////////////////////////////////////
// Test
PARAM_TEST_CASE(ResizeLanczos, cv::cuda::DeviceInfo, cv::Size, MatType, double, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
double coeff;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
coeff = GET_PARAM(3);
useRoi = GET_PARAM(4);
cv::cuda::setDevice(devInfo.deviceID());
}
virtual void TearDown()
{
// GpuMat destructors will automatically clean up GPU memory
}
};
CUDA_TEST_P(ResizeLanczos, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::cuda::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, cv::INTER_LANCZOS4);
cv::Mat dst_gold;
resizeLanczosGold(src, dst_gold, coeff, coeff);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, ResizeLanczos, testing::Combine(
testing::Values(cv::cuda::DeviceInfo()),
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5, 1.5, 2.0),
WHOLE_SUBMAT));
/////////////////
PARAM_TEST_CASE(ResizeLanczosSameAsHost, cv::cuda::DeviceInfo, cv::Size, MatType, double, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
double coeff;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
coeff = GET_PARAM(3);
useRoi = GET_PARAM(4);
cv::cuda::setDevice(devInfo.deviceID());
}
virtual void TearDown()
{
// GpuMat destructors will automatically clean up GPU memory
}
};
CUDA_TEST_P(ResizeLanczosSameAsHost, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::cuda::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, cv::INTER_LANCZOS4);
cv::Mat dst_gold;
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, cv::INTER_LANCZOS4);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, ResizeLanczosSameAsHost, testing::Combine(
testing::Values(cv::cuda::DeviceInfo()),
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5, 1.5, 2.0),
WHOLE_SUBMAT));
}} // namespace
#endif // HAVE_CUDA
+45
View File
@@ -0,0 +1,45 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
CV_CUDA_TEST_MAIN("gpu")
+57
View File
@@ -0,0 +1,57 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include <thread>
#include "opencv2/ts.hpp"
#include "opencv2/ts/cuda_test.hpp"
#include "opencv2/cudawarping.hpp"
#include "opencv2/geometry.hpp"
#include "cvconfig.h"
#include "interpolation.hpp"
#endif
+131
View File
@@ -0,0 +1,131 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
////////////////////////////////////////////////////////
// pyrDown
PARAM_TEST_CASE(PyrDown, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(PyrDown, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size((size.width + 1) / 2, (size.height + 1) / 2), type, useRoi);
cv::cuda::pyrDown(loadMat(src, useRoi), dst);
cv::Mat dst_gold;
cv::pyrDown(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, PyrDown, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
WHOLE_SUBMAT));
////////////////////////////////////////////////////////
// pyrUp
PARAM_TEST_CASE(PyrUp, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(PyrUp, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size(size.width * 2, size.height * 2), type, useRoi);
cv::cuda::pyrUp(loadMat(src, useRoi), dst);
cv::Mat dst_gold;
cv::pyrUp(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, PyrUp, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
WHOLE_SUBMAT));
}} // namespace
#endif // HAVE_CUDA
+285
View File
@@ -0,0 +1,285 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#include "opencv2/core/matx.hpp"
#include "nppdefs.h"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
///////////////////////////////////////////////////////////////////
// Gold implementation
namespace
{
template <typename T, template <typename> class Interpolator> void remapImpl(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal)
{
const int cn = src.channels();
cv::Size dsize = xmap.size();
dst.create(dsize, src.type());
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
for (int c = 0; c < cn; ++c)
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ymap.at<float>(y, x), xmap.at<float>(y, x), c, borderType, borderVal);
}
}
}
void remapGold(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
{
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal);
static const func_t nearest_funcs[] =
{
remapImpl<unsigned char, NearestInterpolator>,
remapImpl<signed char, NearestInterpolator>,
remapImpl<unsigned short, NearestInterpolator>,
remapImpl<short, NearestInterpolator>,
remapImpl<int, NearestInterpolator>,
remapImpl<float, NearestInterpolator>
};
static const func_t linear_funcs[] =
{
remapImpl<unsigned char, LinearInterpolator>,
remapImpl<signed char, LinearInterpolator>,
remapImpl<unsigned short, LinearInterpolator>,
remapImpl<short, LinearInterpolator>,
remapImpl<int, LinearInterpolator>,
remapImpl<float, LinearInterpolator>
};
static const func_t cubic_funcs[] =
{
remapImpl<unsigned char, CubicInterpolator>,
remapImpl<signed char, CubicInterpolator>,
remapImpl<unsigned short, CubicInterpolator>,
remapImpl<short, CubicInterpolator>,
remapImpl<int, CubicInterpolator>,
remapImpl<float, CubicInterpolator>
};
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
funcs[interpolation][src.depth()](src, xmap, ymap, dst, borderType, borderVal);
}
}
///////////////////////////////////////////////////////////////////
// Test
PARAM_TEST_CASE(Remap, cv::cuda::DeviceInfo, cv::Size, MatType, Interpolation, BorderType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
int type;
int interpolation;
int borderType;
bool useRoi;
cv::Mat xmap;
cv::Mat ymap;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
interpolation = GET_PARAM(3);
borderType = GET_PARAM(4);
useRoi = GET_PARAM(5);
cv::cuda::setDevice(devInfo.deviceID());
// rotation matrix
const double aplha = CV_PI / 4;
static double M[2][3] = { {std::cos(aplha), -std::sin(aplha), size.width / 2.0},
{std::sin(aplha), std::cos(aplha), 0.0}};
xmap.create(size, CV_32FC1);
ymap.create(size, CV_32FC1);
for (int y = 0; y < size.height; ++y)
{
for (int x = 0; x < size.width; ++x)
{
xmap.at<float>(y, x) = static_cast<float>(M[0][0] * x + M[0][1] * y + M[0][2]);
ymap.at<float>(y, x) = static_cast<float>(M[1][0] * x + M[1][1] * y + M[1][2]);
}
}
}
};
CUDA_TEST_P(Remap, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::Scalar val = randomScalar(0.0, 255.0);
cv::cuda::GpuMat dst = createMat(xmap.size(), type, useRoi);
cv::cuda::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, val);
cv::Mat dst_gold;
remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, Remap, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES_EXTRA,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT));
class RemapOutOfScope : public Remap {};
CUDA_TEST_P(RemapOutOfScope, Regression_18224)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(xmap.size(), type, useRoi);
randu(xmap, NPP_MAX_32S, NPP_MAXABS_32F);
randu(ymap, NPP_MAX_32S, NPP_MAXABS_32F);
cv::cuda::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, 0.);
cv::Mat dst_gold;
remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, 0.);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, RemapOutOfScope, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES_EXTRA,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR)),
testing::Values(BorderType(cv::BORDER_CONSTANT)),
WHOLE_SUBMAT));
PARAM_TEST_CASE(RemapRelative, cv::cuda::DeviceInfo, MatType, Interpolation, BorderType)
{
cv::cuda::DeviceInfo devInfo;
int type;
int interpolation;
int borderType;
cv::cuda::GpuMat gSrc;
cv::cuda::GpuMat gMapRelativeX32F;
cv::cuda::GpuMat gMapRelativeY32F;
cv::cuda::GpuMat gMapAbsoluteX32F;
cv::cuda::GpuMat gMapAbsoluteY32F;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
type = GET_PARAM(1);
interpolation = GET_PARAM(2);
borderType = GET_PARAM(3);
cv::cuda::setDevice(devInfo.deviceID());
const int nChannels = CV_MAT_CN(type);
const cv::Size size(127, 61);
cv::Mat data64FC1(1, size.area()*nChannels, CV_64FC1);
data64FC1.forEach<double>([&](double& pixel, const int* position) {pixel = static_cast<double>(position[1]);});
cv::Mat src;
data64FC1.reshape(nChannels, size.height).convertTo(src, type);
cv::Mat mapRelativeX32F(size, CV_32FC1);
mapRelativeX32F.setTo(cv::Scalar::all(-0.33));
cv::Mat mapRelativeY32F(size, CV_32FC1);
mapRelativeY32F.setTo(cv::Scalar::all(-0.33));
cv::Mat mapAbsoluteX32F = mapRelativeX32F.clone();
mapAbsoluteX32F.forEach<float>([&](float& pixel, const int* position) {
pixel += static_cast<float>(position[1]);
});
cv::Mat mapAbsoluteY32F = mapRelativeY32F.clone();
mapAbsoluteY32F.forEach<float>([&](float& pixel, const int* position) {
pixel += static_cast<float>(position[0]);
});
gSrc.upload(src);
gMapRelativeX32F.upload(mapRelativeX32F);
gMapRelativeY32F.upload(mapRelativeY32F);
gMapAbsoluteX32F.upload(mapAbsoluteX32F);
gMapAbsoluteY32F.upload(mapAbsoluteY32F);
}
};
CUDA_TEST_P(RemapRelative, RemapRelative_Validity)
{
cv::cuda::GpuMat gDstAbsolute;
cv::cuda::remap(gSrc, gDstAbsolute, gMapAbsoluteX32F, gMapAbsoluteY32F, interpolation, borderType);
cv::cuda::GpuMat gDstRelative;
cv::cuda::remap(gSrc, gDstRelative, gMapRelativeX32F, gMapRelativeY32F, interpolation | WARP_RELATIVE_MAP, borderType);
cv::Mat dstAbsolute;
gDstAbsolute.download(dstAbsolute);
cv::Mat dstRelative;
gDstRelative.download(dstRelative);
EXPECT_MAT_NEAR(dstAbsolute, dstRelative, (dstAbsolute.depth() == CV_32F) ? 1e-3 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_RemapRelative, RemapRelative, testing::Combine(
ALL_DEVICES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4),
MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4),
MatType(CV_16SC1), MatType(CV_16SC3), MatType(CV_16SC4),
MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT))));
}} // namespace
#endif // HAVE_CUDA
+265
View File
@@ -0,0 +1,265 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
///////////////////////////////////////////////////////////////////
// Gold implementation
namespace
{
template <typename T, template <typename> class Interpolator>
void resizeImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
{
const int cn = src.channels();
cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy));
dst.create(dsize, src.type());
float ifx = static_cast<float>(1.0 / fx);
float ify = static_cast<float>(1.0 / fy);
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
for (int c = 0; c < cn; ++c)
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, y * ify, x * ifx, c, cv::BORDER_REPLICATE);
}
}
}
void resizeGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy, int interpolation)
{
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy);
static const func_t nearest_funcs[] =
{
resizeImpl<unsigned char, NearestInterpolator>,
resizeImpl<signed char, NearestInterpolator>,
resizeImpl<unsigned short, NearestInterpolator>,
resizeImpl<short, NearestInterpolator>,
resizeImpl<int, NearestInterpolator>,
resizeImpl<float, NearestInterpolator>
};
static const func_t linear_funcs[] =
{
resizeImpl<unsigned char, LinearInterpolator>,
resizeImpl<signed char, LinearInterpolator>,
resizeImpl<unsigned short, LinearInterpolator>,
resizeImpl<short, LinearInterpolator>,
resizeImpl<int, LinearInterpolator>,
resizeImpl<float, LinearInterpolator>
};
static const func_t cubic_funcs[] =
{
resizeImpl<unsigned char, CubicInterpolator>,
resizeImpl<signed char, CubicInterpolator>,
resizeImpl<unsigned short, CubicInterpolator>,
resizeImpl<short, CubicInterpolator>,
resizeImpl<int, CubicInterpolator>,
resizeImpl<float, CubicInterpolator>
};
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
funcs[interpolation][src.depth()](src, dst, fx, fy);
}
}
///////////////////////////////////////////////////////////////////
// Test
PARAM_TEST_CASE(Resize, cv::cuda::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
double coeff;
int interpolation;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
coeff = GET_PARAM(3);
interpolation = GET_PARAM(4);
useRoi = GET_PARAM(5);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(Resize, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::cuda::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold;
resizeGold(src, dst_gold, coeff, coeff, interpolation);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, Resize, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5, 1.5, 2.0),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
WHOLE_SUBMAT));
/////////////////
PARAM_TEST_CASE(ResizeSameAsHost, cv::cuda::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
double coeff;
int interpolation;
int type;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
coeff = GET_PARAM(3);
interpolation = GET_PARAM(4);
useRoi = GET_PARAM(5);
cv::cuda::setDevice(devInfo.deviceID());
}
};
// downscaling only: used for classifiers
CUDA_TEST_P(ResizeSameAsHost, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::cuda::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::cuda::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold;
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, ResizeSameAsHost, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_AREA)),
WHOLE_SUBMAT));
PARAM_TEST_CASE(ResizeTextures, cv::cuda::DeviceInfo, Interpolation)
{
cv::cuda::DeviceInfo devInfo;
Interpolation interpolation;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
interpolation = GET_PARAM(1);
cv::cuda::setDevice(devInfo.deviceID());
}
};
void ResizeThread(const Interpolation interp, const GpuMat& imgIn, const std::vector<GpuMat>& imgsOut, Stream& stream) {
for (auto& imgOut : imgsOut)
cv::cuda::resize(imgIn, imgOut, imgOut.size(), 0, 0, interp, stream);
}
CUDA_TEST_P(ResizeTextures, Accuracy)
{
constexpr int nThreads = 5;
constexpr int nIters = 5;
const Size szIn(100, 100);
const Size szOut(200, 200);
vector<Stream> streams(nThreads, cv::cuda::Stream::Null());
vector<GpuMat> imgsIn;
vector<vector<GpuMat>> imgsOut;
for (int i = 0; i < nThreads; i++) {
imgsIn.push_back(GpuMat(szIn, CV_8UC1, i));
vector<GpuMat> imgsOutPerThread;
for (int j = 0; j < nIters; j++)
imgsOutPerThread.push_back(GpuMat(szOut, CV_8UC1));
imgsOut.push_back(imgsOutPerThread);
}
vector<std::thread> thread(nThreads);
for (int i = 0; i < nThreads; i++) thread.at(i) = std::thread(ResizeThread, interpolation, std::ref(imgsIn.at(i)), std::ref(imgsOut.at(i)), std::ref(streams.at(i)));
for (int i = 0; i < nThreads; i++) thread.at(i).join();
for (int i = 0; i < nThreads; i++) {
GpuMat imgOutGs;
cv::cuda::resize(imgsIn.at(i), imgOutGs, szOut, 0, 0, interpolation, streams.at(i));
Mat imgOutGsHost; imgOutGs.download(imgOutGsHost);
for (const auto& imgOut : imgsOut.at(i)) {
Mat imgOutHost; imgOut.download(imgOutHost);
ASSERT_TRUE(cv::norm(imgOutHost, imgOutGsHost, NORM_INF) == 0);
}
}
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, ResizeTextures, testing::Combine(
ALL_DEVICES,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
}} // namespace
#endif // HAVE_CUDA
@@ -0,0 +1,312 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
namespace
{
cv::Mat createTransformMatrix(cv::Size srcSize, double angle)
{
cv::Mat M(2, 3, CV_64FC1);
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2;
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0;
return M;
}
}
///////////////////////////////////////////////////////////////////
// Test buildWarpAffineMaps
PARAM_TEST_CASE(BuildWarpAffineMaps, cv::cuda::DeviceInfo, cv::Size, Inverse)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
bool inverse;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
inverse = GET_PARAM(2);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(BuildWarpAffineMaps, Accuracy)
{
cv::Mat M = createTransformMatrix(size, CV_PI / 4);
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
cv::cuda::GpuMat xmap, ymap;
cv::cuda::buildWarpAffineMaps(M, inverse, size, xmap, ymap);
int interpolation = cv::INTER_NEAREST;
int borderMode = cv::BORDER_CONSTANT;
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::Mat dst;
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode);
cv::Mat dst_gold;
cv::warpAffine(src, dst_gold, M, size, flags, borderMode);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, BuildWarpAffineMaps, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
DIRECT_INVERSE));
///////////////////////////////////////////////////////////////////
// Gold implementation
namespace
{
template <typename T, template <typename> class Interpolator> void warpAffineImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal)
{
const int cn = src.channels();
dst.create(dsize, src.type());
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
float xcoo = static_cast<float>(M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2));
float ycoo = static_cast<float>(M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2));
for (int c = 0; c < cn; ++c)
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal);
}
}
}
void warpAffineGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
{
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal);
static const func_t nearest_funcs[] =
{
warpAffineImpl<unsigned char, NearestInterpolator>,
warpAffineImpl<signed char, NearestInterpolator>,
warpAffineImpl<unsigned short, NearestInterpolator>,
warpAffineImpl<short, NearestInterpolator>,
warpAffineImpl<int, NearestInterpolator>,
warpAffineImpl<float, NearestInterpolator>
};
static const func_t linear_funcs[] =
{
warpAffineImpl<unsigned char, LinearInterpolator>,
warpAffineImpl<signed char, LinearInterpolator>,
warpAffineImpl<unsigned short, LinearInterpolator>,
warpAffineImpl<short, LinearInterpolator>,
warpAffineImpl<int, LinearInterpolator>,
warpAffineImpl<float, LinearInterpolator>
};
static const func_t cubic_funcs[] =
{
warpAffineImpl<unsigned char, CubicInterpolator>,
warpAffineImpl<signed char, CubicInterpolator>,
warpAffineImpl<unsigned short, CubicInterpolator>,
warpAffineImpl<short, CubicInterpolator>,
warpAffineImpl<int, CubicInterpolator>,
warpAffineImpl<float, CubicInterpolator>
};
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
if (inverse)
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal);
else
{
cv::Mat iM;
cv::invertAffineTransform(M, iM);
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal);
}
}
}
///////////////////////////////////////////////////////////////////
// Test
PARAM_TEST_CASE(WarpAffine, cv::cuda::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
int type;
bool inverse;
int interpolation;
int borderType;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
inverse = GET_PARAM(3);
interpolation = GET_PARAM(4);
borderType = GET_PARAM(5);
useRoi = GET_PARAM(6);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(WarpAffine, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::Mat M = createTransformMatrix(size, CV_PI / 3);
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::Scalar val = randomScalar(0.0, 255.0);
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
cv::cuda::warpAffine(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
cv::Mat dst_gold;
warpAffineGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
}
CUDA_TEST_P(WarpAffine, OverlapDetection)
{
cv::Mat src = randomMat(size, type);
ASSERT_FALSE(src.empty());
cv::cuda::GpuMat gpuSrc;
gpuSrc.upload(src);
cv::Mat M = cv::Mat::eye(2, 3, CV_64FC1);
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
{
cv::cuda::GpuMat gpuDst(gpuSrc, cv::Rect(0, 0, size.width, size.height));
EXPECT_THROW(
cv::cuda::warpAffine(gpuSrc, gpuDst, M, size, flags, borderType, cv::Scalar::all(0)),
cv::Exception);
}
{
cv::cuda::GpuMat gpuDst(size, gpuSrc.type());
ASSERT_NE(gpuSrc.data, gpuDst.data); // Confirm they are distinct
EXPECT_NO_THROW({
cv::cuda::warpAffine(gpuSrc, gpuDst, M, size, flags, borderType, cv::Scalar::all(0));
});
}
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, WarpAffine, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////
// Test NPP
PARAM_TEST_CASE(WarpAffineNPP, cv::cuda::DeviceInfo, MatType, Inverse, Interpolation)
{
cv::cuda::DeviceInfo devInfo;
int type;
bool inverse;
int interpolation;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
type = GET_PARAM(1);
inverse = GET_PARAM(2);
interpolation = GET_PARAM(3);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(WarpAffineNPP, Accuracy)
{
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
ASSERT_FALSE(src.empty());
cv::Mat M = createTransformMatrix(src.size(), CV_PI / 4);
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::cuda::GpuMat dst;
cv::cuda::warpAffine(loadMat(src), dst, M, src.size(), flags);
cv::Mat dst_gold;
warpAffineGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, WarpAffineNPP, testing::Combine(
ALL_DEVICES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
}} // namespace
#endif // HAVE_CUDA
@@ -0,0 +1,285 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
namespace opencv_test { namespace {
namespace
{
cv::Mat createTransformMatrix(cv::Size srcSize, double angle)
{
cv::Mat M(3, 3, CV_64FC1);
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2;
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0;
M.at<double>(2, 0) = 0.0 ; M.at<double>(2, 1) = 0.0 ; M.at<double>(2, 2) = 1.0;
return M;
}
}
///////////////////////////////////////////////////////////////////
// Test buildWarpPerspectiveMaps
PARAM_TEST_CASE(BuildWarpPerspectiveMaps, cv::cuda::DeviceInfo, cv::Size, Inverse)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
bool inverse;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
inverse = GET_PARAM(2);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(BuildWarpPerspectiveMaps, Accuracy)
{
cv::Mat M = createTransformMatrix(size, CV_PI / 4);
cv::cuda::GpuMat xmap, ymap;
cv::cuda::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap);
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
int interpolation = cv::INTER_NEAREST;
int borderMode = cv::BORDER_CONSTANT;
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::Mat dst;
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode);
cv::Mat dst_gold;
cv::warpPerspective(src, dst_gold, M, size, flags, borderMode);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, BuildWarpPerspectiveMaps, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
DIRECT_INVERSE));
///////////////////////////////////////////////////////////////////
// Gold implementation
namespace
{
template <typename T, template <typename> class Interpolator> void warpPerspectiveImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal)
{
const int cn = src.channels();
dst.create(dsize, src.type());
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
float coeff = static_cast<float>(M.at<double>(2, 0) * x + M.at<double>(2, 1) * y + M.at<double>(2, 2));
float xcoo = static_cast<float>((M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2)) / coeff);
float ycoo = static_cast<float>((M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2)) / coeff);
for (int c = 0; c < cn; ++c)
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal);
}
}
}
void warpPerspectiveGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
{
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal);
static const func_t nearest_funcs[] =
{
warpPerspectiveImpl<unsigned char, NearestInterpolator>,
warpPerspectiveImpl<signed char, NearestInterpolator>,
warpPerspectiveImpl<unsigned short, NearestInterpolator>,
warpPerspectiveImpl<short, NearestInterpolator>,
warpPerspectiveImpl<int, NearestInterpolator>,
warpPerspectiveImpl<float, NearestInterpolator>
};
static const func_t linear_funcs[] =
{
warpPerspectiveImpl<unsigned char, LinearInterpolator>,
warpPerspectiveImpl<signed char, LinearInterpolator>,
warpPerspectiveImpl<unsigned short, LinearInterpolator>,
warpPerspectiveImpl<short, LinearInterpolator>,
warpPerspectiveImpl<int, LinearInterpolator>,
warpPerspectiveImpl<float, LinearInterpolator>
};
static const func_t cubic_funcs[] =
{
warpPerspectiveImpl<unsigned char, CubicInterpolator>,
warpPerspectiveImpl<signed char, CubicInterpolator>,
warpPerspectiveImpl<unsigned short, CubicInterpolator>,
warpPerspectiveImpl<short, CubicInterpolator>,
warpPerspectiveImpl<int, CubicInterpolator>,
warpPerspectiveImpl<float, CubicInterpolator>
};
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
if (inverse)
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal);
else
{
cv::Mat iM;
cv::invert(M, iM);
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal);
}
}
}
///////////////////////////////////////////////////////////////////
// Test
PARAM_TEST_CASE(WarpPerspective, cv::cuda::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
int type;
bool inverse;
int interpolation;
int borderType;
bool useRoi;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
size = GET_PARAM(1);
type = GET_PARAM(2);
inverse = GET_PARAM(3);
interpolation = GET_PARAM(4);
borderType = GET_PARAM(5);
useRoi = GET_PARAM(6);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(WarpPerspective, Accuracy)
{
cv::Mat src = randomMat(size, type);
cv::Mat M = createTransformMatrix(size, CV_PI / 3);
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::Scalar val = randomScalar(0.0, 255.0);
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
cv::cuda::warpPerspective(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
cv::Mat dst_gold;
warpPerspectiveGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, WarpPerspective, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////
// Test NPP
PARAM_TEST_CASE(WarpPerspectiveNPP, cv::cuda::DeviceInfo, MatType, Inverse, Interpolation)
{
cv::cuda::DeviceInfo devInfo;
int type;
bool inverse;
int interpolation;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
type = GET_PARAM(1);
inverse = GET_PARAM(2);
interpolation = GET_PARAM(3);
cv::cuda::setDevice(devInfo.deviceID());
}
};
CUDA_TEST_P(WarpPerspectiveNPP, Accuracy)
{
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
ASSERT_FALSE(src.empty());
cv::Mat M = createTransformMatrix(src.size(), CV_PI / 4);
int flags = interpolation;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::cuda::GpuMat dst;
cv::cuda::warpPerspective(loadMat(src), dst, M, src.size(), flags);
cv::Mat dst_gold;
warpPerspectiveGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
}
INSTANTIATE_TEST_CASE_P(CUDA_Warping, WarpPerspectiveNPP, testing::Combine(
ALL_DEVICES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
}} // namespace
#endif // HAVE_CUDA