vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:11:13 +08:00
commit 12022378a3
3872 changed files with 2513409 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
set(test_deps opencv_cudev opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui opencv_ts ${OPENCV_MODULE_opencv_ts_DEPS})
ocv_check_dependencies(${test_deps})
if(OCV_DEPENDENCIES_FOUND)
set(the_target "opencv_test_${name}")
ocv_module_include_directories("${test_deps}" "${the_module}")
file(GLOB test_srcs "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.cu")
file(GLOB test_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
source_group("Src" FILES ${test_srcs})
source_group("Include" FILES ${test_hdrs})
set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs})
ocv_cuda_filter_options()
set(target_libs ${test_deps} ${OPENCV_LINKER_LIBS})
if(NOT ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_check_windows_crt_linkage()
set(target_libs ${target_libs} ${CUDA_LIBRARIES})
set(test_cudev_cuda_options "")
if(CUDA_VERSION VERSION_LESS "11.0")
# Windows version does not support --std option
if(UNIX OR APPLE)
list(APPEND test_cudev_cuda_options "-std=c++11")
endif()
else()
if(CUDA_VERSION VERSION_LESS "12.8")
list(APPEND test_cudev_cuda_options "-std=c++14")
else()
list(APPEND test_cudev_cuda_options "-std=c++17")
if(WIN32)
list(APPEND test_cudev_cuda_options "-Xcompiler=/Zc:preprocessor")
endif()
endif()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
endif()
CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${test_cudev_cuda_options})
else()
ocv_add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES})
endif()
ocv_target_link_libraries(${the_target} PRIVATE ${target_libs})
add_dependencies(opencv_tests ${the_target})
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}")
set_source_files_properties(${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch}
PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest")
# Additional target properties
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
endif()
ocv_add_test_from_target("${the_target}" "Accuracy" "${the_target}")
if(INSTALL_TESTS)
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
endif()
endif()
+168
View File
@@ -0,0 +1,168 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
////////////////////////////////////////////////////////////////////////////////
// SqrtTest
template <typename T>
class SqrtTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst = sqrt_(d_src);
Mat dst_gold;
cv::sqrt(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
}
void test_expr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = sqrt_(d_src1 * d_src2);
Mat dst_gold;
cv::multiply(src1, src2, dst_gold);
cv::sqrt(dst_gold, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
}
};
TYPED_TEST_CASE(SqrtTest, float);
TYPED_TEST(SqrtTest, GpuMat)
{
SqrtTest<TypeParam>::test_gpumat();
}
TYPED_TEST(SqrtTest, Expr)
{
SqrtTest<TypeParam>::test_expr();
}
////////////////////////////////////////////////////////////////////////////////
// MagnitudeTest
template <typename T>
class MagnitudeTest : public ::testing::Test
{
public:
void test_accuracy()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst1 = hypot_(d_src1, d_src2);
GpuMat_<T> dst2 = magnitude_(d_src1, d_src2);
GpuMat_<T> dst3 = sqrt_(sqr_(d_src1) + sqr_(d_src2));
EXPECT_MAT_NEAR(dst1, dst2, 1e-4);
EXPECT_MAT_NEAR(dst2, dst3, 0.0);
}
};
TYPED_TEST_CASE(MagnitudeTest, float);
TYPED_TEST(MagnitudeTest, Accuracy)
{
MagnitudeTest<TypeParam>::test_accuracy();
}
////////////////////////////////////////////////////////////////////////////////
// PowTest
template <typename T>
class PowTest : public ::testing::Test
{
public:
void test_accuracy()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst1 = pow_(d_src, 0.5);
GpuMat_<T> dst2 = sqrt_(d_src);
EXPECT_MAT_NEAR(dst1, dst2, 1e-5);
}
};
TYPED_TEST_CASE(PowTest, float);
TYPED_TEST(PowTest, Accuracy)
{
PowTest<TypeParam>::test_accuracy();
}
+395
View File
@@ -0,0 +1,395 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
typedef ::testing::Types<uchar, ushort, short, int, float> AllTypes;
typedef ::testing::Types<short, int, float> SignedTypes;
////////////////////////////////////////////////////////////////////////////////
// UnaryMinusTest
template <typename T>
class UnaryMinusTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst = -d_src;
Mat dst_gold;
src.convertTo(dst_gold, src.depth(), -1);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_globptr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GlobPtrSz<T> d_src_ptr = d_src;
GpuMat_<T> dst = -d_src_ptr;
Mat dst_gold;
src.convertTo(dst_gold, src.depth(), -1);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_texptr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
Texture<T> tex_src(d_src);
GpuMat_<T> dst = -tex_src;
Mat dst_gold;
src.convertTo(dst_gold, src.depth(), -1);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_expr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = -(d_src1 + d_src2);
Mat dst_gold;
cv::add(src1, src2, dst_gold);
dst_gold.convertTo(dst_gold, dst_gold.depth(), -1);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(UnaryMinusTest, SignedTypes);
TYPED_TEST(UnaryMinusTest, GpuMat)
{
UnaryMinusTest<TypeParam>::test_gpumat();
}
TYPED_TEST(UnaryMinusTest, GlobPtrSz)
{
UnaryMinusTest<TypeParam>::test_globptr();
}
TYPED_TEST(UnaryMinusTest, TexturePtr)
{
UnaryMinusTest<TypeParam>::test_texptr();
}
TYPED_TEST(UnaryMinusTest, Expr)
{
UnaryMinusTest<TypeParam>::test_expr();
}
////////////////////////////////////////////////////////////////////////////////
// PlusTest
template <typename T>
class PlusTest : public ::testing::Test
{
public:
void test_gpumat_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = d_src1 + d_src2;
Mat dst_gold;
cv::add(src1, src2, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_texptr_scalar()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
Texture<T> tex_src(d_src);
GpuMat_<T> dst = tex_src + static_cast<T>(5);
Mat dst_gold;
cv::add(src, 5, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_expr_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
Mat src3 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2), d_src3(src3);
GpuMat_<T> dst = d_src1 + d_src2 + d_src3;
Mat dst_gold;
cv::add(src1, src2, dst_gold);
cv::add(dst_gold, src3, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_scalar_expr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = static_cast<T>(5) + (d_src1 + d_src2);
Mat dst_gold;
cv::add(src1, src2, dst_gold);
cv::add(dst_gold, 5, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(PlusTest, AllTypes);
TYPED_TEST(PlusTest, GpuMat_GpuMat)
{
PlusTest<TypeParam>::test_gpumat_gpumat();
}
TYPED_TEST(PlusTest, TexturePtr_Scalar)
{
PlusTest<TypeParam>::test_texptr_scalar();
}
TYPED_TEST(PlusTest, Expr_GpuMat)
{
PlusTest<TypeParam>::test_expr_gpumat();
}
TYPED_TEST(PlusTest, Scalar_Expr)
{
PlusTest<TypeParam>::test_scalar_expr();
}
////////////////////////////////////////////////////////////////////////////////
// MinusTest
template <typename T>
class MinusTest : public ::testing::Test
{
public:
void test_gpumat_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = d_src1 - d_src2;
Mat dst_gold;
cv::subtract(src1, src2, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_texptr_scalar()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
Texture<T> tex_src(d_src);
GpuMat_<T> dst = tex_src - static_cast<T>(5);
Mat dst_gold;
cv::subtract(src, 5, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_expr_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
Mat src3 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2), d_src3(src3);
GpuMat_<T> dst = (d_src1 + d_src2) - d_src3;
Mat dst_gold;
cv::add(src1, src2, dst_gold);
cv::subtract(dst_gold, src3, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_scalar_expr()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = static_cast<T>(5) - (d_src1 + d_src2);
Mat dst_gold;
cv::add(src1, src2, dst_gold);
cv::subtract(5, dst_gold, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(MinusTest, SignedTypes);
TYPED_TEST(MinusTest, GpuMat_GpuMat)
{
MinusTest<TypeParam>::test_gpumat_gpumat();
}
TYPED_TEST(MinusTest, TexturePtr_Scalar)
{
MinusTest<TypeParam>::test_texptr_scalar();
}
TYPED_TEST(MinusTest, Expr_GpuMat)
{
MinusTest<TypeParam>::test_expr_gpumat();
}
TYPED_TEST(MinusTest, Scalar_Expr)
{
MinusTest<TypeParam>::test_scalar_expr();
}
////////////////////////////////////////////////////////////////////////////////
// AbsDiffTest
template <typename T>
class AbsDiffTest : public ::testing::Test
{
public:
void test_accuracy()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst1 = absdiff_(d_src1, d_src2);
GpuMat_<T> dst2 = abs_(d_src1 - d_src2);
EXPECT_MAT_NEAR(dst1, dst2, 0.0);
}
};
TYPED_TEST_CASE(AbsDiffTest, SignedTypes);
TYPED_TEST(AbsDiffTest, Accuracy)
{
AbsDiffTest<TypeParam>::test_accuracy();
}
+146
View File
@@ -0,0 +1,146 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
typedef ::testing::Types<uchar, ushort, short, int> IntTypes;
////////////////////////////////////////////////////////////////////////////////
// BitNotTest
template <typename T>
class BitNotTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst = ~d_src;
Mat dst_gold;
cv::bitwise_not(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(BitNotTest, IntTypes);
TYPED_TEST(BitNotTest, GpuMat)
{
BitNotTest<TypeParam>::test_gpumat();
}
////////////////////////////////////////////////////////////////////////////////
// BitAndTest
template <typename T>
class BitAndTest : public ::testing::Test
{
public:
void test_gpumat_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = d_src1 & d_src2;
Mat dst_gold;
cv::bitwise_and(src1, src2, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(BitAndTest, IntTypes);
TYPED_TEST(BitAndTest, GpuMat_GpuMat)
{
BitAndTest<TypeParam>::test_gpumat_gpumat();
}
////////////////////////////////////////////////////////////////////////////////
// LShiftTest
template <typename T>
class LShiftTest : public ::testing::Test
{
public:
void test_accuracy()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst1 = d_src << 2;
GpuMat_<T> dst2 = d_src * 4;
EXPECT_MAT_NEAR(dst1, dst2, 0.0);
}
};
TYPED_TEST_CASE(LShiftTest, int);
TYPED_TEST(LShiftTest, Accuracy)
{
LShiftTest<TypeParam>::test_accuracy();
}
+151
View File
@@ -0,0 +1,151 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
typedef ::testing::Types<uchar, ushort, short, int, float> AllTypes;
////////////////////////////////////////////////////////////////////////////////
// LessTest
template <typename T>
class LessTest : public ::testing::Test
{
public:
void test_gpumat_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<uchar> dst = (d_src1 < d_src2) * 255;
Mat dst_gold;
cv::compare(src1, src2, dst_gold, CMP_LT);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(LessTest, AllTypes);
TYPED_TEST(LessTest, GpuMat_GpuMat)
{
LessTest<TypeParam>::test_gpumat_gpumat();
}
////////////////////////////////////////////////////////////////////////////////
// MinTest
template <typename T>
class MinTest : public ::testing::Test
{
public:
void test_gpumat_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src1 = randomMat(size, type);
Mat src2 = randomMat(size, type);
GpuMat_<T> d_src1(src1), d_src2(src2);
GpuMat_<T> dst = min_(d_src1, d_src2);
Mat dst_gold;
cv::min(src1, src2, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(MinTest, AllTypes);
TYPED_TEST(MinTest, GpuMat_GpuMat)
{
MinTest<TypeParam>::test_gpumat_gpumat();
}
////////////////////////////////////////////////////////////////////////////////
// ThreshBinaryTest
typedef ::testing::Types<uchar, short, float> ThreshTypes;
template <typename T>
class ThreshBinaryTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst = threshBinary_(d_src, 128, 0);
Mat dst_gold;
cv::threshold(src, dst_gold, 128, 0, THRESH_BINARY);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(ThreshBinaryTest, ThreshTypes);
TYPED_TEST(ThreshBinaryTest, GpuMat)
{
ThreshBinaryTest<TypeParam>::test_gpumat();
}
+180
View File
@@ -0,0 +1,180 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
namespace cv {
enum {
COLOR_BGR2BGR = COLOR_BGR2RGB,
COLOR_BGR2LRGB = COLOR_BGR2RGB,
COLOR_BGR2LBGR = COLOR_BGR2RGB
};
}
#define CVT_COLOR_TEST(src_space, dst_space, src_cn, dst_cn) \
TEST(CvtColor, src_space ## _to_ ## dst_space) \
{ \
const Size size = randomSize(100, 400); \
Mat bgrb = randomMat(size, CV_8UC3); \
Mat srcb; \
cv::cvtColor(bgrb, srcb, COLOR_BGR ## 2 ## src_space, src_cn); \
GpuMat_<SelectIf<src_cn == 1, uchar, uchar ## src_cn>::type> d_srcb(srcb); \
GpuMat_<SelectIf<dst_cn == 1, uchar, uchar ## dst_cn>::type> dstb = src_space ## _to_ ## dst_space ## _(d_srcb); \
Mat dstb_gold; \
cv::cvtColor(srcb, dstb_gold, COLOR_ ## src_space ## 2 ## dst_space); \
EXPECT_MAT_NEAR(dstb_gold, dstb, 2.0); \
Mat bgrf = randomMat(size, CV_32FC3, 0, 1); \
Mat srcf; \
cv::cvtColor(bgrf, srcf, COLOR_BGR ## 2 ## src_space, src_cn); \
GpuMat_<SelectIf<src_cn == 1, float, float ## src_cn>::type> d_srcf(srcf); \
GpuMat_<SelectIf<dst_cn == 1, float, float ## dst_cn>::type> dstf = src_space ## _to_ ## dst_space ## _(d_srcf); \
Mat dstf_gold; \
cv::cvtColor(srcf, dstf_gold, COLOR_ ## src_space ## 2 ## dst_space); \
EXPECT_MAT_NEAR(dstf_gold, dstf, 2.0); \
}
// RGB <-> BGR
CVT_COLOR_TEST(BGR, RGB, 3, 3)
CVT_COLOR_TEST(BGR, BGRA, 3, 4)
CVT_COLOR_TEST(BGR, RGBA, 3, 4)
CVT_COLOR_TEST(BGRA, BGR, 4, 3)
CVT_COLOR_TEST(BGRA, RGB, 4, 3)
CVT_COLOR_TEST(BGRA, RGBA, 4, 4)
// RGB <-> Gray
CVT_COLOR_TEST(BGR, GRAY, 3, 1)
CVT_COLOR_TEST(RGB, GRAY, 3, 1)
CVT_COLOR_TEST(BGRA, GRAY, 4, 1)
CVT_COLOR_TEST(RGBA, GRAY, 4, 1)
CVT_COLOR_TEST(GRAY, BGR, 1, 3)
CVT_COLOR_TEST(GRAY, BGRA, 1, 4)
// RGB <-> YUV
CVT_COLOR_TEST(RGB, YUV, 3, 3)
CVT_COLOR_TEST(BGR, YUV, 3, 3)
CVT_COLOR_TEST(YUV, RGB, 3, 3)
CVT_COLOR_TEST(YUV, BGR, 3, 3)
// RGB <-> YCrCb
CVT_COLOR_TEST(RGB, YCrCb, 3, 3)
CVT_COLOR_TEST(BGR, YCrCb, 3, 3)
CVT_COLOR_TEST(YCrCb, RGB, 3, 3)
CVT_COLOR_TEST(YCrCb, BGR, 3, 3)
// RGB <-> XYZ
CVT_COLOR_TEST(RGB, XYZ, 3, 3)
CVT_COLOR_TEST(BGR, XYZ, 3, 3)
CVT_COLOR_TEST(XYZ, RGB, 3, 3)
CVT_COLOR_TEST(XYZ, BGR, 3, 3)
// RGB <-> HSV
CVT_COLOR_TEST(RGB, HSV, 3, 3)
CVT_COLOR_TEST(BGR, HSV, 3, 3)
CVT_COLOR_TEST(HSV, RGB, 3, 3)
CVT_COLOR_TEST(HSV, BGR, 3, 3)
CVT_COLOR_TEST(RGB, HSV_FULL, 3, 3)
CVT_COLOR_TEST(BGR, HSV_FULL, 3, 3)
CVT_COLOR_TEST(HSV, RGB_FULL, 3, 3)
CVT_COLOR_TEST(HSV, BGR_FULL, 3, 3)
// RGB <-> HLS
CVT_COLOR_TEST(RGB, HLS, 3, 3)
CVT_COLOR_TEST(BGR, HLS, 3, 3)
CVT_COLOR_TEST(HLS, RGB, 3, 3)
CVT_COLOR_TEST(HLS, BGR, 3, 3)
CVT_COLOR_TEST(RGB, HLS_FULL, 3, 3)
CVT_COLOR_TEST(BGR, HLS_FULL, 3, 3)
CVT_COLOR_TEST(HLS, RGB_FULL, 3, 3)
CVT_COLOR_TEST(HLS, BGR_FULL, 3, 3)
// RGB <-> Lab
CVT_COLOR_TEST(RGB, Lab, 3, 3)
CVT_COLOR_TEST(BGR, Lab, 3, 3)
CVT_COLOR_TEST(Lab, RGB, 3, 3)
CVT_COLOR_TEST(Lab, BGR, 3, 3)
CVT_COLOR_TEST(LRGB, Lab, 3, 3)
CVT_COLOR_TEST(LBGR, Lab, 3, 3)
CVT_COLOR_TEST(Lab, LRGB, 3, 3)
CVT_COLOR_TEST(Lab, LBGR, 3, 3)
// RGB <-> Luv
CVT_COLOR_TEST(RGB, Luv, 3, 3)
CVT_COLOR_TEST(BGR, Luv, 3, 3)
CVT_COLOR_TEST(Luv, RGB, 3, 3)
CVT_COLOR_TEST(Luv, BGR, 3, 3)
CVT_COLOR_TEST(LRGB, Luv, 3, 3)
CVT_COLOR_TEST(LBGR, Luv, 3, 3)
CVT_COLOR_TEST(Luv, LRGB, 3, 3)
CVT_COLOR_TEST(Luv, LBGR, 3, 3)
+151
View File
@@ -0,0 +1,151 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
typedef ::testing::Types<uchar, ushort, short, int, float> AllTypes;
typedef ::testing::Types<short, float> Fp16Types;
////////////////////////////////////////////////////////////////////////////////
// CvtTest
template <typename T>
class CvtTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
GpuMat_<T> d_src(src);
GpuMat_<T> dst = cvt_<T>(cvt_<float>(d_src) * 2.0f - 10.0f);
Mat dst_gold;
src.convertTo(dst_gold, src.depth(), 2, -10);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
// dummy class
template <typename T>
class CvFp16Test : public ::testing::Test
{
public:
void test_gpumat()
{
}
};
template <>
class CvFp16Test <short> : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<float>::type;
Mat src = randomMat(size, type), dst, ref;
GpuMat_<float> g_src(src);
GpuMat g_dst;
// Fp32 -> Fp16
g_src.convertTo(g_dst, CV_16F);
src.convertTo(dst, CV_16F);
// Fp16 -> Fp32
GpuMat g_tmp = g_dst.clone();
g_tmp.convertTo(g_dst, CV_32F);
dst.convertTo(ref, CV_32F);
g_dst.download(dst);
EXPECT_MAT_NEAR(dst, ref, 0.0);
}
};
template <>
class CvFp16Test <float> : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<float>::type;
Mat src = randomMat(size, type), dst, ref;
GpuMat_<float> g_src(src);
GpuMat g_dst;
// Fp32 -> Fp16
g_src.convertTo(g_dst, CV_16F);
src.convertTo(ref, CV_16F);
g_dst.download(dst);
EXPECT_MAT_NEAR(dst, ref, 0.0);
}
};
TYPED_TEST_CASE(CvtTest, AllTypes);
TYPED_TEST(CvtTest, GpuMat)
{
CvtTest<TypeParam>::test_gpumat();
}
TYPED_TEST_CASE(CvFp16Test, Fp16Types);
TYPED_TEST(CvFp16Test, GpuMat)
{
CvFp16Test<TypeParam>::test_gpumat();
}
+109
View File
@@ -0,0 +1,109 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
TEST(Sobel, Accuracy)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
Texture<uchar> tex_src(d_src);
GpuMat_<short> dx = sobelX_(cvt_<int>(tex_src));
GpuMat_<short> dy = sobelY_(cvt_<int>(tex_src));
Mat dx_gold, dy_gold;
cv::Sobel(src, dx_gold, CV_16S, 1, 0, 3, 1, 0, BORDER_REPLICATE);
cv::Sobel(src, dy_gold, CV_16S, 0, 1, 3, 1, 0, BORDER_REPLICATE);
EXPECT_MAT_NEAR(dx_gold, dx, 0.0);
EXPECT_MAT_NEAR(dy_gold, dy, 0.0);
}
TEST(Scharr, Accuracy)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
Texture<uchar> tex_src(d_src);
GpuMat_<short> dx = scharrX_(cvt_<int>(tex_src));
GpuMat_<short> dy = scharrY_(cvt_<int>(tex_src));
Mat dx_gold, dy_gold;
cv::Scharr(src, dx_gold, CV_16S, 1, 0, 1, 0, BORDER_REPLICATE);
cv::Scharr(src, dy_gold, CV_16S, 0, 1, 1, 0, BORDER_REPLICATE);
EXPECT_MAT_NEAR(dx_gold, dx, 0.0);
EXPECT_MAT_NEAR(dy_gold, dy, 0.0);
}
TEST(Laplacian, Accuracy)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
Texture<uchar> tex_src(d_src);
GpuMat_<short> dst1 = laplacian_<1>(cvt_<int>(tex_src));
GpuMat_<short> dst3 = laplacian_<3>(cvt_<int>(tex_src));
Mat dst1_gold, dst3_gold;
cv::Laplacian(src, dst1_gold, CV_16S, 1, 1, 0, BORDER_REPLICATE);
cv::Laplacian(src, dst3_gold, CV_16S, 3, 1, 0, BORDER_REPLICATE);
EXPECT_MAT_NEAR(dst1_gold, dst1, 0.0);
EXPECT_MAT_NEAR(dst3_gold, dst3, 0.0);
}
+103
View File
@@ -0,0 +1,103 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
TEST(DISABLED_Integral, _8u)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uint> dst = integral_(d_src);
Mat dst_gold;
cv::integral(src, dst_gold);
dst_gold = dst_gold(Rect(1, 1, size.width, size.height));
ASSERT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(Integral, _32f)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
GpuMat_<float> d_src(src);
GpuMat_<float> dst = integral_(d_src);
Mat dst_gold;
cv::integral(src, dst_gold, CV_32F);
dst_gold = dst_gold(Rect(1, 1, size.width, size.height));
ASSERT_PRED_FORMAT2(cvtest::MatComparator(1e-5, 0), dst_gold, Mat(dst));
}
TEST(DISABLED_Integral, _8u_opt)
{
const Size size(640, 480);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uint> dst = integral_(d_src);
Mat dst_gold;
cv::integral(src, dst_gold);
dst_gold = dst_gold(Rect(1, 1, size.width, size.height));
ASSERT_MAT_NEAR(dst_gold, dst, 0.0);
}
+82
View File
@@ -0,0 +1,82 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
////////////////////////////////////////////////////////////////////////////////
// LutTest
template <typename T>
class LutTest : public ::testing::Test
{
public:
void test_gpumat()
{
const Size size = randomSize(100, 400);
const int type = DataType<T>::type;
Mat src = randomMat(size, type);
Mat tbl = randomMat(Size(256, 1), type);
GpuMat_<T> d_src(src), d_tbl(tbl);
GpuMat_<T> dst = lut_(d_src, d_tbl);
Mat dst_gold;
cv::LUT(src, tbl, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(LutTest, uchar);
TYPED_TEST(LutTest, GpuMat)
{
LutTest<TypeParam>::test_gpumat();
}
+46
View File
@@ -0,0 +1,46 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/ts.hpp"
CV_TEST_MAIN("cv")
+244
View File
@@ -0,0 +1,244 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
namespace opencv_test { namespace {
template <typename ElemType>
class GpuMatNDTest : public ::testing::Test
{
public:
using MatType = Mat_<ElemType>;
using CnType = typename Mat_<ElemType>::channel_type;
static constexpr int cn = DataType<ElemType>::channels;
using SizeArray = GpuMatND::SizeArray;
static MatType RandomMat(const SizeArray& size)
{
const auto dims = static_cast<int>(size.size());
MatType ret(dims, size.data());
for (ElemType& elem : ret)
for (int i = 0; i < cn; ++i)
elem[i] = cv::randu<CnType>();
return ret;
}
static std::vector<Range> RandomRange(const SizeArray& size)
{
const auto dims = static_cast<int>(size.size());
std::vector<Range> ret;
const auto margin = cv::randu<int>() & 0x1 + 1; // 1 or 2
for (int s : size)
if (s > margin * 2)
ret.emplace_back(margin, s-margin);
else
ret.push_back(Range::all());
return ret;
}
static std::vector<Range> RandomRange2D(const SizeArray& size)
{
const auto dims = static_cast<int>(size.size());
std::vector<Range> ret = RandomRange(size);
for (int i = 0; i < dims - 2; ++i)
{
const auto start = cv::randu<unsigned int>() % size[i];
ret[i] = Range(static_cast<int>(start), static_cast<int>(start) + 1);
}
return ret;
}
static void doTest1(const SizeArray& size)
{
const MatType gold = RandomMat(size);
MatType dst;
GpuMatND gmat;
// simple upload, download test for GpuMatND
gmat.upload(gold);
gmat.download(dst);
EXPECT_TRUE(std::equal(gold.begin(), gold.end(), dst.begin()));
}
static void doTest2(const SizeArray& size)
{
const MatType gold = RandomMat(size);
const std::vector<Range> ranges = RandomRange(size);
const MatType goldSub = gold(ranges);
MatType dst;
GpuMatND gmat;
// upload partial mat, download it, and compare
gmat.upload(goldSub);
gmat.download(dst);
EXPECT_TRUE(std::equal(goldSub.begin(), goldSub.end(), dst.begin()));
// upload full mat, extract partial mat from it, download it, and compare
gmat.upload(gold);
gmat = gmat(ranges);
gmat.download(dst);
EXPECT_TRUE(std::equal(goldSub.begin(), goldSub.end(), dst.begin()));
}
static void doTest3(const SizeArray& size)
{
if (std::is_same<CnType, hfloat>::value) // GpuMat::convertTo is not implemented for CV_16F
return;
const MatType gold = RandomMat(size);
const std::vector<Range> ranges = RandomRange2D(size);
MatType dst;
GpuMatND gmat;
// Test GpuMatND to GpuMat conversion:
// extract a 2D-plane and set its elements in the extracted region to 1
// compare the values of the full mat between Mat and GpuMatND
gmat.upload(gold);
GpuMat plane = gmat(ranges).createGpuMatHeader();
EXPECT_TRUE(!plane.refcount); // plane points to externally allocated memory(a part of gmat)
const GpuMat dummy = plane.clone();
EXPECT_TRUE(dummy.refcount); // dummy is clone()-ed from plane, so it manages its memory
// currently, plane(GpuMat) points to a sub-matrix of gmat(GpuMatND)
// in this case, dummy and plane have same size and type,
// so plane does not get reallocated inside convertTo,
// so this convertTo sets a sub-matrix region of gmat to 1
dummy.convertTo(plane, -1, 0, 1);
EXPECT_TRUE(!plane.refcount); // plane still points to externally allocated memory(a part of gmat)
gmat.download(dst);
// set a sub-matrix region of gold to 1
Mat plane_ = gold(ranges);
const Mat dummy_ = plane_.clone();
dummy_.convertTo(plane_, -1, 0, 1);
EXPECT_TRUE(std::equal(gold.begin(), gold.end(), dst.begin()));
}
static void doTest4(const SizeArray& size)
{
if (std::is_same<CnType, hfloat>::value) // GpuMat::convertTo is not implemented for CV_16F
return;
const MatType gold = RandomMat(size);
const std::vector<Range> ranges = RandomRange2D(size);
MatType dst;
GpuMatND gmat;
// Test handling external memory
gmat.upload(gold);
const GpuMatND external(gmat.size, gmat.type(), gmat.getDevicePtr(), {gmat.step.begin(), gmat.step.end() - 1});
// set a sub-matrix region of external to 2
GpuMat plane = external(ranges).createGpuMatHeader();
const GpuMat dummy = plane.clone();
dummy.convertTo(plane, -1, 0, 2);
external.download(dst);
// set a sub-matrix region of gold to 2
Mat plane_ = gold(ranges);
const Mat dummy_ = plane_.clone();
dummy_.convertTo(plane_, -1, 0, 2);
EXPECT_TRUE(std::equal(gold.begin(), gold.end(), dst.begin()));
}
static void doTest5(const SizeArray& size)
{
if (std::is_same<CnType, hfloat>::value) // GpuMat::convertTo is not implemented for CV_16F
return;
const MatType gold = RandomMat(size);
const std::vector<Range> ranges = RandomRange(size);
MatType goldSub = gold(ranges);
MatType dst;
GpuMatND gmat;
// Upload a sub-mat, set a sub-region of the sub-mat to 3, download, and compare
gmat.upload(goldSub);
const std::vector<Range> rangesInRanges = RandomRange2D(gmat.size);
GpuMat plane = gmat(rangesInRanges).createGpuMatHeader();
const GpuMat dummy = plane.clone();
dummy.convertTo(plane, -1, 0, 3);
gmat.download(dst);
Mat plane_ = goldSub(rangesInRanges);
const Mat dummy_ = plane_.clone();
dummy_.convertTo(plane_, -1, 0, 3);
EXPECT_TRUE(std::equal(goldSub.begin(), goldSub.end(), dst.begin()));
}
};
using ElemTypes = ::testing::Types<
Vec<uchar, 1>, Vec<uchar, 2>, Vec<uchar, 3>, Vec<uchar, 4>, // CV_8U
Vec<schar, 1>, Vec<schar, 2>, Vec<schar, 3>, Vec<schar, 4>, // CV_8S
Vec<ushort, 1>, Vec<ushort, 2>, Vec<ushort, 3>, Vec<ushort, 4>, // CV_16U
Vec<short, 1>, Vec<short, 2>, Vec<short, 3>, Vec<short, 4>, // CV_16S
Vec<int, 1>, Vec<int, 2>, Vec<int, 3>, Vec<int, 4>, // CV_32S
Vec<float, 1>, Vec<float, 2>, Vec<float, 3>, Vec<float, 4>, // CV_32F
Vec<double, 1>, Vec<double, 2>, Vec<double, 3>, Vec<double, 4>, //CV_64F
Vec<hfloat, 1>, Vec<hfloat, 2>, Vec<hfloat, 3>, Vec<hfloat, 4> // CV_16F
>;
using SizeArray = GpuMatND::SizeArray;
#define DIFFERENT_SIZES_ND std::vector<SizeArray>{ \
SizeArray{2, 1}, SizeArray{3, 2, 1}, SizeArray{1, 3, 2, 1}, SizeArray{2, 1, 3, 2, 1}, SizeArray{3, 2, 1, 3, 2, 1}, \
SizeArray{1}, SizeArray{1, 1}, SizeArray{1, 1, 1}, SizeArray{1, 1, 1, 1}, \
SizeArray{4}, SizeArray{4, 4}, SizeArray{4, 4, 4}, SizeArray{4, 4, 4, 4}, \
SizeArray{11}, SizeArray{13, 11}, SizeArray{17, 13, 11}, SizeArray{19, 17, 13, 11}}
TYPED_TEST_CASE(GpuMatNDTest, ElemTypes);
TYPED_TEST(GpuMatNDTest, Test1)
{
for (auto& size : DIFFERENT_SIZES_ND)
GpuMatNDTest<TypeParam>::doTest1(size);
}
TYPED_TEST(GpuMatNDTest, Test2)
{
for (auto& size : DIFFERENT_SIZES_ND)
GpuMatNDTest<TypeParam>::doTest2(size);
}
TYPED_TEST(GpuMatNDTest, Test3)
{
for (auto& size : DIFFERENT_SIZES_ND)
GpuMatNDTest<TypeParam>::doTest3(size);
}
TYPED_TEST(GpuMatNDTest, Test4)
{
for (auto& size : DIFFERENT_SIZES_ND)
GpuMatNDTest<TypeParam>::doTest4(size);
}
TYPED_TEST(GpuMatNDTest, Test5)
{
for (auto& size : DIFFERENT_SIZES_ND)
GpuMatNDTest<TypeParam>::doTest5(size);
}
}} // namespace
+55
View File
@@ -0,0 +1,55 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include "opencv2/cudev.hpp"
#define CV_TEST_SKIP_NAMESPACE_CHECK
#include "opencv2/ts.hpp"
#include "opencv2/ts/cuda_test.hpp"
#include "cvconfig.h"
#endif
+81
View File
@@ -0,0 +1,81 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
TEST(PyrDown, _8uc1)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = pyrDown_(d_src);
Mat dst_gold;
cv::pyrDown(src, dst_gold);
ASSERT_MAT_NEAR(dst_gold, dst, 1.0);
}
TEST(PyrUp, _32fc4)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC4);
GpuMat_<float4> d_src(src);
GpuMat_<float4> dst = pyrDown_(d_src);
Mat dst_gold;
cv::pyrDown(src, dst_gold);
ASSERT_MAT_NEAR(dst_gold, dst, 1e-4);
}
+312
View File
@@ -0,0 +1,312 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
TEST(Sum, GpuMat)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<float> dst = sum_(d_src);
float res;
dst.download(_OutputArray(&res, 1));
Scalar dst_gold = cv::sum(src);
ASSERT_FLOAT_EQ(static_cast<float>(dst_gold[0]), res);
}
TEST(Sum, Expr)
{
const Size size = randomSize(100, 400);
Mat src1 = randomMat(size, CV_32FC1, 0, 1);
Mat src2 = randomMat(size, CV_32FC1, 0, 1);
GpuMat_<float> d_src1(src1), d_src2(src2);
GpuMat_<float> dst = sum_(abs_(d_src1 - d_src2));
float res;
dst.download(_OutputArray(&res, 1));
Scalar dst_gold = cv::norm(src1, src2, NORM_L1);
ASSERT_FLOAT_EQ(static_cast<float>(dst_gold[0]), res);
}
TEST(MinVal, GpuMat)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<float> dst = minVal_(d_src);
float res;
dst.download(_OutputArray(&res, 1));
double res_gold;
cv::minMaxLoc(src, &res_gold, 0);
ASSERT_FLOAT_EQ(static_cast<float>(res_gold), res);
}
TEST(MaxVal, Expr)
{
const Size size = randomSize(100, 400);
Mat src1 = randomMat(size, CV_32SC1);
Mat src2 = randomMat(size, CV_32SC1);
GpuMat_<int> d_src1(src1), d_src2(src2);
GpuMat_<float> dst = maxVal_(abs_(d_src1 - d_src2));
float res;
dst.download(_OutputArray(&res, 1));
double res_gold = cv::norm(src1, src2, NORM_INF);
ASSERT_FLOAT_EQ(static_cast<float>(res_gold), res);
}
TEST(MinMaxVal, GpuMat)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<float> dst = minMaxVal_(d_src);
float res[2];
dst.download(Mat(1, 2, CV_32FC1, res));
double res_gold[2];
cv::minMaxLoc(src, &res_gold[0], &res_gold[1]);
ASSERT_FLOAT_EQ(static_cast<float>(res_gold[0]), res[0]);
ASSERT_FLOAT_EQ(static_cast<float>(res_gold[1]), res[1]);
}
TEST(NonZeroCount, Accuracy)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1, 0, 5);
GpuMat_<uchar> d_src(src);
GpuMat_<int> dst1 = countNonZero_(d_src);
GpuMat_<int> dst2 = sum_(cvt_<int>(d_src) != 0);
EXPECT_MAT_NEAR(dst1, dst2, 0.0);
}
TEST(ReduceToRow, Sum)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<int> dst = reduceToRow_<Sum<int> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 0, REDUCE_SUM, CV_32S);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(ReduceToRow, Avg)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<float> dst = reduceToRow_<Avg<float> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 0, REDUCE_AVG, CV_32F);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
}
TEST(ReduceToRow, Min)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = reduceToRow_<Min<uchar> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 0, REDUCE_MIN);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(ReduceToRow, Max)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = reduceToRow_<Max<uchar> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 0, REDUCE_MAX);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(ReduceToColumn, Sum)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<int> dst = reduceToColumn_<Sum<int> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 1, REDUCE_SUM, CV_32S);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(ReduceToColumn, Avg)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<float> dst = reduceToColumn_<Avg<float> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 1, REDUCE_AVG, CV_32F);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
}
TEST(ReduceToColumn, Min)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = reduceToColumn_<Min<uchar> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 1, REDUCE_MIN);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(ReduceToColumn, Max)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = reduceToColumn_<Max<uchar> >(d_src);
Mat dst_gold;
cv::reduce(src, dst_gold, 1, REDUCE_MAX);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
static void calcHistGold(const cv::Mat& src, cv::Mat& hist)
{
hist.create(1, 256, CV_32SC1);
hist.setTo(cv::Scalar::all(0));
int* hist_row = hist.ptr<int>();
for (int y = 0; y < src.rows; ++y)
{
const uchar* src_row = src.ptr(y);
for (int x = 0; x < src.cols; ++x)
++hist_row[src_row[x]];
}
}
TEST(Histogram, GpuMat)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<int> dst = histogram_<256>(d_src);
Mat dst_gold;
calcHistGold(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
+140
View File
@@ -0,0 +1,140 @@
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cudev;
using namespace cvtest;
// BlockScanInt
template <int THREADS_NUM>
__global__ void int_kernel(int* data)
{
uint tid = Block::threadLineId();
#if CV_CUDEV_ARCH >= 300
const int n_warps = (THREADS_NUM - 1) / WARP_SIZE + 1;
__shared__ int smem[n_warps];
#else
__shared__ int smem[THREADS_NUM];
#endif
data[tid] = blockScanInclusive<THREADS_NUM>(data[tid], smem, tid);
}
#define BLOCK_SCAN_INT_TEST(block_size) \
TEST(BlockScanInt, BlockSize##block_size) \
{ \
Mat src = randomMat(Size(block_size, 1), CV_32SC1, 0, 1024); \
\
GpuMat d_src; \
d_src.upload(src); \
\
for (int col = 1; col < block_size; col++) \
src.at<int>(0, col) += src.at<int>(0, col - 1); \
\
int_kernel<block_size><<<1, block_size>>>((int*)d_src.data); \
\
CV_CUDEV_SAFE_CALL(cudaDeviceSynchronize()); \
\
EXPECT_MAT_NEAR(d_src, src, 0); \
}
BLOCK_SCAN_INT_TEST(29)
BLOCK_SCAN_INT_TEST(30)
BLOCK_SCAN_INT_TEST(32)
BLOCK_SCAN_INT_TEST(40)
BLOCK_SCAN_INT_TEST(41)
BLOCK_SCAN_INT_TEST(59)
BLOCK_SCAN_INT_TEST(60)
BLOCK_SCAN_INT_TEST(64)
BLOCK_SCAN_INT_TEST(70)
BLOCK_SCAN_INT_TEST(71)
BLOCK_SCAN_INT_TEST(109)
BLOCK_SCAN_INT_TEST(110)
BLOCK_SCAN_INT_TEST(128)
BLOCK_SCAN_INT_TEST(130)
BLOCK_SCAN_INT_TEST(131)
BLOCK_SCAN_INT_TEST(189)
BLOCK_SCAN_INT_TEST(200)
BLOCK_SCAN_INT_TEST(256)
BLOCK_SCAN_INT_TEST(300)
BLOCK_SCAN_INT_TEST(311)
BLOCK_SCAN_INT_TEST(489)
BLOCK_SCAN_INT_TEST(500)
BLOCK_SCAN_INT_TEST(512)
BLOCK_SCAN_INT_TEST(600)
BLOCK_SCAN_INT_TEST(611)
BLOCK_SCAN_INT_TEST(1024)
// BlockScanDouble
template <int THREADS_NUM>
__global__ void double_kernel(double* data)
{
uint tid = Block::threadLineId();
#if CV_CUDEV_ARCH >= 300
const int n_warps = (THREADS_NUM - 1) / WARP_SIZE + 1;
__shared__ double smem[n_warps];
#else
__shared__ double smem[THREADS_NUM];
#endif
data[tid] = blockScanInclusive<THREADS_NUM>(data[tid], smem, tid);
}
#define BLOCK_SCAN_DOUBLE_TEST(block_size) \
TEST(BlockScanDouble, BlockSize##block_size) \
{ \
Mat src = randomMat(Size(block_size, 1), CV_64FC1, 0.0, 1.0); \
\
GpuMat d_src; \
d_src.upload(src); \
\
for (int col = 1; col < block_size; col++) \
src.at<double>(0, col) += src.at<double>(0, col - 1); \
\
double_kernel<block_size><<<1, block_size>>>((double*)d_src.data); \
\
CV_CUDEV_SAFE_CALL(cudaDeviceSynchronize()); \
\
EXPECT_MAT_NEAR(d_src, src, 1e-10); \
}
BLOCK_SCAN_DOUBLE_TEST(29)
BLOCK_SCAN_DOUBLE_TEST(30)
BLOCK_SCAN_DOUBLE_TEST(32)
BLOCK_SCAN_DOUBLE_TEST(40)
BLOCK_SCAN_DOUBLE_TEST(41)
BLOCK_SCAN_DOUBLE_TEST(59)
BLOCK_SCAN_DOUBLE_TEST(60)
BLOCK_SCAN_DOUBLE_TEST(64)
BLOCK_SCAN_DOUBLE_TEST(70)
BLOCK_SCAN_DOUBLE_TEST(71)
BLOCK_SCAN_DOUBLE_TEST(109)
BLOCK_SCAN_DOUBLE_TEST(110)
BLOCK_SCAN_DOUBLE_TEST(128)
BLOCK_SCAN_DOUBLE_TEST(130)
BLOCK_SCAN_DOUBLE_TEST(131)
BLOCK_SCAN_DOUBLE_TEST(189)
BLOCK_SCAN_DOUBLE_TEST(200)
BLOCK_SCAN_DOUBLE_TEST(256)
BLOCK_SCAN_DOUBLE_TEST(300)
BLOCK_SCAN_DOUBLE_TEST(311)
BLOCK_SCAN_DOUBLE_TEST(489)
BLOCK_SCAN_DOUBLE_TEST(500)
BLOCK_SCAN_DOUBLE_TEST(512)
BLOCK_SCAN_DOUBLE_TEST(600)
BLOCK_SCAN_DOUBLE_TEST(611)
BLOCK_SCAN_DOUBLE_TEST(1024)
+183
View File
@@ -0,0 +1,183 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
typedef ::testing::Types<uchar, ushort, short, int, float> AllTypes;
////////////////////////////////////////////////////////////////////////////////
// MergeTest
template <typename T>
class MergeTest : public ::testing::Test
{
public:
void test_c2()
{
const Size size = randomSize(100, 400);
const int src_type = DataType<T>::type;
Mat src1 = randomMat(size, src_type);
Mat src2 = randomMat(size, src_type);
GpuMat_<T> d_src1(src1);
GpuMat_<T> d_src2(src2);
GpuMat_<typename MakeVec<T, 2>::type> dst;
std::array<GlobPtrSz<T>, 2 > d_src = {globPtr(d_src1), globPtr(d_src2)};
gridMerge(d_src, dst);
Mat dst_gold;
Mat srcs[] = {src1, src2};
cv::merge(srcs, 2, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
void test_c3()
{
const Size size = randomSize(100, 400);
const int src_type = DataType<T>::type;
Mat src1 = randomMat(size, src_type);
Mat src2 = randomMat(size, src_type);
Mat src3 = randomMat(size, src_type);
GpuMat_<T> d_src1(src1);
GpuMat_<T> d_src2(src2);
GpuMat_<T> d_src3(src3);
std::array<GlobPtrSz<T>, 3 > d_src = {globPtr(d_src1), globPtr(d_src2), globPtr(d_src3)};
GpuMat_<typename MakeVec<T, 3>::type> dst;
gridMerge(d_src, dst);
Mat dst_gold;
Mat srcs[] = {src1, src2, src3};
cv::merge(srcs, 3, dst_gold);
ASSERT_MAT_NEAR(dst_gold, dst, 0.0);
}
};
TYPED_TEST_CASE(MergeTest, AllTypes);
TYPED_TEST(MergeTest, C2)
{
MergeTest<TypeParam>::test_c2();
}
TYPED_TEST(MergeTest, C3)
{
MergeTest<TypeParam>::test_c3();
}
////////////////////////////////////////////////////////////////////////////////
// SplitTest
template <typename T>
class SplitTest : public ::testing::Test
{
public:
void test_c3()
{
const Size size = randomSize(100, 400);
const int src_type = CV_MAKE_TYPE(DataType<T>::depth, 3);
Mat src = randomMat(size, src_type);
GpuMat_<typename MakeVec<T, 3>::type> d_src(src);
GpuMat_<T> dst1, dst2, dst3;
gridSplit(d_src, tie(dst1, dst2, dst3));
std::vector<Mat> dst;
cv::split(src, dst);
ASSERT_MAT_NEAR(dst[0], dst1, 0.0);
ASSERT_MAT_NEAR(dst[1], dst2, 0.0);
ASSERT_MAT_NEAR(dst[2], dst3, 0.0);
}
void test_c4()
{
const Size size = randomSize(100, 400);
const int src_type = CV_MAKE_TYPE(DataType<T>::depth, 4);
Mat src = randomMat(size, src_type);
GpuMat_<typename MakeVec<T, 4>::type> d_src(src);
GpuMat_<T> dst1, dst2, dst3, dst4;
gridSplit(d_src, tie(dst1, dst2, dst3, dst4));
std::vector<Mat> dst;
cv::split(src, dst);
ASSERT_MAT_NEAR(dst[0], dst1, 0.0);
ASSERT_MAT_NEAR(dst[1], dst2, 0.0);
ASSERT_MAT_NEAR(dst[2], dst3, 0.0);
ASSERT_MAT_NEAR(dst[3], dst4, 0.0);
}
};
TYPED_TEST_CASE(SplitTest, AllTypes);
TYPED_TEST(SplitTest, C3)
{
SplitTest<TypeParam>::test_c3();
}
TYPED_TEST(SplitTest, C4)
{
SplitTest<TypeParam>::test_c4();
}
+259
View File
@@ -0,0 +1,259 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
// remap
enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH };
static void generateMap(Mat& mapx, Mat& mapy, int remapMode)
{
for (int j = 0; j < mapx.rows; ++j)
{
for (int i = 0; i < mapx.cols; ++i)
{
switch (remapMode)
{
case HALF_SIZE:
if (i > mapx.cols*0.25 && i < mapx.cols*0.75 && j > mapx.rows*0.25 && j < mapx.rows*0.75)
{
mapx.at<float>(j,i) = 2.f * (i - mapx.cols * 0.25f) + 0.5f;
mapy.at<float>(j,i) = 2.f * (j - mapx.rows * 0.25f) + 0.5f;
}
else
{
mapx.at<float>(j,i) = 0.f;
mapy.at<float>(j,i) = 0.f;
}
break;
case UPSIDE_DOWN:
mapx.at<float>(j,i) = static_cast<float>(i);
mapy.at<float>(j,i) = static_cast<float>(mapx.rows - j);
break;
case REFLECTION_X:
mapx.at<float>(j,i) = static_cast<float>(mapx.cols - i);
mapy.at<float>(j,i) = static_cast<float>(j);
break;
case REFLECTION_BOTH:
mapx.at<float>(j,i) = static_cast<float>(mapx.cols - i);
mapy.at<float>(j,i) = static_cast<float>(mapx.rows - j);
break;
} // end of switch
}
}
}
static void test_remap(int remapMode)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
Mat mapx(size, CV_32FC1);
Mat mapy(size, CV_32FC1);
generateMap(mapx, mapy, remapMode);
GpuMat_<float> d_src(src);
GpuMat_<float> d_mapx(mapx);
GpuMat_<float> d_mapy(mapy);
GpuMat_<float> dst = remap_(interNearest(brdReplicate(d_src)), d_mapx, d_mapy);
Mat dst_gold;
cv::remap(src, dst_gold, mapx, mapy, INTER_NEAREST, BORDER_REPLICATE);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(Remap, HALF_SIZE)
{
test_remap(HALF_SIZE);
}
TEST(Remap, UPSIDE_DOWN)
{
test_remap(UPSIDE_DOWN);
}
TEST(Remap, REFLECTION_X)
{
test_remap(REFLECTION_X);
}
TEST(Remap, REFLECTION_BOTH)
{
test_remap(REFLECTION_BOTH);
}
// resize
TEST(Resize, Upscale)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
GpuMat_<float> d_src(src);
Texture<float> tex_src(d_src);
GpuMat_<float> dst1 = resize_(interCubic(tex_src), 2, 2);
Mat mapx(size.height * 2, size.width * 2, CV_32FC1);
Mat mapy(size.height * 2, size.width * 2, CV_32FC1);
for (int y = 0; y < mapx.rows; ++y)
{
for (int x = 0; x < mapx.cols; ++x)
{
mapx.at<float>(y, x) = static_cast<float>(x / 2);
mapy.at<float>(y, x) = static_cast<float>(y / 2);
}
}
GpuMat_<float> d_mapx(mapx);
GpuMat_<float> d_mapy(mapy);
GpuMat_<float> dst2 = remap_(interCubic(brdReplicate(d_src)), d_mapx, d_mapy);
EXPECT_MAT_NEAR(dst1, dst2, 0.0);
}
TEST(Resize, Downscale)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
const float fx = 1.0f / 3.0f;
const float fy = 1.0f / 3.0f;
GpuMat_<float> d_src(src);
Texture<float> tex_src(d_src);
GpuMat_<float> dst1 = resize_(interArea(tex_src, Size(3, 3)), fx, fy);
Mat mapx(cv::saturate_cast<int>(size.height * fy), cv::saturate_cast<int>(size.width * fx), CV_32FC1);
Mat mapy(cv::saturate_cast<int>(size.height * fy), cv::saturate_cast<int>(size.width * fx), CV_32FC1);
for (int y = 0; y < mapx.rows; ++y)
{
for (int x = 0; x < mapx.cols; ++x)
{
mapx.at<float>(y, x) = x / fx;
mapy.at<float>(y, x) = y / fy;
}
}
GpuMat_<float> d_mapx(mapx);
GpuMat_<float> d_mapy(mapy);
GpuMat_<float> dst2 = remap_(interArea(brdReplicate(d_src), Size(3, 3)), d_mapx, d_mapy);
EXPECT_MAT_NEAR(dst1, dst2, 0.0);
}
// warpAffine & warpPerspective
Mat createAffineTransformMatrix(Size srcSize, float angle, bool perspective)
{
cv::Mat M(perspective ? 3 : 2, 3, CV_32FC1);
{
M.at<float>(0, 0) = std::cos(angle); M.at<float>(0, 1) = -std::sin(angle); M.at<float>(0, 2) = static_cast<float>(srcSize.width / 2);
M.at<float>(1, 0) = std::sin(angle); M.at<float>(1, 1) = std::cos(angle); M.at<float>(1, 2) = 0.0f;
}
if (perspective)
{
M.at<float>(2, 0) = 0.0f ; M.at<float>(2, 1) = 0.0f ; M.at<float>(2, 2) = 1.0f;
}
return M;
}
TEST(WarpAffine, Rotation)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
Mat M = createAffineTransformMatrix(size, static_cast<float>(CV_PI / 4), false);
GpuMat_<float> d_src(src);
GpuMat_<float> d_M;
createContinuous(M.size(), M.type(), d_M);
d_M.upload(M);
GpuMat_<float> dst = warpAffine_(interNearest(brdConstant(d_src)), size, d_M);
Mat dst_gold;
cv::warpAffine(src, dst_gold, M, size, INTER_NEAREST | WARP_INVERSE_MAP);
EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-3);
}
TEST(WarpPerspective, Rotation)
{
if (cvtest::skipUnstableTests)
throw SkipTestException("Skip unstable test: https://github.com/opencv/opencv/issues/27813");
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC1, 0, 1);
Mat M = createAffineTransformMatrix(size, static_cast<float>(CV_PI / 4), true);
GpuMat_<float> d_src(src);
GpuMat_<float> d_M;
createContinuous(M.size(), M.type(), d_M);
d_M.upload(M);
GpuMat_<float> dst = warpPerspective_(interNearest(brdConstant(d_src)), size, d_M);
Mat dst_gold;
cv::warpPerspective(src, dst_gold, M, size, INTER_NEAREST | WARP_INVERSE_MAP);
EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-3);
}
+81
View File
@@ -0,0 +1,81 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cuda;
using namespace cv::cudev;
using namespace cvtest;
TEST(Transpose, _8uc1)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_8UC1);
GpuMat_<uchar> d_src(src);
GpuMat_<uchar> dst = transpose_(d_src);
Mat dst_gold;
cv::transpose(src, dst_gold);
ASSERT_MAT_NEAR(dst_gold, dst, 0.0);
}
TEST(Transpose, _32fc3)
{
const Size size = randomSize(100, 400);
Mat src = randomMat(size, CV_32FC3);
GpuMat_<float3> d_src(src);
GpuMat_<float3> dst = transpose_(d_src);
Mat dst_gold;
cv::transpose(src, dst_gold);
ASSERT_MAT_NEAR(dst_gold, dst, 0.0);
}