Commit 9885a671 authored by Andrey Pavlenko's avatar Andrey Pavlenko Committed by OpenCV Buildbot

Merge pull request #2346 from ilya-lavrenov:umat_tests_cleanup

parents 47d9b933 9b627a5e
......@@ -15,127 +15,4 @@
#include "opencv2/core/private.hpp"
#define MWIDTH 256
#define MHEIGHT 256
#define MIN_VALUE 171
#define MAX_VALUE 357
#define RNG_SEED 123456
template <typename T>
struct TSTestWithParam : public ::testing::TestWithParam<T>
{
cv::RNG rng;
TSTestWithParam()
{
rng = cv::RNG(RNG_SEED);
}
int randomInt(int minVal, int maxVal)
{
return rng.uniform(minVal, maxVal);
}
double randomDouble(double minVal, double maxVal)
{
return rng.uniform(minVal, maxVal);
}
double randomDoubleLog(double minVal, double maxVal)
{
double logMin = log((double)minVal + 1);
double logMax = log((double)maxVal + 1);
double pow = rng.uniform(logMin, logMax);
double v = exp(pow) - 1;
CV_Assert(v >= minVal && (v < maxVal || (v == minVal && v == maxVal)));
return v;
}
cv::Size randomSize(int minVal, int maxVal)
{
#if 1
return cv::Size((int)randomDoubleLog(minVal, maxVal), (int)randomDoubleLog(minVal, maxVal));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
cv::Size randomSize(int minValX, int maxValX, int minValY, int maxValY)
{
#if 1
return cv::Size(randomDoubleLog(minValX, maxValX), randomDoubleLog(minValY, maxValY));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
cv::Scalar randomScalar(double minVal, double maxVal)
{
return cv::Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
}
cv::Mat randomMat(cv::Size size, int type, double minVal, double maxVal, bool useRoi = false)
{
cv::RNG dataRng(rng.next());
return cvtest::randomMat(dataRng, size, type, minVal, maxVal, useRoi);
}
};
#define PARAM_TEST_CASE(name, ...) struct name : public TSTestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define UMAT_TEST_CHANNELS testing::Values(1, 2, 3, 4)
#define UMAT_TEST_SIZES testing::Values(cv::Size(1,1), cv::Size(1,128), cv::Size(128,1), cv::Size(128, 128), cv::Size(640,480), cv::Size(751,373), cv::Size(1200, 1200))
#define UMAT_TEST_DEPTH testing::Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F)
# define CORE_TEST_P(test_case_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : \
public test_case_name { \
public: \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() { } \
virtual void TestBody(); \
void CoreTestBody(); \
private: \
static int AddToRegistry() \
{ \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
#test_case_name, \
#test_name, \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
return 0; \
} \
\
static int gtest_registering_dummy_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
}; \
\
int GTEST_TEST_CLASS_NAME_(test_case_name, \
test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() \
{ \
try \
{ \
CoreTestBody(); \
} \
catch (...) \
{ \
std::cout << "Something wrong in CoreTestBody running" << std::endl; \
throw; \
} \
} \
\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::CoreTestBody()
#endif
This diff is collapsed.
......@@ -45,8 +45,6 @@
#include "ocl_test.hpp"
#include "ts_perf.hpp"
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
......@@ -130,6 +128,4 @@ using namespace perf;
} // namespace cvtest::ocl
} // namespace cvtest
#endif // HAVE_OPENCL
#endif // __OPENCV_TS_OCL_PERF_HPP__
......@@ -42,11 +42,8 @@
#ifndef __OPENCV_TS_OCL_TEST_HPP__
#define __OPENCV_TS_OCL_TEST_HPP__
#include "cvconfig.h" // to get definition of HAVE_OPENCL
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCL
#include "opencv2/ts.hpp"
#include "opencv2/highgui.hpp"
......@@ -60,45 +57,20 @@ namespace ocl {
using namespace cv;
using namespace testing;
namespace traits {
template <typename T>
struct GetMatForRead
{
};
template <>
struct GetMatForRead<Mat>
{
static const Mat get(const Mat& m) { return m; }
};
template <>
struct GetMatForRead<UMat>
{
static const Mat get(const UMat& m) { return m.getMat(ACCESS_READ); }
};
} // namespace traits
template <typename T>
const Mat getMatForRead(const T& mat)
{
return traits::GetMatForRead<T>::get(mat);
}
extern int test_loop_times;
#define MAX_VALUE 357
#define EXPECT_MAT_NORM(mat, eps) \
{ \
EXPECT_LE(checkNorm(mat), eps) \
EXPECT_LE(TestUtils::checkNorm(mat), eps) \
}
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNorm(mat1, mat2), eps) \
EXPECT_LE(TestUtils::checkNorm(mat1, mat2), eps) \
<< "Size: " << mat1.size() << std::endl; \
}
......@@ -106,7 +78,7 @@ extern int test_loop_times;
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNormRelative(mat1, mat2), eps) \
EXPECT_LE(TestUtils::checkNormRelative(mat1, mat2), eps) \
<< "Size: " << mat1.size() << std::endl; \
}
......@@ -227,54 +199,22 @@ struct CV_EXPORTS TestUtils
// If the two vectors are not equal, it will return the difference in vector size
// Else it will return (total diff of each 1 and 2 rects covered pixels)/(total 1 rects covered pixels)
// The smaller, the better matched
static double checkRectSimilarity(cv::Size sz, std::vector<cv::Rect>& ob1, std::vector<cv::Rect>& ob2);
static double checkRectSimilarity(const cv::Size & sz, std::vector<cv::Rect>& ob1, std::vector<cv::Rect>& ob2);
//! read image from testdata folder.
static cv::Mat readImage(const String &fileName, int flags = cv::IMREAD_COLOR);
static cv::Mat readImageType(const String &fname, int type);
static double checkNorm(const cv::Mat &m);
static double checkNorm(const cv::Mat &m1, const cv::Mat &m2);
static double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2);
static inline double checkNormRelative(const Mat &m1, const Mat &m2)
{
return cv::norm(m1, m2, cv::NORM_INF) /
std::max((double)std::numeric_limits<float>::epsilon(),
(double)std::max(cv::norm(m1, cv::NORM_INF), norm(m2, cv::NORM_INF)));
}
static void showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bool alwaysShow = false);
static double checkNorm(InputArray m);
static double checkNorm(InputArray m1, InputArray m2);
static double checkSimilarity(InputArray m1, InputArray m2);
static void showDiff(InputArray _src, InputArray _gold, InputArray _actual, double eps, bool alwaysShow);
template <typename T1>
static double checkNorm(const T1& m)
{
return checkNorm(getMatForRead(m));
}
template <typename T1, typename T2>
static double checkNorm(const T1& m1, const T2& m2)
{
return checkNorm(getMatForRead(m1), getMatForRead(m2));
}
template <typename T1, typename T2>
static double checkSimilarity(const T1& m1, const T2& m2)
static inline double checkNormRelative(InputArray m1, InputArray m2)
{
return checkSimilarity(getMatForRead(m1), getMatForRead(m2));
}
template <typename T1, typename T2>
static inline double checkNormRelative(const T1& m1, const T2& m2)
{
const Mat _m1 = getMatForRead(m1);
const Mat _m2 = getMatForRead(m2);
return checkNormRelative(_m1, _m2);
}
template <typename T1, typename T2, typename T3>
static void showDiff(const T1& src, const T2& gold, const T3& actual, double eps, bool alwaysShow = false)
{
const Mat _src = getMatForRead(src);
const Mat _gold = getMatForRead(gold);
const Mat _actual = getMatForRead(actual);
showDiff(_src, _gold, _actual, eps, alwaysShow);
return cv::norm(m1.getMat(), m2.getMat(), cv::NORM_INF) /
std::max((double)std::numeric_limits<float>::epsilon(),
(double)std::max(cv::norm(m1.getMat(), cv::NORM_INF), norm(m2.getMat(), cv::NORM_INF)));
}
};
......@@ -334,8 +274,6 @@ CV_ENUM(BorderType, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WR
#define OCL_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
INSTANTIATE_TEST_CASE_P(OCL_ ## prefix, test_case_name, generator)
}} // namespace cvtest::ocl
#endif // HAVE_OPENCL
} } // namespace cvtest::ocl
#endif // __OPENCV_TS_OCL_TEST_HPP__
......@@ -43,8 +43,6 @@
#include "opencv2/ts/ocl_perf.hpp"
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
......@@ -82,6 +80,4 @@ void randu(InputOutputArray dst)
} // namespace perf
}} // namespace cvtest::ocl
#endif // HAVE_OPENCL
} } // namespace cvtest::ocl
......@@ -43,8 +43,6 @@
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
......@@ -197,41 +195,39 @@ Mat TestUtils::readImageType(const String &fname, int type)
return src;
}
double TestUtils::checkNorm(const Mat &m)
double TestUtils::checkNorm(InputArray m)
{
return norm(m, NORM_INF);
return norm(m.getMat(), NORM_INF);
}
double TestUtils::checkNorm(const Mat &m1, const Mat &m2)
double TestUtils::checkNorm(InputArray m1, InputArray m2)
{
return norm(m1, m2, NORM_INF);
return norm(m1.getMat(), m2.getMat(), NORM_INF);
}
double TestUtils::checkSimilarity(const Mat &m1, const Mat &m2)
double TestUtils::checkSimilarity(InputArray m1, InputArray m2)
{
Mat diff;
matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
matchTemplate(m1.getMat(), m2.getMat(), diff, CV_TM_CCORR_NORMED);
return std::abs(diff.at<float>(0, 0) - 1.f);
}
double TestUtils::checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vector<Rect>& ob2)
double TestUtils::checkRectSimilarity(const Size & sz, std::vector<Rect>& ob1, std::vector<Rect>& ob2)
{
double final_test_result = 0.0;
size_t sz1 = ob1.size();
size_t sz2 = ob2.size();
if(sz1 != sz2)
{
if (sz1 != sz2)
return sz1 > sz2 ? (double)(sz1 - sz2) : (double)(sz2 - sz1);
}
else
{
if(sz1==0 && sz2==0)
if (sz1 == 0 && sz2 == 0)
return 0;
cv::Mat cpu_result(sz, CV_8UC1);
cpu_result.setTo(0);
for(vector<Rect>::const_iterator r = ob1.begin(); r != ob1.end(); r++)
for (vector<Rect>::const_iterator r = ob1.begin(); r != ob1.end(); r++)
{
cv::Mat cpu_result_roi(cpu_result, *r);
cpu_result_roi.setTo(1);
......@@ -251,7 +247,7 @@ double TestUtils::checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vect
cv::Mat result_;
multiply(cpu_result, gpu_result, result_);
int result = cv::countNonZero(result_ > 0);
if(cpu_area!=0 && result!=0)
if (cpu_area!=0 && result!=0)
final_test_result = 1.0 - (double)result/(double)cpu_area;
else if(cpu_area==0 && result!=0)
final_test_result = -1;
......@@ -259,8 +255,10 @@ double TestUtils::checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vect
return final_test_result;
}
void TestUtils::showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bool alwaysShow)
void TestUtils::showDiff(InputArray _src, InputArray _gold, InputArray _actual, double eps, bool alwaysShow)
{
Mat src = _src.getMat(), actual = _actual.getMat(), gold = _gold.getMat();
Mat diff, diff_thresh;
absdiff(gold, actual, diff);
diff.convertTo(diff, CV_32F);
......@@ -288,6 +286,4 @@ void TestUtils::showDiff(const Mat& src, const Mat& gold, const Mat& actual, dou
}
}
}} // namespace cvtest::ocl
#endif // HAVE_OPENCL
} } // namespace cvtest::ocl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment