fixed gpu::filter2D border interpolation for CV_32FC1 type

added additional tests for gpu filters
fixed gpu features2D tests
pull/13383/head
Vladislav Vinogradov 13 years ago
parent c1a6cb6221
commit 059cef57e6
  1. 2
      modules/gpu/include/opencv2/gpu/gpu.hpp
  2. 21
      modules/gpu/src/cuda/imgproc.cu
  3. 2
      modules/gpu/src/surf.cpp
  4. 292
      modules/gpu/test/test_calib3d.cpp
  5. 22
      modules/gpu/test/test_copy_make_border.cpp
  6. 203
      modules/gpu/test/test_core.cpp
  7. 565
      modules/gpu/test/test_features2d.cpp
  8. 643
      modules/gpu/test/test_filters.cpp
  9. 8
      modules/gpu/test/test_imgproc.cpp
  10. 4
      modules/gpu/test/test_remap.cpp
  11. 3
      modules/gpu/test/test_threshold.cpp
  12. 4
      modules/gpu/test/test_warp_affine.cpp
  13. 4
      modules/gpu/test/test_warp_perspective.cpp
  14. 249
      modules/gpu/test/utility.cpp
  15. 221
      modules/gpu/test/utility.hpp

@ -1661,7 +1661,7 @@ public:
}; };
//! Constructor //! Constructor
explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 3, int edgeThreshold = 31, explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31,
int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31); int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31);
//! Compute the ORB features on an image //! Compute the ORB features on an image

@ -911,27 +911,28 @@ namespace cv { namespace gpu { namespace device
__constant__ float c_filter2DKernel[FILTER2D_MAX_KERNEL_SIZE * FILTER2D_MAX_KERNEL_SIZE]; __constant__ float c_filter2DKernel[FILTER2D_MAX_KERNEL_SIZE * FILTER2D_MAX_KERNEL_SIZE];
texture<float, cudaTextureType2D, cudaReadModeElementType> filter2DTex(0, cudaFilterModePoint, cudaAddressModeBorder); texture<float, cudaTextureType2D, cudaReadModeElementType> filter2DTex(0, cudaFilterModePoint, cudaAddressModeClamp);
__global__ void filter2D(int ofsX, int ofsY, DevMem2Df dst, const int kWidth, const int kHeight, const int anchorX, const int anchorY) __global__ void filter2D(int ofsX, int ofsY, PtrStepf dst, const int kWidth, const int kHeight, const int anchorX, const int anchorY, const BrdReflect101<float> brd)
{ {
const int x = blockIdx.x * blockDim.x + threadIdx.x; const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y; const int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x >= dst.cols || y >= dst.rows) if (x > brd.last_col || y > brd.last_row)
return; return;
float res = 0; float res = 0;
const int baseX = ofsX + x - anchorX;
const int baseY = ofsY + y - anchorY;
int kInd = 0; int kInd = 0;
for (int i = 0; i < kHeight; ++i) for (int i = 0; i < kHeight; ++i)
{ {
for (int j = 0; j < kWidth; ++j) for (int j = 0; j < kWidth; ++j)
res += tex2D(filter2DTex, baseX + j, baseY + i) * c_filter2DKernel[kInd++]; {
const int srcX = ofsX + brd.idx_col(x - anchorX + j);
const int srcY = ofsY + brd.idx_row(y - anchorY + i);
res += tex2D(filter2DTex, srcX, srcY) * c_filter2DKernel[kInd++];
}
} }
dst.ptr(y)[x] = res; dst.ptr(y)[x] = res;
@ -946,7 +947,9 @@ namespace cv { namespace gpu { namespace device
bindTexture(&filter2DTex, src); bindTexture(&filter2DTex, src);
filter2D<<<grid, block, 0, stream>>>(ofsX, ofsY, dst, kWidth, kHeight, anchorX, anchorY); BrdReflect101<float> brd(dst.rows, dst.cols);
filter2D<<<grid, block, 0, stream>>>(ofsX, ofsY, dst, kWidth, kHeight, anchorX, anchorY, brd);
cudaSafeCall(cudaGetLastError()); cudaSafeCall(cudaGetLastError());
if (stream == 0) if (stream == 0)

@ -238,7 +238,7 @@ namespace
cv::gpu::SURF_GPU::SURF_GPU() cv::gpu::SURF_GPU::SURF_GPU()
{ {
hessianThreshold = 100; hessianThreshold = 100;
extended = 1; extended = true;
nOctaves = 4; nOctaves = 4;
nOctaveLayers = 2; nOctaveLayers = 2;
keypointsRatio = 0.01f; keypointsRatio = 0.01f;

@ -41,20 +41,13 @@
#include "precomp.hpp" #include "precomp.hpp"
#ifdef HAVE_CUDA namespace {
using namespace cvtest;
using namespace testing;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// BlockMatching // StereoBM
struct StereoBlockMatching : TestWithParam<cv::gpu::DeviceInfo> struct StereoBM : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
virtual void SetUp() virtual void SetUp()
@ -62,44 +55,34 @@ struct StereoBlockMatching : TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
img_l = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
img_r = readImage("stereobm/aloe-R.png", CV_LOAD_IMAGE_GRAYSCALE);
img_template = readImage("stereobm/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
} }
}; };
TEST_P(StereoBlockMatching, Regression) TEST_P(StereoBM, Regression)
{ {
cv::Mat disp; cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE);
cv::gpu::GpuMat dev_disp; cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE);
cv::gpu::StereoBM_GPU bm(0, 128, 19);
bm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), dev_disp); ASSERT_FALSE(left_image.empty());
ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty());
dev_disp.download(disp); cv::gpu::StereoBM_GPU bm(0, 128, 19);
cv::gpu::GpuMat disp;
disp.convertTo(disp, img_template.type()); bm(loadMat(left_image), loadMat(right_image), disp);
EXPECT_MAT_NEAR(img_template, disp, 0.0); EXPECT_MAT_NEAR(disp_gold, disp, 0.0);
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBlockMatching, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBM, ALL_DEVICES);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// BeliefPropagation // StereoBeliefPropagation
struct StereoBeliefPropagation : TestWithParam<cv::gpu::DeviceInfo> struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
virtual void SetUp() virtual void SetUp()
@ -107,44 +90,37 @@ struct StereoBeliefPropagation : TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
img_l = readImage("stereobp/aloe-L.png");
img_r = readImage("stereobp/aloe-R.png");
img_template = readImage("stereobp/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
} }
}; };
TEST_P(StereoBeliefPropagation, Regression) TEST_P(StereoBeliefPropagation, Regression)
{ {
cv::Mat disp; cv::Mat left_image = readImage("stereobp/aloe-L.png");
cv::Mat right_image = readImage("stereobp/aloe-R.png");
cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
cv::gpu::GpuMat dev_disp; ASSERT_FALSE(left_image.empty());
cv::gpu::StereoBeliefPropagation bpm(64, 8, 2, 25, 0.1f, 15, 1, CV_16S); ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty());
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), dev_disp); cv::gpu::StereoBeliefPropagation bp(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
cv::gpu::GpuMat disp;
dev_disp.download(disp); bp(loadMat(left_image), loadMat(right_image), disp);
disp.convertTo(disp, img_template.type()); cv::Mat h_disp(disp);
h_disp.convertTo(h_disp, disp_gold.depth());
EXPECT_MAT_NEAR(img_template, disp, 0.0); EXPECT_MAT_NEAR(disp_gold, h_disp, 0.0);
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBeliefPropagation, ALL_DEVICES);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// ConstantSpaceBP // StereoConstantSpaceBP
struct StereoConstantSpaceBP : TestWithParam<cv::gpu::DeviceInfo> struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
virtual void SetUp() virtual void SetUp()
@ -152,207 +128,177 @@ struct StereoConstantSpaceBP : TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
img_l = readImage("csstereobp/aloe-L.png");
img_r = readImage("csstereobp/aloe-R.png");
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
img_template = readImage("csstereobp/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
else
img_template = readImage("csstereobp/aloe-disp_CC1X.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
} }
}; };
TEST_P(StereoConstantSpaceBP, Regression) TEST_P(StereoConstantSpaceBP, Regression)
{ {
cv::Mat disp; cv::Mat left_image = readImage("csstereobp/aloe-L.png");
cv::Mat right_image = readImage("csstereobp/aloe-R.png");
cv::Mat disp_gold;
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
disp_gold = readImage("csstereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
else
disp_gold = readImage("csstereobp/aloe-disp_CC1X.png", cv::IMREAD_GRAYSCALE);
cv::gpu::GpuMat dev_disp; ASSERT_FALSE(left_image.empty());
cv::gpu::StereoConstantSpaceBP bpm(128, 16, 4, 4); ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty());
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), dev_disp); cv::gpu::StereoConstantSpaceBP csbp(128, 16, 4, 4);
cv::gpu::GpuMat disp;
dev_disp.download(disp); csbp(loadMat(left_image), loadMat(right_image), disp);
disp.convertTo(disp, img_template.type()); cv::Mat h_disp(disp);
h_disp.convertTo(h_disp, disp_gold.depth());
EXPECT_MAT_NEAR(img_template, disp, 1.0); EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0);
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoConstantSpaceBP, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoConstantSpaceBP, ALL_DEVICES);
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// projectPoints // transformPoints
struct ProjectPoints : TestWithParam<cv::gpu::DeviceInfo> struct TransformPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Mat src;
cv::Mat rvec;
cv::Mat tvec;
cv::Mat camera_mat;
std::vector<cv::Point2f> dst_gold;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
src = cvtest::randomMat(rng, cv::Size(1000, 1), CV_32FC3, 0, 10, false);
rvec = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false);
tvec = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false);
camera_mat = cvtest::randomMat(rng, cv::Size(3, 3), CV_32F, 0, 1, false);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
cv::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), dst_gold);
} }
}; };
TEST_P(ProjectPoints, Accuracy) TEST_P(TransformPoints, Accuracy)
{ {
cv::Mat dst; cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat dst;
cv::gpu::transformPoints(loadMat(src), rvec, tvec, dst);
cv::gpu::projectPoints(cv::gpu::GpuMat(src), rvec, tvec, camera_mat, cv::Mat(), d_dst); ASSERT_EQ(src.size(), dst.size());
ASSERT_EQ(src.type(), dst.type());
d_dst.download(dst); cv::Mat h_dst(dst);
ASSERT_EQ(dst_gold.size(), static_cast<size_t>(dst.cols)); cv::Mat rot;
ASSERT_EQ(1, dst.rows); cv::Rodrigues(rvec, rot);
ASSERT_EQ(CV_32FC2, dst.type());
for (size_t i = 0; i < dst_gold.size(); ++i) for (int i = 0; i < h_dst.cols; ++i)
{ {
cv::Point2f res_gold = dst_gold[i]; cv::Point3f res = h_dst.at<cv::Point3f>(0, i);
cv::Point2f res_actual = dst.at<cv::Point2f>(0, i);
cv::Point2f err = res_actual - res_gold; cv::Point3f p = src.at<cv::Point3f>(0, i);
cv::Point3f res_gold(
rot.at<float>(0, 0) * p.x + rot.at<float>(0, 1) * p.y + rot.at<float>(0, 2) * p.z + tvec.at<float>(0, 0),
rot.at<float>(1, 0) * p.x + rot.at<float>(1, 1) * p.y + rot.at<float>(1, 2) * p.z + tvec.at<float>(0, 1),
rot.at<float>(2, 0) * p.x + rot.at<float>(2, 1) * p.y + rot.at<float>(2, 2) * p.z + tvec.at<float>(0, 2));
ASSERT_LE(err.dot(err) / res_gold.dot(res_gold), 1e-3f); ASSERT_POINT3_NEAR(res_gold, res, 1e-5);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, TransformPoints, ALL_DEVICES);
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// transformPoints // ProjectPoints
struct TransformPoints : TestWithParam<cv::gpu::DeviceInfo> struct ProjectPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Mat src;
cv::Mat rvec;
cv::Mat tvec;
cv::Mat rot;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
src = cvtest::randomMat(rng, cv::Size(1000, 1), CV_32FC3, 0, 10, false);
rvec = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false);
tvec = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false);
cv::Rodrigues(rvec, rot);
} }
}; };
TEST_P(TransformPoints, Accuracy) TEST_P(ProjectPoints, Accuracy)
{ {
cv::Mat dst; cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat dst;
cv::gpu::projectPoints(loadMat(src), rvec, tvec, camera_mat, cv::Mat(), dst);
cv::gpu::transformPoints(cv::gpu::GpuMat(src), rvec, tvec, d_dst); ASSERT_EQ(1, dst.rows);
ASSERT_EQ(MatType(CV_32FC2), MatType(dst.type()));
d_dst.download(dst); std::vector<cv::Point2f> dst_gold;
cv::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), dst_gold);
ASSERT_EQ(src.size(), dst.size()); ASSERT_EQ(dst_gold.size(), static_cast<size_t>(dst.cols));
ASSERT_EQ(src.type(), dst.type());
cv::Mat h_dst(dst);
for (int i = 0; i < dst.cols; ++i) for (size_t i = 0; i < dst_gold.size(); ++i)
{ {
cv::Point3f p = src.at<cv::Point3f>(0, i); cv::Point2f res = h_dst.at<cv::Point2f>(0, i);
cv::Point3f res_gold( cv::Point2f res_gold = dst_gold[i];
rot.at<float>(0, 0) * p.x + rot.at<float>(0, 1) * p.y + rot.at<float>(0, 2) * p.z + tvec.at<float>(0, 0),
rot.at<float>(1, 0) * p.x + rot.at<float>(1, 1) * p.y + rot.at<float>(1, 2) * p.z + tvec.at<float>(0, 1),
rot.at<float>(2, 0) * p.x + rot.at<float>(2, 1) * p.y + rot.at<float>(2, 2) * p.z + tvec.at<float>(0, 2));
cv::Point3f res_actual = dst.at<cv::Point3f>(0, i);
cv::Point3f err = res_actual - res_gold;
ASSERT_LE(err.dot(err) / res_gold.dot(res_gold), 1e-3f); ASSERT_LE(cv::norm(res_gold - res) / cv::norm(res_gold), 1e-3f);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, TransformPoints, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ProjectPoints, ALL_DEVICES);
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// solvePnPRansac // SolvePnPRansac
struct SolvePnPRansac : TestWithParam<cv::gpu::DeviceInfo> struct SolvePnPRansac : testing::TestWithParam<cv::gpu::DeviceInfo>
{ {
static const int num_points = 5000;
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Mat object;
cv::Mat camera_mat;
std::vector<cv::Point2f> image_vec;
cv::Mat rvec_gold;
cv::Mat tvec_gold;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GetParam(); devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
}
};
cv::RNG& rng = cvtest::TS::ptr()->get_rng(); TEST_P(SolvePnPRansac, Accuracy)
{
object = cvtest::randomMat(rng, cv::Size(num_points, 1), CV_32FC3, 0, 100, false); cv::Mat object = randomMat(cv::Size(5000, 1), CV_32FC3, 0, 100);
camera_mat = cvtest::randomMat(rng, cv::Size(3, 3), CV_32F, 0.5, 1, false); cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f; camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f; camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f; camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f; camera_mat.at<float>(2, 1) = 0.f;
rvec_gold = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false); std::vector<cv::Point2f> image_vec;
tvec_gold = cvtest::randomMat(rng, cv::Size(3, 1), CV_32F, 0, 1, false); cv::Mat rvec_gold;
cv::Mat tvec_gold;
rvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
tvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec); cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec);
}
};
TEST_P(SolvePnPRansac, Accuracy)
{
cv::Mat rvec, tvec; cv::Mat rvec, tvec;
std::vector<int> inliers; std::vector<int> inliers;
cv::gpu::solvePnPRansac(object, cv::Mat(1, image_vec.size(), CV_32FC2, &image_vec[0]),
camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)),
rvec, tvec, false, 200, 2.f, 100, &inliers);
cv::gpu::solvePnPRansac(object, cv::Mat(1, image_vec.size(), CV_32FC2, &image_vec[0]), camera_mat, ASSERT_LE(cv::norm(rvec - rvec_gold), 1e-3);
cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), rvec, tvec, false, 200, 2.f, 100, &inliers); ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3);
ASSERT_LE(cv::norm(rvec - rvec_gold), 1e-3f);
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3f);
} }
INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES);
#endif // HAVE_CUDA } // namespace

@ -41,9 +41,11 @@
#include "precomp.hpp" #include "precomp.hpp"
#ifdef HAVE_CUDA namespace {
PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, int, Border, UseRoi) IMPLEMENT_PARAM_CLASS(Border, int)
PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, Border, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -82,9 +84,17 @@ TEST_P(CopyMakeBorder, Accuracy)
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, 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(MatType(CV_8UC1),
testing::Values(1, 10, 50), MatType(CV_8UC3),
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_CONSTANT), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), MatType(CV_8UC4),
MatType(CV_16UC1),
MatType(CV_16UC3),
MatType(CV_16UC4),
MatType(CV_32FC1),
MatType(CV_32FC3),
MatType(CV_32FC4)),
testing::Values(Border(1), Border(10), Border(50)),
ALL_BORDER_TYPES,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
#endif // HAVE_CUDA } // namespace

@ -41,10 +41,12 @@
#include "precomp.hpp" #include "precomp.hpp"
namespace {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Add_Array // Add_Array
PARAM_TEST_CASE(Add_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, int, UseRoi) PARAM_TEST_CASE(Add_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -90,7 +92,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Add_Array, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
DEPTH_PAIRS, DEPTH_PAIRS,
testing::Values(1, 2, 3, 4), ALL_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -139,7 +141,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Add_Scalar, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Subtract_Array // Subtract_Array
PARAM_TEST_CASE(Subtract_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, int, UseRoi) PARAM_TEST_CASE(Subtract_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -185,7 +187,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Subtract_Array, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
DEPTH_PAIRS, DEPTH_PAIRS,
testing::Values(1, 2, 3, 4), ALL_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -234,7 +236,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Subtract_Scalar, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Multiply_Array // Multiply_Array
PARAM_TEST_CASE(Multiply_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, int, UseRoi) PARAM_TEST_CASE(Multiply_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -279,7 +281,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Multiply_Array, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
DEPTH_PAIRS, DEPTH_PAIRS,
testing::Values(1, 2, 3, 4), ALL_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -425,7 +427,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Multiply_Scalar, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Divide_Array // Divide_Array
PARAM_TEST_CASE(Divide_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, int, UseRoi) PARAM_TEST_CASE(Divide_Array, cv::gpu::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -470,7 +472,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Divide_Array, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
DEPTH_PAIRS, DEPTH_PAIRS,
testing::Values(1, 2, 3, 4), ALL_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -794,10 +796,8 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Sqr, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Sqrt // Sqrt
namespace template <typename T> void sqrtImpl(const cv::Mat& src, cv::Mat& dst)
{ {
template <typename T> void sqrtImpl(const cv::Mat& src, cv::Mat& dst)
{
dst.create(src.size(), src.type()); dst.create(src.size(), src.type());
for (int y = 0; y < src.rows; ++y) for (int y = 0; y < src.rows; ++y)
@ -805,10 +805,10 @@ namespace
for (int x = 0; x < src.cols; ++x) for (int x = 0; x < src.cols; ++x)
dst.at<T>(y, x) = static_cast<T>(std::sqrt(static_cast<float>(src.at<T>(y, x)))); dst.at<T>(y, x) = static_cast<T>(std::sqrt(static_cast<float>(src.at<T>(y, x))));
} }
} }
void sqrtGold(const cv::Mat& src, cv::Mat& dst) void sqrtGold(const cv::Mat& src, cv::Mat& dst)
{ {
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst);
const func_t funcs[] = const func_t funcs[] =
@ -818,7 +818,6 @@ namespace
}; };
funcs[src.depth()](src, dst); funcs[src.depth()](src, dst);
}
} }
PARAM_TEST_CASE(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi) PARAM_TEST_CASE(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
@ -864,10 +863,8 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Sqrt, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Log // Log
namespace template <typename T> void logImpl(const cv::Mat& src, cv::Mat& dst)
{ {
template <typename T> void logImpl(const cv::Mat& src, cv::Mat& dst)
{
dst.create(src.size(), src.type()); dst.create(src.size(), src.type());
for (int y = 0; y < src.rows; ++y) for (int y = 0; y < src.rows; ++y)
@ -875,10 +872,10 @@ namespace
for (int x = 0; x < src.cols; ++x) for (int x = 0; x < src.cols; ++x)
dst.at<T>(y, x) = static_cast<T>(std::log(static_cast<float>(src.at<T>(y, x)))); dst.at<T>(y, x) = static_cast<T>(std::log(static_cast<float>(src.at<T>(y, x))));
} }
} }
void logGold(const cv::Mat& src, cv::Mat& dst) void logGold(const cv::Mat& src, cv::Mat& dst)
{ {
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst);
const func_t funcs[] = const func_t funcs[] =
@ -888,7 +885,6 @@ namespace
}; };
funcs[src.depth()](src, dst); funcs[src.depth()](src, dst);
}
} }
PARAM_TEST_CASE(Log, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi) PARAM_TEST_CASE(Log, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
@ -974,6 +970,9 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Exp, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// compare // compare
CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE)
#define ALL_CMP_CODES testing::Values(CmpCode(cv::CMP_EQ), CmpCode(cv::CMP_NE), CmpCode(cv::CMP_GT), CmpCode(cv::CMP_GE), CmpCode(cv::CMP_LT), CmpCode(cv::CMP_LE))
PARAM_TEST_CASE(Compare, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode, UseRoi) PARAM_TEST_CASE(Compare, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
@ -1088,7 +1087,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Bitwise_Array, testing::Combine(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Bitwise_Scalar // Bitwise_Scalar
PARAM_TEST_CASE(Bitwise_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, int) PARAM_TEST_CASE(Bitwise_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1150,15 +1149,13 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Bitwise_Scalar, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)), testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)),
testing::Values(1, 3, 4))); IMAGE_CHANNELS));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// RShift // RShift
namespace template <typename T> void rhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{ {
template <typename T> void rhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{
const int cn = src.channels(); const int cn = src.channels();
dst.create(src.size(), src.type()); dst.create(src.size(), src.type());
@ -1171,10 +1168,10 @@ namespace
dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) >> val.val[c]; dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) >> val.val[c];
} }
} }
} }
void rhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst) void rhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{ {
typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst); typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst);
const func_t funcs[] = const func_t funcs[] =
@ -1183,10 +1180,9 @@ namespace
}; };
funcs[src.depth()](src, val, dst); funcs[src.depth()](src, val, dst);
}
} }
PARAM_TEST_CASE(RShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, int, UseRoi) PARAM_TEST_CASE(RShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1229,16 +1225,14 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, RShift, testing::Combine(
MatDepth(CV_16U), MatDepth(CV_16U),
MatDepth(CV_16S), MatDepth(CV_16S),
MatDepth(CV_32S)), MatDepth(CV_32S)),
testing::Values(1, 3, 4), IMAGE_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// LShift // LShift
namespace template <typename T> void lhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{ {
template <typename T> void lhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{
const int cn = src.channels(); const int cn = src.channels();
dst.create(src.size(), src.type()); dst.create(src.size(), src.type());
@ -1251,10 +1245,10 @@ namespace
dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) << val.val[c]; dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) << val.val[c];
} }
} }
} }
void lhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst) void lhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
{ {
typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst); typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst);
const func_t funcs[] = const func_t funcs[] =
@ -1263,10 +1257,9 @@ namespace
}; };
funcs[src.depth()](src, val, dst); funcs[src.depth()](src, val, dst);
}
} }
PARAM_TEST_CASE(LShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, int, UseRoi) PARAM_TEST_CASE(LShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1305,7 +1298,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, LShift, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)), testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)),
testing::Values(1, 3, 4), IMAGE_CHANNELS,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -1411,7 +1404,7 @@ PARAM_TEST_CASE(Pow, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
TEST_P(Pow, Accuracy) TEST_P(Pow, Accuracy)
{ {
cv::Mat src = randomMat(size, depth, 0.0, 100.0); cv::Mat src = randomMat(size, depth, 0.0, 10.0);
double power = randomDouble(2.0, 4.0); double power = randomDouble(2.0, 4.0);
if (src.depth() < CV_32F) if (src.depth() < CV_32F)
@ -1423,7 +1416,7 @@ TEST_P(Pow, Accuracy)
cv::Mat dst_gold; cv::Mat dst_gold;
cv::pow(src, power, dst_gold); cv::pow(src, power, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 0.0 : 1e-6); EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 0.0 : 1e-1);
} }
INSTANTIATE_TEST_CASE_P(GPU_Core, Pow, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Core, Pow, testing::Combine(
@ -1486,6 +1479,9 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, AddWeighted, testing::Combine(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// GEMM // GEMM
CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T);
#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
PARAM_TEST_CASE(GEMM, cv::gpu::DeviceInfo, cv::Size, MatType, GemmFlags, UseRoi) PARAM_TEST_CASE(GEMM, cv::gpu::DeviceInfo, cv::Size, MatType, GemmFlags, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
@ -1579,6 +1575,10 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Transpose, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Flip // Flip
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y))
PARAM_TEST_CASE(Flip, cv::gpu::DeviceInfo, cv::Size, MatType, FlipCode, UseRoi) PARAM_TEST_CASE(Flip, cv::gpu::DeviceInfo, cv::Size, MatType, FlipCode, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
@ -1772,7 +1772,9 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Magnitude, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Phase // Phase
PARAM_TEST_CASE(Phase, cv::gpu::DeviceInfo, cv::Size, bool, UseRoi) IMPLEMENT_PARAM_CLASS(AngleInDegrees, bool)
PARAM_TEST_CASE(Phase, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1807,13 +1809,13 @@ TEST_P(Phase, Accuracy)
INSTANTIATE_TEST_CASE_P(GPU_Core, Phase, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Core, Phase, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Bool(), testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// CartToPolar // CartToPolar
PARAM_TEST_CASE(CartToPolar, cv::gpu::DeviceInfo, cv::Size, bool, UseRoi) PARAM_TEST_CASE(CartToPolar, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1851,13 +1853,13 @@ TEST_P(CartToPolar, Accuracy)
INSTANTIATE_TEST_CASE_P(GPU_Core, CartToPolar, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Core, CartToPolar, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Bool(), testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// polarToCart // polarToCart
PARAM_TEST_CASE(PolarToCart, cv::gpu::DeviceInfo, cv::Size, bool, UseRoi) PARAM_TEST_CASE(PolarToCart, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -1895,7 +1897,7 @@ TEST_P(PolarToCart, Accuracy)
INSTANTIATE_TEST_CASE_P(GPU_Core, PolarToCart, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Core, PolarToCart, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Bool(), testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -2026,11 +2028,9 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, NormDiff, testing::Combine(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Sum // Sum
namespace template <typename T>
cv::Scalar absSumImpl(const cv::Mat& src)
{ {
template <typename T>
cv::Scalar absSumImpl(const cv::Mat& src)
{
const int cn = src.channels(); const int cn = src.channels();
cv::Scalar sum = cv::Scalar::all(0); cv::Scalar sum = cv::Scalar::all(0);
@ -2045,10 +2045,10 @@ namespace
} }
return sum; return sum;
} }
cv::Scalar absSumGold(const cv::Mat& src) cv::Scalar absSumGold(const cv::Mat& src)
{ {
typedef cv::Scalar (*func_t)(const cv::Mat& src); typedef cv::Scalar (*func_t)(const cv::Mat& src);
static const func_t funcs[] = static const func_t funcs[] =
@ -2063,11 +2063,11 @@ namespace
}; };
return funcs[src.depth()](src); return funcs[src.depth()](src);
} }
template <typename T> template <typename T>
cv::Scalar sqrSumImpl(const cv::Mat& src) cv::Scalar sqrSumImpl(const cv::Mat& src)
{ {
const int cn = src.channels(); const int cn = src.channels();
cv::Scalar sum = cv::Scalar::all(0); cv::Scalar sum = cv::Scalar::all(0);
@ -2085,10 +2085,10 @@ namespace
} }
return sum; return sum;
} }
cv::Scalar sqrSumGold(const cv::Mat& src) cv::Scalar sqrSumGold(const cv::Mat& src)
{ {
typedef cv::Scalar (*func_t)(const cv::Mat& src); typedef cv::Scalar (*func_t)(const cv::Mat& src);
static const func_t funcs[] = static const func_t funcs[] =
@ -2103,7 +2103,6 @@ namespace
}; };
return funcs[src.depth()](src); return funcs[src.depth()](src);
}
} }
PARAM_TEST_CASE(Sum, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi) PARAM_TEST_CASE(Sum, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
@ -2164,57 +2163,6 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Sum, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// MinMax // MinMax
namespace
{
void minMaxLocGold(const cv::Mat& src, double* minVal_, double* maxVal_ = 0, cv::Point* minLoc_ = 0, cv::Point* maxLoc_ = 0, const cv::Mat& mask = cv::Mat())
{
if (src.depth() != CV_8S)
{
cv::minMaxLoc(src, minVal_, maxVal_, minLoc_, maxLoc_, mask);
return;
}
// OpenCV's minMaxLoc doesn't support CV_8S type
double minVal = std::numeric_limits<double>::max();
cv::Point minLoc(-1, -1);
double maxVal = -std::numeric_limits<double>::max();
cv::Point maxLoc(-1, -1);
for (int y = 0; y < src.rows; ++y)
{
const schar* src_row = src.ptr<signed char>(y);
const uchar* mask_row = mask.empty() ? 0 : mask.ptr<unsigned char>(y);
for (int x = 0; x < src.cols; ++x)
{
if (!mask_row || mask_row[x])
{
schar val = src_row[x];
if (val < minVal)
{
minVal = val;
minLoc = cv::Point(x, y);
}
if (val > maxVal)
{
maxVal = val;
maxLoc = cv::Point(x, y);
}
}
}
}
if (minVal_) *minVal_ = minVal;
if (maxVal_) *maxVal_ = maxVal;
if (minLoc_) *minLoc_ = minLoc;
if (maxLoc_) *maxLoc_ = maxLoc;
}
}
PARAM_TEST_CASE(MinMax, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi) PARAM_TEST_CASE(MinMax, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
@ -2278,16 +2226,14 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, MinMax, testing::Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// MinMaxLoc // MinMaxLoc
namespace template <typename T>
void expectEqualImpl(const cv::Mat& src, cv::Point loc_gold, cv::Point loc)
{ {
template <typename T>
void expectEqualImpl(const cv::Mat& src, cv::Point loc_gold, cv::Point loc)
{
EXPECT_EQ(src.at<T>(loc_gold.y, loc_gold.x), src.at<T>(loc.y, loc.x)); EXPECT_EQ(src.at<T>(loc_gold.y, loc_gold.x), src.at<T>(loc.y, loc.x));
} }
void expectEqual(const cv::Mat& src, cv::Point loc_gold, cv::Point loc) void expectEqual(const cv::Mat& src, cv::Point loc_gold, cv::Point loc)
{ {
typedef void (*func_t)(const cv::Mat& src, cv::Point loc_gold, cv::Point loc); typedef void (*func_t)(const cv::Mat& src, cv::Point loc_gold, cv::Point loc);
static const func_t funcs[] = static const func_t funcs[] =
@ -2302,7 +2248,6 @@ namespace
}; };
funcs[src.depth()](src, loc_gold, loc); funcs[src.depth()](src, loc_gold, loc);
}
} }
PARAM_TEST_CASE(MinMaxLoc, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi) PARAM_TEST_CASE(MinMaxLoc, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
@ -2420,7 +2365,10 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, CountNonZero, testing::Combine(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Reduce // Reduce
PARAM_TEST_CASE(Reduce, cv::gpu::DeviceInfo, cv::Size, MatDepth, int, ReduceCode, UseRoi) CV_ENUM(ReduceCode, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
#define ALL_REDUCE_CODES testing::Values(ReduceCode(CV_REDUCE_SUM), ReduceCode(CV_REDUCE_AVG), ReduceCode(CV_REDUCE_MAX), ReduceCode(CV_REDUCE_MIN))
PARAM_TEST_CASE(Reduce, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, ReduceCode, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -2448,6 +2396,7 @@ PARAM_TEST_CASE(Reduce, cv::gpu::DeviceInfo, cv::Size, MatDepth, int, ReduceCode
dst_depth = (reduceOp == CV_REDUCE_MAX || reduceOp == CV_REDUCE_MIN) ? depth : CV_32F; dst_depth = (reduceOp == CV_REDUCE_MAX || reduceOp == CV_REDUCE_MIN) ? depth : CV_32F;
dst_type = CV_MAKE_TYPE(dst_depth, channels); dst_type = CV_MAKE_TYPE(dst_depth, channels);
} }
}; };
TEST_P(Reduce, Rows) TEST_P(Reduce, Rows)
@ -2486,6 +2435,8 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Reduce, testing::Combine(
MatDepth(CV_16U), MatDepth(CV_16U),
MatDepth(CV_16S), MatDepth(CV_16S),
MatDepth(CV_32F)), MatDepth(CV_32F)),
testing::Values(1, 2, 3, 4), ALL_CHANNELS,
ALL_REDUCE_CODES, ALL_REDUCE_CODES,
WHOLE_SUBMAT)); WHOLE_SUBMAT));
} // namespace

@ -41,12 +41,74 @@
#include "precomp.hpp" #include "precomp.hpp"
#ifdef HAVE_CUDA namespace {
using namespace cvtest; bool keyPointsEquals(const cv::KeyPoint& p1, const cv::KeyPoint& p2)
using namespace testing; {
const double maxPtDif = 1.0;
const double maxSizeDif = 1.0;
const double maxAngleDif = 2.0;
const double maxResponseDif = 0.1;
double dist = cv::norm(p1.pt - p2.pt);
if (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id)
{
return true;
}
return false;
}
struct KeyPointLess : std::binary_function<cv::KeyPoint, cv::KeyPoint, bool>
{
bool operator()(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2) const
{
return kp1.pt.y < kp2.pt.y || (kp1.pt.y == kp2.pt.y && kp1.pt.x < kp2.pt.x);
}
};
testing::AssertionResult assertKeyPointsEquals(const char* gold_expr, const char* actual_expr, std::vector<cv::KeyPoint>& gold, std::vector<cv::KeyPoint>& actual)
{
if (gold.size() != actual.size())
{
return testing::AssertionFailure() << "KeyPoints size mistmach\n"
<< "\"" << gold_expr << "\" : " << gold.size() << "\n"
<< "\"" << actual_expr << "\" : " << actual.size();
}
std::sort(actual.begin(), actual.end(), KeyPointLess());
std::sort(gold.begin(), gold.end(), KeyPointLess());
for (size_t i; i < gold.size(); ++i)
{
const cv::KeyPoint& p1 = gold[i];
const cv::KeyPoint& p2 = actual[i];
if (!keyPointsEquals(p1, p2))
{
return testing::AssertionFailure() << "KeyPoints differ at " << i << "\n"
<< "\"" << gold_expr << "\" vs \"" << actual_expr << "\" : \n"
<< "pt : " << testing::PrintToString(p1.pt) << " vs " << testing::PrintToString(p2.pt) << "\n"
<< "size : " << p1.size << " vs " << p2.size << "\n"
<< "angle : " << p1.angle << " vs " << p2.angle << "\n"
<< "response : " << p1.response << " vs " << p2.response << "\n"
<< "octave : " << p1.octave << " vs " << p2.octave << "\n"
<< "class_id : " << p1.class_id << " vs " << p2.class_id;
}
}
return ::testing::AssertionSuccess();
}
#define ASSERT_KEYPOINTS_EQ(gold, actual) EXPECT_PRED_FORMAT2(assertKeyPointsEquals, gold, actual);
int getValidMatchesCount(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2, const std::vector<cv::DMatch>& matches) int getMatchedPointsCount(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2, const std::vector<cv::DMatch>& matches)
{ {
int validCount = 0; int validCount = 0;
@ -57,23 +119,9 @@ int getValidMatchesCount(const std::vector<cv::KeyPoint>& keypoints1, const std:
const cv::KeyPoint& p1 = keypoints1[m.queryIdx]; const cv::KeyPoint& p1 = keypoints1[m.queryIdx];
const cv::KeyPoint& p2 = keypoints2[m.trainIdx]; const cv::KeyPoint& p2 = keypoints2[m.trainIdx];
const float maxPtDif = 1.f; if (keyPointsEquals(p1, p2))
const float maxSizeDif = 1.f;
const float maxAngleDif = 2.f;
const float maxResponseDif = 0.1f;
float dist = (float) cv::norm(p1.pt - p2.pt);
if (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id)
{
++validCount; ++validCount;
} }
}
return validCount; return validCount;
} }
@ -81,78 +129,280 @@ int getValidMatchesCount(const std::vector<cv::KeyPoint>& keypoints1, const std:
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// SURF // SURF
struct SURF : TestWithParam<cv::gpu::DeviceInfo> IMPLEMENT_PARAM_CLASS(SURF_HessianThreshold, double)
IMPLEMENT_PARAM_CLASS(SURF_Octaves, int)
IMPLEMENT_PARAM_CLASS(SURF_OctaveLayers, int)
IMPLEMENT_PARAM_CLASS(SURF_Extended, bool)
IMPLEMENT_PARAM_CLASS(SURF_Upright, bool)
PARAM_TEST_CASE(SURF, cv::gpu::DeviceInfo, SURF_HessianThreshold, SURF_Octaves, SURF_OctaveLayers, SURF_Extended, SURF_Upright)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
double hessianThreshold;
cv::Mat image; int nOctaves;
cv::Mat mask; int nOctaveLayers;
bool extended;
std::vector<cv::KeyPoint> keypoints_gold; bool upright;
std::vector<float> descriptors_gold;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GetParam(); devInfo = GET_PARAM(0);
hessianThreshold = GET_PARAM(1);
nOctaves = GET_PARAM(2);
nOctaveLayers = GET_PARAM(3);
extended = GET_PARAM(4);
upright = GET_PARAM(5);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
}
};
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE); TEST_P(SURF, Detector)
{
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::gpu::SURF_GPU surf;
surf.hessianThreshold = hessianThreshold;
surf.nOctaves = nOctaves;
surf.nOctaveLayers = nOctaveLayers;
surf.extended = extended;
surf.upright = upright;
surf.keypointsRatio = 0.05f;
std::vector<cv::KeyPoint> keypoints;
surf(loadMat(image), cv::gpu::GpuMat(), keypoints);
cv::SURF surf_gold;
surf_gold.hessianThreshold = hessianThreshold;
surf_gold.nOctaves = nOctaves;
surf_gold.nOctaveLayers = nOctaveLayers;
surf_gold.extended = extended;
surf_gold.upright = upright;
std::vector<cv::KeyPoint> keypoints_gold;
surf_gold(image, cv::noArray(), keypoints_gold);
ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
}
TEST_P(SURF, Detector_Masked)
{
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty()); ASSERT_FALSE(image.empty());
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1)); cv::Mat mask(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0)); mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::SURF fdetector_gold; cv::gpu::SURF_GPU surf;
fdetector_gold.extended = false; surf.hessianThreshold = hessianThreshold;
fdetector_gold(image, mask, keypoints_gold, descriptors_gold); surf.nOctaves = nOctaves;
surf.nOctaveLayers = nOctaveLayers;
surf.extended = extended;
surf.upright = upright;
surf.keypointsRatio = 0.05f;
std::vector<cv::KeyPoint> keypoints;
surf(loadMat(image), loadMat(mask), keypoints);
cv::SURF surf_gold;
surf_gold.hessianThreshold = hessianThreshold;
surf_gold.nOctaves = nOctaves;
surf_gold.nOctaveLayers = nOctaveLayers;
surf_gold.extended = extended;
surf_gold.upright = upright;
std::vector<cv::KeyPoint> keypoints_gold;
surf_gold(image, mask, keypoints_gold);
ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
}
TEST_P(SURF, Descriptor)
{
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::gpu::SURF_GPU surf;
surf.hessianThreshold = hessianThreshold;
surf.nOctaves = nOctaves;
surf.nOctaveLayers = nOctaveLayers;
surf.extended = extended;
surf.upright = upright;
surf.keypointsRatio = 0.05f;
cv::SURF surf_gold;
surf_gold.hessianThreshold = hessianThreshold;
surf_gold.nOctaves = nOctaves;
surf_gold.nOctaveLayers = nOctaveLayers;
surf_gold.extended = extended;
surf_gold.upright = upright;
std::vector<cv::KeyPoint> keypoints;
surf_gold(image, cv::noArray(), keypoints);
cv::gpu::GpuMat descriptors;
surf(loadMat(image), cv::gpu::GpuMat(), keypoints, descriptors, true);
cv::Mat descriptors_gold;
surf_gold(image, cv::noArray(), keypoints, descriptors_gold, true);
cv::BFMatcher matcher(cv::NORM_L2);
std::vector<cv::DMatch> matches;
matcher.match(descriptors_gold, cv::Mat(descriptors), matches);
int matchedCount = getMatchedPointsCount(keypoints, keypoints, matches);
double matchedRatio = static_cast<double>(matchedCount) / keypoints.size();
EXPECT_GT(matchedRatio, 0.35);
}
INSTANTIATE_TEST_CASE_P(GPU_Features2D, SURF, testing::Combine(
ALL_DEVICES,
testing::Values(SURF_HessianThreshold(100.0), SURF_HessianThreshold(500.0), SURF_HessianThreshold(1000.0)),
testing::Values(SURF_Octaves(3), SURF_Octaves(4)),
testing::Values(SURF_OctaveLayers(2), SURF_OctaveLayers(3)),
testing::Values(SURF_Extended(false), SURF_Extended(true)),
testing::Values(SURF_Upright(false), SURF_Upright(true))));
/////////////////////////////////////////////////////////////////////////////////////////////////
// FAST
IMPLEMENT_PARAM_CLASS(FAST_Threshold, int)
IMPLEMENT_PARAM_CLASS(FAST_NonmaxSupression, bool)
PARAM_TEST_CASE(FAST, cv::gpu::DeviceInfo, FAST_Threshold, FAST_NonmaxSupression)
{
cv::gpu::DeviceInfo devInfo;
int threshold;
bool nonmaxSupression;
virtual void SetUp()
{
devInfo = GET_PARAM(0);
threshold = GET_PARAM(1);
nonmaxSupression = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
} }
}; };
TEST_P(SURF, EmptyDataTest) TEST_P(FAST, Accuracy)
{ {
cv::gpu::SURF_GPU fdetector; cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::gpu::FAST_GPU fast(threshold);
fast.nonmaxSupression = nonmaxSupression;
cv::gpu::GpuMat image;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
std::vector<float> descriptors; fast(loadMat(image), cv::gpu::GpuMat(), keypoints);
fdetector(image, cv::gpu::GpuMat(), keypoints, descriptors); std::vector<cv::KeyPoint> keypoints_gold;
cv::FAST(image, keypoints_gold, threshold, nonmaxSupression);
EXPECT_TRUE(keypoints.empty()); ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
EXPECT_TRUE(descriptors.empty());
} }
TEST_P(SURF, Accuracy) INSTANTIATE_TEST_CASE_P(GPU_Features2D, FAST, testing::Combine(
ALL_DEVICES,
testing::Values(FAST_Threshold(25), FAST_Threshold(50)),
testing::Values(FAST_NonmaxSupression(false), FAST_NonmaxSupression(true))));
/////////////////////////////////////////////////////////////////////////////////////////////////
// ORB
IMPLEMENT_PARAM_CLASS(ORB_FeaturesCount, int)
IMPLEMENT_PARAM_CLASS(ORB_ScaleFactor, float)
IMPLEMENT_PARAM_CLASS(ORB_LevelsCount, int)
IMPLEMENT_PARAM_CLASS(ORB_EdgeThreshold, int)
IMPLEMENT_PARAM_CLASS(ORB_firstLevel, int)
IMPLEMENT_PARAM_CLASS(ORB_WTA_K, int)
IMPLEMENT_PARAM_CLASS(ORB_PatchSize, int)
IMPLEMENT_PARAM_CLASS(ORB_BlurForDescriptor, bool)
CV_ENUM(ORB_ScoreType, cv::ORB::HARRIS_SCORE, cv::ORB::FAST_SCORE)
PARAM_TEST_CASE(ORB, cv::gpu::DeviceInfo, ORB_FeaturesCount, ORB_ScaleFactor, ORB_LevelsCount, ORB_EdgeThreshold, ORB_firstLevel, ORB_WTA_K, ORB_ScoreType, ORB_PatchSize, ORB_BlurForDescriptor)
{ {
std::vector<cv::KeyPoint> keypoints; cv::gpu::DeviceInfo devInfo;
cv::Mat descriptors; int nFeatures;
float scaleFactor;
int nLevels;
int edgeThreshold;
int firstLevel;
int WTA_K;
int scoreType;
int patchSize;
bool blurForDescriptor;
cv::gpu::GpuMat dev_descriptors; virtual void SetUp()
cv::gpu::SURF_GPU fdetector; fdetector.extended = false; {
devInfo = GET_PARAM(0);
nFeatures = GET_PARAM(1);
scaleFactor = GET_PARAM(2);
nLevels = GET_PARAM(3);
edgeThreshold = GET_PARAM(4);
firstLevel = GET_PARAM(5);
WTA_K = GET_PARAM(6);
scoreType = GET_PARAM(7);
patchSize = GET_PARAM(8);
blurForDescriptor = GET_PARAM(9);
fdetector(loadMat(image), loadMat(mask), keypoints, dev_descriptors); cv::gpu::setDevice(devInfo.deviceID());
}
};
dev_descriptors.download(descriptors); TEST_P(ORB, Accuracy)
{
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::BFMatcher matcher(cv::NORM_L2); cv::Mat mask(image.size(), CV_8UC1, cv::Scalar::all(1));
std::vector<cv::DMatch> matches; mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::gpu::ORB_GPU orb(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
orb.blurForDescriptor = blurForDescriptor;
std::vector<cv::KeyPoint> keypoints;
cv::gpu::GpuMat descriptors;
orb(loadMat(image), loadMat(mask), keypoints, descriptors);
matcher.match(cv::Mat(static_cast<int>(keypoints_gold.size()), 64, CV_32FC1, &descriptors_gold[0]), descriptors, matches); cv::ORB orb_gold(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
int validCount = getValidMatchesCount(keypoints_gold, keypoints, matches); std::vector<cv::KeyPoint> keypoints_gold;
cv::Mat descriptors_gold;
orb_gold(image, mask, keypoints_gold, descriptors_gold);
cv::BFMatcher matcher(cv::NORM_HAMMING);
std::vector<cv::DMatch> matches;
matcher.match(descriptors_gold, cv::Mat(descriptors), matches);
double validRatio = (double) validCount / matches.size(); int matchedCount = getMatchedPointsCount(keypoints_gold, keypoints, matches);
double matchedRatio = static_cast<double>(matchedCount) / keypoints.size();
EXPECT_GT(validRatio, 0.5); EXPECT_GT(matchedRatio, 0.35);
} }
INSTANTIATE_TEST_CASE_P(Features2D, SURF, DEVICES(cv::gpu::GLOBAL_ATOMICS)); INSTANTIATE_TEST_CASE_P(GPU_Features2D, ORB, testing::Combine(
ALL_DEVICES,
testing::Values(ORB_FeaturesCount(1000)),
testing::Values(ORB_ScaleFactor(1.2f)),
testing::Values(ORB_LevelsCount(4), ORB_LevelsCount(8)),
testing::Values(ORB_EdgeThreshold(31)),
testing::Values(ORB_firstLevel(0), ORB_firstLevel(2)),
testing::Values(ORB_WTA_K(2), ORB_WTA_K(3), ORB_WTA_K(4)),
testing::Values(ORB_ScoreType(cv::ORB::HARRIS_SCORE)),
testing::Values(ORB_PatchSize(31), ORB_PatchSize(29)),
testing::Values(ORB_BlurForDescriptor(false), ORB_BlurForDescriptor(true))));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// BruteForceMatcher // BruteForceMatcher
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, int) CV_ENUM(DistType, cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist, cv::gpu::BruteForceMatcher_GPU_base::HammingDist)
IMPLEMENT_PARAM_CLASS(DescriptorSize, int)
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, DescriptorSize)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::gpu::BruteForceMatcher_GPU_base::DistType distType; cv::gpu::BruteForceMatcher_GPU_base::DistType distType;
@ -212,10 +462,9 @@ PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, int)
TEST_P(BruteForceMatcher, Match) TEST_P(BruteForceMatcher, Match)
{ {
std::vector<cv::DMatch> matches;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
std::vector<cv::DMatch> matches;
matcher.match(loadMat(query), loadMat(train), matches); matcher.match(loadMat(query), loadMat(train), matches);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
@ -234,17 +483,13 @@ TEST_P(BruteForceMatcher, Match)
TEST_P(BruteForceMatcher, MatchAdd) TEST_P(BruteForceMatcher, MatchAdd)
{ {
std::vector<cv::DMatch> matches;
bool isMaskSupported;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::GpuMat d_train(train); cv::gpu::GpuMat d_train(train);
// make add() twice to test such case // make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows/2))); matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows/2, train.rows))); matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal) // prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2); std::vector<cv::gpu::GpuMat> masks(2);
@ -255,18 +500,17 @@ TEST_P(BruteForceMatcher, MatchAdd)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0)); masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
} }
std::vector<cv::DMatch> matches;
matcher.match(cv::gpu::GpuMat(query), matches, masks); matcher.match(cv::gpu::GpuMat(query), matches, masks);
isMaskSupported = matcher.isMaskSupported();
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0; int badCount = 0;
int shift = matcher.isMaskSupported() ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++) for (size_t i = 0; i < matches.size(); i++)
{ {
cv::DMatch match = matches[i]; cv::DMatch match = matches[i];
int shift = isMaskSupported ? 1 : 0;
{
if ((int)i < queryDescCount / 2) if ((int)i < queryDescCount / 2)
{ {
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + shift) || (match.imgIdx != 0)) if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + shift) || (match.imgIdx != 0))
@ -278,7 +522,6 @@ TEST_P(BruteForceMatcher, MatchAdd)
badCount++; badCount++;
} }
} }
}
ASSERT_EQ(0, badCount); ASSERT_EQ(0, badCount);
} }
@ -287,9 +530,9 @@ TEST_P(BruteForceMatcher, KnnMatch2)
{ {
const int knn = 2; const int knn = 2;
std::vector< std::vector<cv::DMatch> > matches;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn); matcher.knnMatch(loadMat(query), loadMat(train), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
@ -317,11 +560,11 @@ TEST_P(BruteForceMatcher, KnnMatch2)
TEST_P(BruteForceMatcher, KnnMatch3) TEST_P(BruteForceMatcher, KnnMatch3)
{ {
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
const int knn = 3; const int knn = 3;
std::vector< std::vector<cv::DMatch> > matches; std::vector< std::vector<cv::DMatch> > matches;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn); matcher.knnMatch(loadMat(query), loadMat(train), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
@ -350,9 +593,6 @@ TEST_P(BruteForceMatcher, KnnMatch3)
TEST_P(BruteForceMatcher, KnnMatchAdd2) TEST_P(BruteForceMatcher, KnnMatchAdd2)
{ {
const int knn = 2; const int knn = 2;
std::vector< std::vector<cv::DMatch> > matches;
bool isMaskSupported;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
@ -371,14 +611,14 @@ TEST_P(BruteForceMatcher, KnnMatchAdd2)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0)); masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
} }
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks); std::vector< std::vector<cv::DMatch> > matches;
isMaskSupported = matcher.isMaskSupported(); matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0; int badCount = 0;
int shift = isMaskSupported ? 1 : 0; int shift = matcher.isMaskSupported() ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++) for (size_t i = 0; i < matches.size(); i++)
{ {
if ((int)matches[i].size() != knn) if ((int)matches[i].size() != knn)
@ -412,9 +652,6 @@ TEST_P(BruteForceMatcher, KnnMatchAdd2)
TEST_P(BruteForceMatcher, KnnMatchAdd3) TEST_P(BruteForceMatcher, KnnMatchAdd3)
{ {
const int knn = 3; const int knn = 3;
std::vector< std::vector<cv::DMatch> > matches;
bool isMaskSupported;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
@ -433,14 +670,13 @@ TEST_P(BruteForceMatcher, KnnMatchAdd3)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0)); masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
} }
std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks); matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
isMaskSupported = matcher.isMaskSupported();
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0; int badCount = 0;
int shift = isMaskSupported ? 1 : 0; int shift = matcher.isMaskSupported() ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++) for (size_t i = 0; i < matches.size(); i++)
{ {
if ((int)matches[i].size() != knn) if ((int)matches[i].size() != knn)
@ -473,16 +709,11 @@ TEST_P(BruteForceMatcher, KnnMatchAdd3)
TEST_P(BruteForceMatcher, RadiusMatch) TEST_P(BruteForceMatcher, RadiusMatch)
{ {
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
return;
const float radius = 1.f / countFactor; const float radius = 1.f / countFactor;
std::vector< std::vector<cv::DMatch> > matches;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
std::vector< std::vector<cv::DMatch> > matches;
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius); matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
@ -505,16 +736,9 @@ TEST_P(BruteForceMatcher, RadiusMatch)
TEST_P(BruteForceMatcher, RadiusMatchAdd) TEST_P(BruteForceMatcher, RadiusMatchAdd)
{ {
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS)) const int n = 3;
return;
int n = 3;
const float radius = 1.f / countFactor * n; const float radius = 1.f / countFactor * n;
std::vector< std::vector<cv::DMatch> > matches;
bool isMaskSupported;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType); cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::GpuMat d_train(train); cv::gpu::GpuMat d_train(train);
@ -532,15 +756,14 @@ TEST_P(BruteForceMatcher, RadiusMatchAdd)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0)); masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
} }
std::vector< std::vector<cv::DMatch> > matches;
matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius, masks); matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius, masks);
isMaskSupported = matcher.isMaskSupported();
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0; int badCount = 0;
int shift = isMaskSupported ? 1 : 0; int shift = matcher.isMaskSupported() ? 1 : 0;
int needMatchCount = isMaskSupported ? n-1 : n; int needMatchCount = matcher.isMaskSupported() ? n-1 : n;
for (size_t i = 0; i < matches.size(); i++) for (size_t i = 0; i < matches.size(); i++)
{ {
if ((int)matches[i].size() != needMatchCount) if ((int)matches[i].size() != needMatchCount)
@ -571,141 +794,9 @@ TEST_P(BruteForceMatcher, RadiusMatchAdd)
ASSERT_EQ(0, badCount); ASSERT_EQ(0, badCount);
} }
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher, Combine( INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist), testing::Values(DistType(cv::gpu::BruteForceMatcher_GPU_base::L1Dist), DistType(cv::gpu::BruteForceMatcher_GPU_base::L2Dist)),
Values(57, 64, 83, 128, 179, 256, 304))); testing::Values(DescriptorSize(57), DescriptorSize(64), DescriptorSize(83), DescriptorSize(128), DescriptorSize(179), DescriptorSize(256), DescriptorSize(304))));
/////////////////////////////////////////////////////////////////////////////////////////////////
// FAST
struct FAST : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
cv::Mat image;
int threshold;
std::vector<cv::KeyPoint> keypoints_gold;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(image.empty());
threshold = 30;
cv::FAST(image, keypoints_gold, threshold);
}
};
struct HashEq
{
size_t hash;
inline HashEq(size_t hash_) : hash(hash_) {}
inline bool operator ()(const cv::KeyPoint& kp) const
{
return kp.hash() == hash;
}
};
struct KeyPointCompare
{
inline bool operator ()(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2) const
{
return kp1.pt.y < kp2.pt.y || (kp1.pt.y == kp2.pt.y && kp1.pt.x < kp2.pt.x);
}
};
TEST_P(FAST, Accuracy)
{
std::vector<cv::KeyPoint> keypoints;
cv::gpu::FAST_GPU fastGPU(threshold);
fastGPU(cv::gpu::GpuMat(image), cv::gpu::GpuMat(), keypoints);
ASSERT_EQ(keypoints.size(), keypoints_gold.size());
std::sort(keypoints.begin(), keypoints.end(), KeyPointCompare());
for (size_t i = 0; i < keypoints_gold.size(); ++i)
{
const cv::KeyPoint& kp1 = keypoints[i];
const cv::KeyPoint& kp2 = keypoints_gold[i];
size_t h1 = kp1.hash();
size_t h2 = kp2.hash();
ASSERT_EQ(h1, h2);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, FAST, DEVICES(cv::gpu::GLOBAL_ATOMICS));
/////////////////////////////////////////////////////////////////////////////////////////////////
// ORB
struct ORB : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
cv::Mat image;
cv::Mat mask;
int npoints;
std::vector<cv::KeyPoint> keypoints_gold;
cv::Mat descriptors_gold;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(image.empty());
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
npoints = 1000;
cv::ORB orbCPU(npoints);
orbCPU(image, mask, keypoints_gold, descriptors_gold);
}
};
TEST_P(ORB, Accuracy)
{
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
cv::gpu::ORB_GPU orbGPU(npoints);
cv::gpu::GpuMat d_descriptors;
orbGPU(cv::gpu::GpuMat(image), cv::gpu::GpuMat(mask), keypoints, d_descriptors);
d_descriptors.download(descriptors);
cv::BFMatcher matcher(cv::NORM_HAMMING);
std::vector<cv::DMatch> matches;
matcher.match(descriptors_gold, descriptors, matches);
int count = getValidMatchesCount(keypoints_gold, keypoints, matches);
double ratio = (double) count / matches.size();
ASSERT_GE(ratio, 0.65);
}
INSTANTIATE_TEST_CASE_P(Features2D, ORB, DEVICES(cv::gpu::GLOBAL_ATOMICS));
#endif // HAVE_CUDA } // namespace

@ -41,115 +41,106 @@
#include "precomp.hpp" #include "precomp.hpp"
#ifdef HAVE_CUDA struct KSize : cv::Size
using namespace cvtest;
using namespace testing;
namespace
{ {
double checkNorm(const cv::Mat& m1, const cv::Mat& m2, const cv::Size& ksize) KSize() {}
{ KSize(int width, int height) : cv::Size(width, height) {}
cv::Rect roi(ksize.width, ksize.height, m1.cols - 2 * ksize.width, m1.rows - 2 * ksize.height); };
cv::Mat m1ROI = m1(roi); void PrintTo(KSize ksize, std::ostream* os)
cv::Mat m2ROI = m2(roi); {
return ::checkNorm(m1ROI, m2ROI); *os << "kernel size " << ksize.width << "x" << ksize.height;
} }
double checkNorm(const cv::Mat& m1, const cv::Mat& m2, int ksize) cv::Mat getInnerROI(cv::InputArray m_, cv::Size ksize)
{ {
return checkNorm(m1, m2, cv::Size(ksize, ksize)); cv::Mat m = getMat(m_);
} cv::Rect roi(ksize.width, ksize.height, m.cols - 2 * ksize.width, m.rows - 2 * ksize.height);
return m(roi);
} }
#define EXPECT_MAT_NEAR_KSIZE(mat1, mat2, ksize, eps) \ cv::Mat getInnerROI(cv::InputArray m, int ksize)
{ \ {
ASSERT_EQ(mat1.type(), mat2.type()); \ return getInnerROI(m, cv::Size(ksize, ksize));
ASSERT_EQ(mat1.size(), mat2.size()); \ }
EXPECT_LE(checkNorm(mat1, mat2, ksize), eps); \
}
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// blur // Blur
IMPLEMENT_PARAM_CLASS(Anchor, cv::Point)
PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, UseRoi) PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, KSize, Anchor, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size ksize; cv::Size ksize;
cv::Point anchor;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
useRoi = GET_PARAM(2); anchor = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::blur(img_rgba, dst_gold_rgba, ksize);
cv::blur(img_gray, dst_gold_gray, ksize);
} }
}; };
TEST_P(Blur, Rgba) TEST_P(Blur, Gray)
{ {
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::blur(loadMat(img_rgba, useRoi), dev_dst_rgba, ksize); cv::gpu::GpuMat dst;
cv::gpu::blur(loadMat(img_gray, useRoi), dst, ksize, anchor);
dev_dst_rgba.download(dst_rgba); cv::Mat dst_gold;
cv::blur(img_gray, dst_gold, ksize, anchor);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, ksize, 1.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
TEST_P(Blur, Gray) TEST_P(Blur, Color)
{ {
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::blur(loadMat(img_gray, useRoi), dev_dst_gray, ksize); cv::gpu::GpuMat dst;
cv::gpu::blur(loadMat(img_rgba, useRoi), dst, ksize, anchor);
dev_dst_gray.download(dst_gray); cv::Mat dst_gold;
cv::blur(img_rgba, dst_gold, ksize, anchor);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, ksize, 1.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 1.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Blur, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)), testing::Values(KSize(3, 3), KSize(5, 5), KSize(7, 7)),
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// sobel // Sobel
PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, int, int, int, UseRoi) IMPLEMENT_PARAM_CLASS(Deriv_X, int)
IMPLEMENT_PARAM_CLASS(Deriv_Y, int)
PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, KSize, Deriv_X, Deriv_Y, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int ksize; cv::Size ksize;
int dx; int dx;
int dy; int dy;
int borderType;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
@ -157,232 +148,224 @@ PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, int, int, int, UseRoi)
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
dx = GET_PARAM(2); dx = GET_PARAM(2);
dy = GET_PARAM(3); dy = GET_PARAM(3);
useRoi = GET_PARAM(4); borderType = GET_PARAM(4);
useRoi = GET_PARAM(5);
if (dx == 0 && dy == 0)
return;
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Sobel(img_rgba, dst_gold_rgba, -1, dx, dy, ksize);
cv::Sobel(img_gray, dst_gold_gray, -1, dx, dy, ksize);
} }
}; };
TEST_P(Sobel, Rgba) TEST_P(Sobel, Gray)
{ {
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::Sobel(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, dx, dy, ksize); cv::gpu::GpuMat dst;
cv::gpu::Sobel(loadMat(img_gray, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType);
dev_dst_rgba.download(dst_rgba); cv::Mat dst_gold;
cv::Sobel(img_gray, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR(dst_gold_rgba, dst_rgba, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
TEST_P(Sobel, Gray) TEST_P(Sobel, Color)
{ {
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Sobel(loadMat(img_gray, useRoi), dev_dst_gray, -1, dx, dy, ksize); cv::gpu::GpuMat dst;
cv::gpu::Sobel(loadMat(img_rgba, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType);
dev_dst_gray.download(dst_gray); cv::Mat dst_gold;
cv::Sobel(img_rgba, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR(dst_gold_gray, dst_gray, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Sobel, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(3, 5, 7), testing::Values(KSize(3, 3), KSize(5, 5), KSize(7, 7)),
Values(0, 1, 2), testing::Values(Deriv_X(0), Deriv_X(1), Deriv_X(2)),
Values(0, 1, 2), testing::Values(Deriv_Y(0), Deriv_Y(1), Deriv_Y(2)),
testing::Values(BorderType(cv::BORDER_REFLECT101),
BorderType(cv::BORDER_REPLICATE),
BorderType(cv::BORDER_CONSTANT),
BorderType(cv::BORDER_REFLECT)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// scharr // Scharr
PARAM_TEST_CASE(Scharr, cv::gpu::DeviceInfo, int, int, UseRoi) PARAM_TEST_CASE(Scharr, cv::gpu::DeviceInfo, Deriv_X, Deriv_Y, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int dx; int dx;
int dy; int dy;
int borderType;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
dx = GET_PARAM(1); dx = GET_PARAM(1);
dy = GET_PARAM(2); dy = GET_PARAM(2);
useRoi = GET_PARAM(3); borderType = GET_PARAM(3);
useRoi = GET_PARAM(4);
if (dx + dy != 1)
return;
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Scharr(img_rgba, dst_gold_rgba, -1, dx, dy);
cv::Scharr(img_gray, dst_gold_gray, -1, dx, dy);
} }
}; };
TEST_P(Scharr, Rgba) TEST_P(Scharr, Gray)
{ {
if (dx + dy != 1) if (dx + dy != 1)
return; return;
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::Scharr(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, dx, dy); cv::gpu::GpuMat dst;
cv::gpu::Scharr(loadMat(img_gray, useRoi), dst, -1, dx, dy, 1.0, borderType);
dev_dst_rgba.download(dst_rgba); cv::Mat dst_gold;
cv::Scharr(img_gray, dst_gold, -1, dx, dy, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
TEST_P(Scharr, Gray) TEST_P(Scharr, Color)
{ {
if (dx + dy != 1) if (dx + dy != 1)
return; return;
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Scharr(loadMat(img_gray, useRoi), dev_dst_gray, -1, dx, dy); cv::gpu::GpuMat dst;
cv::gpu::Scharr(loadMat(img_rgba, useRoi), dst, -1, dx, dy, 1.0, borderType);
dev_dst_gray.download(dst_gray); cv::Mat dst_gold;
cv::Scharr(img_rgba, dst_gold, -1, dx, dy, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Scharr, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(0, 1), testing::Values(Deriv_X(0), Deriv_X(1)),
Values(0, 1), testing::Values(Deriv_Y(0), Deriv_Y(1)),
testing::Values(BorderType(cv::BORDER_REFLECT101),
BorderType(cv::BORDER_REPLICATE),
BorderType(cv::BORDER_CONSTANT),
BorderType(cv::BORDER_REFLECT)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// gaussianBlur // GaussianBlur
PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, UseRoi) PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, KSize, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size ksize; cv::Size ksize;
int borderType;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
double sigma1, sigma2; double sigma1, sigma2;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
useRoi = GET_PARAM(2); borderType = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA); sigma1 = randomDouble(0.1, 1.0);
cv::cvtColor(img, img_gray, CV_BGR2GRAY); sigma2 = randomDouble(0.1, 1.0);
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
sigma1 = rng.uniform(0.1, 1.0);
sigma2 = rng.uniform(0.1, 1.0);
cv::GaussianBlur(img_rgba, dst_gold_rgba, ksize, sigma1, sigma2);
cv::GaussianBlur(img_gray, dst_gold_gray, ksize, sigma1, sigma2);
} }
}; };
TEST_P(GaussianBlur, Rgba) TEST_P(GaussianBlur, Gray)
{ {
if (!devInfo.supports(cv::gpu::FEATURE_SET_COMPUTE_20) && ksize.height > 16) cv::Mat img_gray;
return; cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Mat dst_rgba;
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GaussianBlur(loadMat(img_rgba, useRoi), dev_dst_rgba, ksize, sigma1, sigma2); cv::gpu::GpuMat dst;
cv::gpu::GaussianBlur(loadMat(img_gray, useRoi), dst, ksize, sigma1, sigma2, borderType);
dev_dst_rgba.download(dst_rgba); cv::Mat dst_gold;
cv::GaussianBlur(img_gray, dst_gold, ksize, sigma1, sigma2, borderType);
EXPECT_MAT_NEAR(dst_gold_rgba, dst_rgba, 4.0); EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
} }
TEST_P(GaussianBlur, Gray) TEST_P(GaussianBlur, Color)
{ {
if (!devInfo.supports(cv::gpu::FEATURE_SET_COMPUTE_20) && ksize.height > 16) cv::Mat img_rgba;
return; cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::Mat dst_gray;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::GaussianBlur(loadMat(img_gray, useRoi), dev_dst_gray, ksize, sigma1, sigma2); cv::gpu::GpuMat dst;
cv::gpu::GaussianBlur(loadMat(img_rgba, useRoi), dst, ksize, sigma1, sigma2, borderType);
dev_dst_gray.download(dst_gray); cv::Mat dst_gold;
cv::GaussianBlur(img_rgba, dst_gold, ksize, sigma1, sigma2, borderType);
EXPECT_MAT_NEAR(dst_gold_gray, dst_gray, 4.0); EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, GaussianBlur, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7), cv::Size(9, 9), cv::Size(11, 11), cv::Size(13, 13), cv::Size(15, 15), cv::Size(17, 17), cv::Size(19, 19), cv::Size(21, 21), cv::Size(23, 23), cv::Size(25, 25), cv::Size(27, 27), cv::Size(29, 29), cv::Size(31, 31)), testing::Values(KSize(3, 3),
KSize(5, 5),
KSize(7, 7),
KSize(9, 9),
KSize(11, 11),
KSize(13, 13),
KSize(15, 15),
KSize(17, 17),
KSize(19, 19),
KSize(21, 21),
KSize(23, 23),
KSize(25, 25),
KSize(27, 27),
KSize(29, 29),
KSize(31, 31)),
testing::Values(BorderType(cv::BORDER_REFLECT101),
BorderType(cv::BORDER_REPLICATE),
BorderType(cv::BORDER_CONSTANT),
BorderType(cv::BORDER_REFLECT)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// laplacian // Laplacian
PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, int, UseRoi) PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, KSize, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int ksize; cv::Size ksize;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
@ -392,256 +375,261 @@ PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, int, UseRoi)
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Laplacian(img_rgba, dst_gold_rgba, -1, ksize);
cv::Laplacian(img_gray, dst_gold_gray, -1, ksize);
} }
}; };
TEST_P(Laplacian, Rgba) TEST_P(Laplacian, Gray)
{ {
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::Laplacian(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, ksize); cv::gpu::GpuMat dst;
cv::gpu::Laplacian(loadMat(img_gray, useRoi), dst, -1, ksize.width);
dev_dst_rgba.download(dst_rgba); cv::Mat dst_gold;
cv::Laplacian(img_gray, dst_gold, -1, ksize.width);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, cv::Size(3, 3)), getInnerROI(dst, cv::Size(3, 3)), 0.0);
} }
TEST_P(Laplacian, Gray) TEST_P(Laplacian, Color)
{ {
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Laplacian(loadMat(img_gray, useRoi), dev_dst_gray, -1, ksize); cv::gpu::GpuMat dst;
cv::gpu::Laplacian(loadMat(img_rgba, useRoi), dst, -1, ksize.width);
dev_dst_gray.download(dst_gray); cv::Mat dst_gold;
cv::Laplacian(img_rgba, dst_gold, -1, ksize.width);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, cv::Size(3, 3)), getInnerROI(dst, cv::Size(3, 3)), 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Laplacian, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(1, 3), testing::Values(KSize(1, 1), KSize(3, 3)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// erode // Erode
IMPLEMENT_PARAM_CLASS(Iterations, int)
PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, UseRoi) PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, Anchor, Iterations, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Point anchor;
int iterations;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat kernel; cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
useRoi = GET_PARAM(1); anchor = GET_PARAM(1);
iterations = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
kernel = cv::Mat::ones(3, 3, CV_8U); img = readImage("stereobp/aloe-L.png");
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA); kernel = cv::Mat::ones(3, 3, CV_8U);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::erode(img_rgba, dst_gold_rgba, kernel);
cv::erode(img_gray, dst_gold_gray, kernel);
} }
}; };
TEST_P(Erode, Rgba) TEST_P(Erode, Gray)
{ {
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba; cv::gpu::GpuMat dst;
cv::gpu::erode(loadMat(img_gray, useRoi), dst, kernel, anchor, iterations);
cv::gpu::erode(loadMat(img_rgba, useRoi), dev_dst_rgba, kernel); cv::Mat dst_gold;
cv::erode(img_gray, dst_gold, kernel, anchor, iterations);
dev_dst_rgba.download(dst_rgba); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
TEST_P(Erode, Gray) TEST_P(Erode, Color)
{ {
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray; cv::gpu::GpuMat dst;
cv::gpu::erode(loadMat(img_rgba, useRoi), dst, kernel, anchor, iterations);
cv::gpu::erode(loadMat(img_gray, useRoi), dev_dst_gray, kernel); cv::Mat dst_gold;
cv::erode(img_rgba, dst_gold, kernel, anchor, iterations);
dev_dst_gray.download(dst_gray); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Erode, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Erode, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// dilate // Dilate
PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, UseRoi) PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, Anchor, Iterations, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Point anchor;
int iterations;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat kernel; cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
useRoi = GET_PARAM(1); anchor = GET_PARAM(1);
iterations = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
kernel = cv::Mat::ones(3, 3, CV_8U); img = readImage("stereobp/aloe-L.png");
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA); kernel = cv::Mat::ones(3, 3, CV_8U);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::dilate(img_rgba, dst_gold_rgba, kernel);
cv::dilate(img_gray, dst_gold_gray, kernel);
} }
}; };
TEST_P(Dilate, Rgba) TEST_P(Dilate, Gray)
{ {
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba; cv::gpu::GpuMat dst;
cv::gpu::dilate(loadMat(img_gray, useRoi), dst, kernel, anchor, iterations);
cv::gpu::dilate(loadMat(img_rgba, useRoi), dev_dst_rgba, kernel); cv::Mat dst_gold;
cv::dilate(img_gray, dst_gold, kernel, anchor, iterations);
dev_dst_rgba.download(dst_rgba); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
TEST_P(Dilate, Gray) TEST_P(Dilate, Color)
{ {
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray; cv::gpu::GpuMat dst;
cv::gpu::dilate(loadMat(img_rgba, useRoi), dst, kernel, anchor, iterations);
cv::gpu::dilate(loadMat(img_gray, useRoi), dev_dst_gray, kernel); cv::Mat dst_gold;
cv::dilate(img_rgba, dst_gold, kernel, anchor, iterations);
dev_dst_gray.download(dst_gray); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, Dilate, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Dilate, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// morphEx // MorphEx
CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT)
#define ALL_MORPH_OPS testing::Values(MorphOp(cv::MORPH_OPEN), MorphOp(cv::MORPH_CLOSE), MorphOp(cv::MORPH_GRADIENT), MorphOp(cv::MORPH_TOPHAT), MorphOp(cv::MORPH_BLACKHAT))
PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, MorphOp, UseRoi) PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, MorphOp, Anchor, Iterations, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int morphOp; int morphOp;
cv::Point anchor;
int iterations;
bool useRoi; bool useRoi;
cv::Mat img_rgba; cv::Mat img;
cv::Mat img_gray;
cv::Mat kernel; cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
virtual void SetUp() virtual void SetUp()
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
morphOp = GET_PARAM(1); morphOp = GET_PARAM(1);
useRoi = GET_PARAM(2); anchor = GET_PARAM(2);
iterations = GET_PARAM(3);
useRoi = GET_PARAM(4);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
kernel = cv::Mat::ones(3, 3, CV_8U); kernel = cv::Mat::ones(3, 3, CV_8U);
cv::morphologyEx(img_rgba, dst_gold_rgba, morphOp, kernel);
cv::morphologyEx(img_gray, dst_gold_gray, morphOp, kernel);
} }
}; };
TEST_P(MorphEx, Rgba) TEST_P(MorphEx, Gray)
{ {
cv::Mat dst_rgba; cv::Mat img_gray;
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::gpu::GpuMat dev_dst_rgba; cv::gpu::GpuMat dst;
cv::gpu::morphologyEx(loadMat(img_gray, useRoi), dst, morphOp, kernel, anchor, iterations);
cv::gpu::morphologyEx(loadMat(img_rgba, useRoi), dev_dst_rgba, morphOp, kernel); cv::Mat dst_gold;
cv::morphologyEx(img_gray, dst_gold, morphOp, kernel, anchor, iterations);
dev_dst_rgba.download(dst_rgba); cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 4, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0);
} }
TEST_P(MorphEx, Gray) TEST_P(MorphEx, Color)
{ {
cv::Mat dst_gray; cv::Mat img_rgba;
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::gpu::GpuMat dev_dst_gray; cv::gpu::GpuMat dst;
cv::gpu::morphologyEx(loadMat(img_rgba, useRoi), dst, morphOp, kernel, anchor, iterations);
cv::gpu::morphologyEx(loadMat(img_gray, useRoi), dev_dst_gray, morphOp, kernel); cv::Mat dst_gold;
cv::morphologyEx(img_rgba, dst_gold, morphOp, kernel, anchor, iterations);
dev_dst_gray.download(dst_gray); cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 4, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0);
} }
INSTANTIATE_TEST_CASE_P(Filter, MorphEx, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, MorphEx, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values((int)cv::MORPH_OPEN, (int)cv::MORPH_CLOSE, (int)cv::MORPH_GRADIENT, (int)cv::MORPH_TOPHAT, (int)cv::MORPH_BLACKHAT), ALL_MORPH_OPS,
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// filter2D // Filter2D
PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, int, UseRoi) PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, KSize, Anchor, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int ksize; cv::Size ksize;
cv::Point anchor;
bool useRoi; bool useRoi;
cv::Mat img; cv::Mat img;
@ -651,78 +639,63 @@ PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, int, UseRoi)
{ {
devInfo = GET_PARAM(0); devInfo = GET_PARAM(0);
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
useRoi = GET_PARAM(2); anchor = GET_PARAM(2);
useRoi = GET_PARAM(3);
cv::gpu::setDevice(devInfo.deviceID()); cv::gpu::setDevice(devInfo.deviceID());
img = readImage("stereobp/aloe-L.png"); img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
kernel = cv::Mat::ones(ksize, ksize, CV_32FC1); kernel = cv::Mat::ones(ksize.height, ksize.width, CV_32FC1);
} }
}; };
TEST_P(Filter2D, Rgba) TEST_P(Filter2D, Gray)
{ {
cv::Mat src; cv::Mat img_gray;
cv::cvtColor(img, src, CV_BGR2BGRA); cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Mat dst_gold;
cv::filter2D(src, dst_gold, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_CONSTANT);
cv::Mat dst;
cv::gpu::GpuMat dev_dst;
cv::gpu::filter2D(loadMat(src, useRoi), dev_dst, -1, kernel); cv::gpu::GpuMat dst;
cv::gpu::filter2D(loadMat(img_gray, useRoi), dst, -1, kernel, anchor);
dev_dst.download(dst); cv::Mat dst_gold;
cv::filter2D(img_gray, dst_gold, -1, kernel, anchor, 0, cv::BORDER_CONSTANT);
EXPECT_MAT_NEAR_KSIZE(dst_gold, dst, ksize, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
TEST_P(Filter2D, Gray) TEST_P(Filter2D, Color)
{ {
cv::Mat src; cv::Mat img_rgba;
cv::cvtColor(img, src, CV_BGR2GRAY); cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::Mat dst_gold;
cv::filter2D(src, dst_gold, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_CONSTANT);
cv::Mat dst;
cv::gpu::GpuMat dev_dst;
cv::gpu::filter2D(loadMat(src, useRoi), dev_dst, -1, kernel); cv::gpu::GpuMat dst;
cv::gpu::filter2D(loadMat(img_rgba, useRoi), dst, -1, kernel, anchor);
dev_dst.download(dst); cv::Mat dst_gold;
cv::filter2D(img_rgba, dst_gold, -1, kernel, anchor, 0, cv::BORDER_CONSTANT);
EXPECT_MAT_NEAR_KSIZE(dst_gold, dst, ksize, 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
} }
TEST_P(Filter2D, 32FC1) TEST_P(Filter2D, Gray_32FC1)
{ {
cv::Mat src; cv::Mat src;
cv::cvtColor(img, src, CV_BGR2GRAY); cv::cvtColor(img, src, CV_BGR2GRAY);
src.convertTo(src, CV_32F, 1.0 / 255.0); src.convertTo(src, CV_32F, 1.0 / 255.0);
cv::Mat dst_gold; cv::gpu::GpuMat dst;
cv::filter2D(src, dst_gold, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_CONSTANT); cv::gpu::filter2D(loadMat(src, useRoi), dst, -1, kernel, anchor);
cv::Mat dst;
cv::gpu::GpuMat dev_dst;
cv::gpu::filter2D(loadMat(src, useRoi), dev_dst, -1, kernel); cv::Mat dst_gold;
cv::filter2D(src, dst_gold, -1, kernel, anchor);
dev_dst.download(dst);
EXPECT_MAT_NEAR_KSIZE(dst_gold, dst, ksize, 1e-3); EXPECT_MAT_NEAR(dst_gold, dst, 1e-3);
} }
INSTANTIATE_TEST_CASE_P(Filter, Filter2D, Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine(
ALL_DEVICES, ALL_DEVICES,
Values(3, 5, 7, 11, 13, 15), testing::Values(KSize(3, 3), KSize(5, 5), KSize(7, 7), KSize(11, 11), KSize(13, 13), KSize(15, 15)),
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
#endif // HAVE_CUDA

@ -2198,7 +2198,7 @@ INSTANTIATE_TEST_CASE_P(ImgProc, EqualizeHist, ALL_DEVICES);
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// cornerHarris // cornerHarris
PARAM_TEST_CASE(CornerHarris, cv::gpu::DeviceInfo, MatType, Border, int, int) PARAM_TEST_CASE(CornerHarris, cv::gpu::DeviceInfo, MatType, BorderType, int, int)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int type; int type;
@ -2257,7 +2257,7 @@ INSTANTIATE_TEST_CASE_P(ImgProc, CornerHarris, Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// cornerMinEigen // cornerMinEigen
PARAM_TEST_CASE(CornerMinEigen, cv::gpu::DeviceInfo, MatType, Border, int, int) PARAM_TEST_CASE(CornerMinEigen, cv::gpu::DeviceInfo, MatType, BorderType, int, int)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
int type; int type;
@ -2572,6 +2572,8 @@ INSTANTIATE_TEST_CASE_P(ImgProc, MeanShiftSegmentation, Combine(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// matchTemplate // matchTemplate
CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED)
PARAM_TEST_CASE(MatchTemplate8U, cv::gpu::DeviceInfo, int, TemplateMethod) PARAM_TEST_CASE(MatchTemplate8U, cv::gpu::DeviceInfo, int, TemplateMethod)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
@ -2776,6 +2778,8 @@ INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate_CCOEF_NORMED, Combine(
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// MulSpectrums // MulSpectrums
CV_FLAGS(DftFlags, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
PARAM_TEST_CASE(MulSpectrums, cv::gpu::DeviceInfo, DftFlags) PARAM_TEST_CASE(MulSpectrums, cv::gpu::DeviceInfo, DftFlags)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;

@ -109,7 +109,7 @@ namespace
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Test // Test
PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Border, UseRoi) PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -171,7 +171,7 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Remap, testing::Combine(
DIFFERENT_SIZES, DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), 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(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_CONSTANT), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
#endif // HAVE_CUDA #endif // HAVE_CUDA

@ -43,6 +43,9 @@
#ifdef HAVE_CUDA #ifdef HAVE_CUDA
CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV)
#define ALL_THRESH_OPS testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV))
PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, UseRoi) PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;

@ -175,7 +175,7 @@ namespace
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Test // Test
PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, Border, UseRoi) PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -225,7 +225,7 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffine, testing::Combine(
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(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, DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////

@ -175,7 +175,7 @@ namespace
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Test // Test
PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, Border, UseRoi) PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
{ {
cv::gpu::DeviceInfo devInfo; cv::gpu::DeviceInfo devInfo;
cv::Size size; cv::Size size;
@ -225,7 +225,7 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspective, testing::Combine(
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(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, DIRECT_INVERSE,
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
WHOLE_SUBMAT)); WHOLE_SUBMAT));
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////

@ -47,6 +47,9 @@ using namespace cv::gpu;
using namespace cvtest; using namespace cvtest;
using namespace testing; using namespace testing;
//////////////////////////////////////////////////////////////////////
// random generators
int randomInt(int minVal, int maxVal) int randomInt(int minVal, int maxVal)
{ {
RNG& rng = TS::ptr()->get_rng(); RNG& rng = TS::ptr()->get_rng();
@ -74,6 +77,9 @@ Mat randomMat(Size size, int type, double minVal, double maxVal)
return randomMat(TS::ptr()->get_rng(), size, type, minVal, maxVal, false); return randomMat(TS::ptr()->get_rng(), size, type, minVal, maxVal, false);
} }
//////////////////////////////////////////////////////////////////////
// GpuMat create
cv::gpu::GpuMat createMat(cv::Size size, int type, bool useRoi) cv::gpu::GpuMat createMat(cv::Size size, int type, bool useRoi)
{ {
Size size0 = size; Size size0 = size;
@ -99,6 +105,30 @@ GpuMat loadMat(const Mat& m, bool useRoi)
return d_m; return d_m;
} }
//////////////////////////////////////////////////////////////////////
// Image load
Mat readImage(const string& fileName, int flags)
{
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
}
Mat readImageType(const string& fname, int type)
{
Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
if (CV_MAT_CN(type) == 4)
{
Mat temp;
cvtColor(src, temp, cv::COLOR_BGR2BGRA);
swap(src, temp);
}
src.convertTo(src, CV_MAT_DEPTH(type));
return src;
}
//////////////////////////////////////////////////////////////////////
// Gpu devices
bool supportFeature(const DeviceInfo& info, FeatureSet feature) bool supportFeature(const DeviceInfo& info, FeatureSet feature)
{ {
return TargetArchs::builtWith(feature) && info.supports(feature); return TargetArchs::builtWith(feature) && info.supports(feature);
@ -150,86 +180,146 @@ vector<DeviceInfo> devices(FeatureSet feature)
return devs_filtered; return devs_filtered;
} }
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end) //////////////////////////////////////////////////////////////////////
{ // Additional assertion
vector<MatType> v;
v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
for (int depth = depth_start; depth <= depth_end; ++depth) Mat getMat(InputArray arr)
{ {
for (int cn = cn_start; cn <= cn_end; ++cn) if (arr.kind() == _InputArray::GPU_MAT)
{ {
v.push_back(CV_MAKETYPE(depth, cn)); Mat m;
} arr.getGpuMat().download(m);
return m;
} }
return v; return arr.getMat();
} }
const vector<MatType>& all_types() double checkNorm(InputArray m1, const InputArray m2)
{ {
static vector<MatType> v = types(CV_8U, CV_64F, 1, 4); return norm(getMat(m1), getMat(m2), NORM_INF);
return v;
} }
Mat readImage(const string& fileName, int flags) void minMaxLocGold(const Mat& src, double* minVal_, double* maxVal_, Point* minLoc_, Point* maxLoc_, const Mat& mask)
{ {
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags); if (src.depth() != CV_8S)
} {
minMaxLoc(src, minVal_, maxVal_, minLoc_, maxLoc_, mask);
return;
}
Mat readImageType(const string& fname, int type) // OpenCV's minMaxLoc doesn't support CV_8S type
{ double minVal = numeric_limits<double>::max();
Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR); Point minLoc(-1, -1);
if (CV_MAT_CN(type) == 4)
double maxVal = -numeric_limits<double>::max();
Point maxLoc(-1, -1);
for (int y = 0; y < src.rows; ++y)
{ {
Mat temp; const schar* src_row = src.ptr<signed char>(y);
cvtColor(src, temp, cv::COLOR_BGR2BGRA); const uchar* mask_row = mask.empty() ? 0 : mask.ptr<unsigned char>(y);
swap(src, temp);
for (int x = 0; x < src.cols; ++x)
{
if (!mask_row || mask_row[x])
{
schar val = src_row[x];
if (val < minVal)
{
minVal = val;
minLoc = cv::Point(x, y);
} }
src.convertTo(src, CV_MAT_DEPTH(type));
return src; if (val > maxVal)
{
maxVal = val;
maxLoc = cv::Point(x, y);
}
}
}
}
if (minVal_) *minVal_ = minVal;
if (maxVal_) *maxVal_ = maxVal;
if (minLoc_) *minLoc_ = minLoc;
if (maxLoc_) *maxLoc_ = maxLoc;
} }
namespace namespace
{ {
Mat getMat(InputArray arr) template <typename T, typename OutT> string printMatValImpl(const Mat& m, Point p)
{ {
if (arr.kind() == _InputArray::GPU_MAT) const int cn = m.channels();
ostringstream ostr;
ostr << "(";
p.x /= cn;
ostr << static_cast<OutT>(m.at<T>(p.y, p.x * cn));
for (int c = 1; c < m.channels(); ++c)
{ {
Mat m; ostr << ", " << static_cast<OutT>(m.at<T>(p.y, p.x * cn + c));
arr.getGpuMat().download(m);
return m;
} }
ostr << ")";
return arr.getMat(); return ostr.str();
}
string printMatVal(const Mat& m, Point p)
{
typedef string (*func_t)(const Mat& m, Point p);
static const func_t funcs[] =
{
printMatValImpl<uchar, int>, printMatValImpl<schar, int>, printMatValImpl<ushort, int>, printMatValImpl<short, int>,
printMatValImpl<int, int>, printMatValImpl<float, float>, printMatValImpl<double, double>
};
return funcs[m.depth()](m, p);
} }
} }
void showDiff(InputArray gold_, InputArray actual_, double eps) testing::AssertionResult assertMatNear(const char* expr1, const char* expr2, const char* eps_expr, cv::InputArray m1_, cv::InputArray m2_, double eps)
{ {
Mat gold = getMat(gold_); Mat m1 = getMat(m1_);
Mat actual = getMat(actual_); Mat m2 = getMat(m2_);
Mat diff; if (m1.size() != m2.size())
absdiff(gold, actual, diff); {
threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY); return AssertionFailure() << "Matrices \"" << expr1 << "\" and \"" << expr2 << "\" have different sizes : \""
<< expr1 << "\" [" << PrintToString(m1.size()) << "] vs \""
<< expr2 << "\" [" << PrintToString(m2.size()) << "]";
}
namedWindow("gold", WINDOW_NORMAL); if (m1.type() != m2.type())
namedWindow("actual", WINDOW_NORMAL); {
namedWindow("diff", WINDOW_NORMAL); return AssertionFailure() << "Matrices \"" << expr1 << "\" and \"" << expr2 << "\" have different types : \""
<< expr1 << "\" [" << PrintToString(MatType(m1.type())) << "] vs \""
<< expr2 << "\" [" << PrintToString(MatType(m2.type())) << "]";
}
imshow("gold", gold); Mat diff;
imshow("actual", actual); absdiff(m1.reshape(1), m2.reshape(1), diff);
imshow("diff", diff);
waitKey(); double maxVal = 0.0;
} Point maxLoc;
minMaxLocGold(diff, 0, &maxVal, 0, &maxLoc);
double checkNorm(InputArray m1, const InputArray m2) if (maxVal > eps)
{ {
return norm(getMat(m1), getMat(m2), NORM_INF); return AssertionFailure() << "The max difference between matrices \"" << expr1 << "\" and \"" << expr2
<< "\" is " << maxVal << " at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ")"
<< ", which exceeds \"" << eps_expr << "\", where \""
<< expr1 << "\" at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ") evaluates to " << printMatVal(m1, maxLoc) << ", \""
<< expr2 << "\" at (" << maxLoc.y << ", " << maxLoc.x / m1.channels() << ") evaluates to " << printMatVal(m2, maxLoc) << ", \""
<< eps_expr << "\" evaluates to " << eps;
}
return AssertionSuccess();
} }
double checkSimilarity(InputArray m1, InputArray m2) double checkSimilarity(InputArray m1, InputArray m2)
@ -239,6 +329,45 @@ double checkSimilarity(InputArray m1, InputArray m2)
return std::abs(diff.at<float>(0, 0) - 1.f); return std::abs(diff.at<float>(0, 0) - 1.f);
} }
//////////////////////////////////////////////////////////////////////
// Helper structs for value-parameterized tests
vector<MatDepth> depths(int depth_start, int depth_end)
{
vector<MatDepth> v;
v.reserve((depth_end - depth_start + 1));
for (int depth = depth_start; depth <= depth_end; ++depth)
v.push_back(depth);
return v;
}
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
{
vector<MatType> v;
v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
for (int depth = depth_start; depth <= depth_end; ++depth)
{
for (int cn = cn_start; cn <= cn_end; ++cn)
{
v.push_back(CV_MAKETYPE(depth, cn));
}
}
return v;
}
const vector<MatType>& all_types()
{
static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
return v;
}
void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os) void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os)
{ {
(*os) << info.name(); (*os) << info.name();
@ -259,3 +388,23 @@ void PrintTo(const Inverse& inverse, std::ostream* os)
else else
(*os) << "direct"; (*os) << "direct";
} }
void showDiff(InputArray gold_, InputArray actual_, double eps)
{
Mat gold = getMat(gold_);
Mat actual = getMat(actual_);
Mat diff;
absdiff(gold, actual, diff);
threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
namedWindow("gold", WINDOW_NORMAL);
namedWindow("actual", WINDOW_NORMAL);
namedWindow("diff", WINDOW_NORMAL);
imshow("gold", gold);
imshow("actual", actual);
imshow("diff", diff);
waitKey();
}

@ -42,37 +42,66 @@
#ifndef __OPENCV_TEST_UTILITY_HPP__ #ifndef __OPENCV_TEST_UTILITY_HPP__
#define __OPENCV_TEST_UTILITY_HPP__ #define __OPENCV_TEST_UTILITY_HPP__
#include <vector>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
//////////////////////////////////////////////////////////////////////
// random generators
int randomInt(int minVal, int maxVal); int randomInt(int minVal, int maxVal);
double randomDouble(double minVal, double maxVal); double randomDouble(double minVal, double maxVal);
cv::Size randomSize(int minVal, int maxVal); cv::Size randomSize(int minVal, int maxVal);
cv::Scalar randomScalar(double minVal, double maxVal); cv::Scalar randomScalar(double minVal, double maxVal);
cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0); cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
//////////////////////////////////////////////////////////////////////
// GpuMat create
cv::gpu::GpuMat createMat(cv::Size size, int type, bool useRoi = false); cv::gpu::GpuMat createMat(cv::Size size, int type, bool useRoi = false);
cv::gpu::GpuMat loadMat(const cv::Mat& m, bool useRoi = false); cv::gpu::GpuMat loadMat(const cv::Mat& m, bool useRoi = false);
void showDiff(cv::InputArray gold, cv::InputArray actual, double eps); //////////////////////////////////////////////////////////////////////
// Image load
//! read image from testdata folder
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
//! read image from testdata folder and convert it to specified type
cv::Mat readImageType(const std::string& fname, int type);
//////////////////////////////////////////////////////////////////////
// Gpu devices
//! return true if device supports specified feature and gpu module was built with support the feature. //! return true if device supports specified feature and gpu module was built with support the feature.
bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature); bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
//! return all devices compatible with current gpu module build. //! return all devices compatible with current gpu module build.
const std::vector<cv::gpu::DeviceInfo>& devices(); const std::vector<cv::gpu::DeviceInfo>& devices();
//! return all devices compatible with current gpu module build which support specified feature. //! return all devices compatible with current gpu module build which support specified feature.
std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature); std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature);
//! read image from testdata folder. #define ALL_DEVICES testing::ValuesIn(devices())
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR); #define DEVICES(feature) testing::ValuesIn(devices(feature))
cv::Mat readImageType(const std::string& fname, int type);
//////////////////////////////////////////////////////////////////////
// Additional assertion
cv::Mat getMat(cv::InputArray arr);
double checkNorm(cv::InputArray m1, cv::InputArray m2); double checkNorm(cv::InputArray m1, cv::InputArray m2);
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \ void minMaxLocGold(const cv::Mat& src, double* minVal_, double* maxVal_ = 0, cv::Point* minLoc_ = 0, cv::Point* maxLoc_ = 0, const cv::Mat& mask = cv::Mat());
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \ testing::AssertionResult assertMatNear(const char* expr1, const char* expr2, const char* eps_expr, cv::InputArray m1, cv::InputArray m2, double eps);
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNorm(mat1, mat2), eps); \ #define EXPECT_MAT_NEAR(m1, m2, eps) EXPECT_PRED_FORMAT3(assertMatNear, m1, m2, eps)
} #define ASSERT_MAT_NEAR(m1, m2, eps) ASSERT_PRED_FORMAT3(assertMatNear, m1, m2, eps)
#define EXPECT_SCALAR_NEAR(s1, s2, eps) \ #define EXPECT_SCALAR_NEAR(s1, s2, eps) \
{ \ { \
@ -81,6 +110,37 @@ double checkNorm(cv::InputArray m1, cv::InputArray m2);
EXPECT_NEAR(s1[2], s2[2], eps); \ EXPECT_NEAR(s1[2], s2[2], eps); \
EXPECT_NEAR(s1[3], s2[3], eps); \ EXPECT_NEAR(s1[3], s2[3], eps); \
} }
#define ASSERT_SCALAR_NEAR(s1, s2, eps) \
{ \
ASSERT_NEAR(s1[0], s2[0], eps); \
ASSERT_NEAR(s1[1], s2[1], eps); \
ASSERT_NEAR(s1[2], s2[2], eps); \
ASSERT_NEAR(s1[3], s2[3], eps); \
}
#define EXPECT_POINT2_NEAR(p1, p2, eps) \
{ \
EXPECT_NEAR(p1.x, p2.x, eps); \
EXPECT_NEAR(p1.y, p2.y, eps); \
}
#define ASSERT_POINT2_NEAR(p1, p2, eps) \
{ \
ASSERT_NEAR(p1.x, p2.x, eps); \
ASSERT_NEAR(p1.y, p2.y, eps); \
}
#define EXPECT_POINT3_NEAR(p1, p2, eps) \
{ \
EXPECT_NEAR(p1.x, p2.x, eps); \
EXPECT_NEAR(p1.y, p2.y, eps); \
EXPECT_NEAR(p1.z, p2.z, eps); \
}
#define ASSERT_POINT3_NEAR(p1, p2, eps) \
{ \
ASSERT_NEAR(p1.x, p2.x, eps); \
ASSERT_NEAR(p1.y, p2.y, eps); \
ASSERT_NEAR(p1.z, p2.z, eps); \
}
double checkSimilarity(cv::InputArray m1, cv::InputArray m2); double checkSimilarity(cv::InputArray m1, cv::InputArray m2);
@ -90,13 +150,63 @@ double checkSimilarity(cv::InputArray m1, cv::InputArray m2);
ASSERT_EQ(mat1.size(), mat2.size()); \ ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkSimilarity(mat1, mat2), eps); \ EXPECT_LE(checkSimilarity(mat1, mat2), eps); \
} }
#define ASSERT_MAT_SIMILAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
ASSERT_LE(checkSimilarity(mat1, mat2), eps); \
}
//////////////////////////////////////////////////////////////////////
// Helper structs for value-parameterized tests
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
namespace cv { namespace gpu namespace cv { namespace gpu
{ {
void PrintTo(const DeviceInfo& info, std::ostream* os); void PrintTo(const DeviceInfo& info, std::ostream* os);
}} }}
#define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113))
// Depth
using perf::MatDepth; using perf::MatDepth;
//! return vector with depths from specified range.
std::vector<MatDepth> depths(int depth_start, int depth_end);
#define ALL_DEPTH testing::Values(MatDepth(CV_8U), MatDepth(CV_8S), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32S), MatDepth(CV_32F), MatDepth(CV_64F))
#define DEPTHS(depth_start, depth_end) testing::ValuesIn(depths(depth_start, depth_end))
#define DEPTH_PAIRS testing::Values(std::make_pair(MatDepth(CV_8U), MatDepth(CV_8U)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16U)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16S)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_16U), MatDepth(CV_16U)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_16S), MatDepth(CV_16S)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_32S), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_32F), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_32F), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_64F), MatDepth(CV_64F)))
// Type
using perf::MatType; using perf::MatType;
//! return vector with types from specified range. //! return vector with types from specified range.
@ -105,6 +215,11 @@ std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4). //! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
const std::vector<MatType>& all_types(); const std::vector<MatType>& all_types();
#define ALL_TYPES testing::ValuesIn(all_types())
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
// ROI
class UseRoi class UseRoi
{ {
public: public:
@ -115,11 +230,15 @@ public:
private: private:
bool val_; bool val_;
}; };
void PrintTo(const UseRoi& useRoi, std::ostream* os); void PrintTo(const UseRoi& useRoi, std::ostream* os);
#define WHOLE testing::Values(UseRoi(false)) #define WHOLE testing::Values(UseRoi(false))
#define SUBMAT testing::Values(UseRoi(true)) #define SUBMAT testing::Values(UseRoi(true))
#define WHOLE_SUBMAT testing::Values(UseRoi(false), UseRoi(true)) #define WHOLE_SUBMAT testing::Values(UseRoi(false), UseRoi(true))
// Direct/Inverse
class Inverse class Inverse
{ {
public: public:
@ -133,75 +252,41 @@ private:
void PrintTo(const Inverse& useRoi, std::ostream* os); void PrintTo(const Inverse& useRoi, std::ostream* os);
#define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true)) #define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true))
CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE) // Param class
#define ALL_CMP_CODES testing::Values(CmpCode(cv::CMP_EQ), CmpCode(cv::CMP_NE), CmpCode(cv::CMP_GT), CmpCode(cv::CMP_GE), CmpCode(cv::CMP_LT), CmpCode(cv::CMP_LE))
CV_ENUM(NormCode, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_TYPE_MASK, cv::NORM_RELATIVE, cv::NORM_MINMAX)
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y))
CV_ENUM(ReduceCode, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) #define IMPLEMENT_PARAM_CLASS(name, type) \
#define ALL_REDUCE_CODES testing::Values(ReduceCode(CV_REDUCE_SUM), ReduceCode(CV_REDUCE_AVG), ReduceCode(CV_REDUCE_MAX), ReduceCode(CV_REDUCE_MIN)) class name \
{ \
public: \
name ( type arg = type ()) : val_(arg) {} \
operator type () const {return val_;} \
private: \
type val_; \
}; \
inline void PrintTo( name param, std::ostream* os) \
{ \
*os << #name << "(" << static_cast< type >(param) << ")"; \
}
CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T); IMPLEMENT_PARAM_CLASS(Channels, int)
#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
CV_ENUM(DistType, cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist) #define ALL_CHANNELS testing::Values(Channels(1), Channels(2), Channels(3), Channels(4))
#define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4))
CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT) // Flags and enums
CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV) CV_ENUM(NormCode, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_TYPE_MASK, cv::NORM_RELATIVE, cv::NORM_MINMAX)
#define ALL_THRESH_OPS testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV))
CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC) CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC)
CV_ENUM(Border, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP) CV_ENUM(BorderType, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP)
#define ALL_BORDER_TYPES testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP))
CV_FLAGS(WarpFlags, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::WARP_INVERSE_MAP) CV_FLAGS(WarpFlags, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::WARP_INVERSE_MAP)
CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED) //////////////////////////////////////////////////////////////////////
// Other
CV_FLAGS(DftFlags, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define ALL_DEVICES testing::ValuesIn(devices())
#define DEVICES(feature) testing::ValuesIn(devices(feature))
#define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113))
#define ALL_DEPTH testing::Values(MatDepth(CV_8U), MatDepth(CV_8S), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32S), MatDepth(CV_32F), MatDepth(CV_64F))
#define ALL_TYPES testing::ValuesIn(all_types())
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
#define DEPTH_PAIRS testing::Values(std::make_pair(MatDepth(CV_8U), MatDepth(CV_8U)), \ void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16U)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16S)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_8U), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_16U), MatDepth(CV_16U)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_16U), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_16S), MatDepth(CV_16S)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_16S), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32S)), \
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_32S), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_32F), MatDepth(CV_32F)), \
std::make_pair(MatDepth(CV_32F), MatDepth(CV_64F)), \
\
std::make_pair(MatDepth(CV_64F), MatDepth(CV_64F)))
#endif // __OPENCV_TEST_UTILITY_HPP__ #endif // __OPENCV_TEST_UTILITY_HPP__

Loading…
Cancel
Save