refactoring npp tests

This commit is contained in:
Anatoly Baksheev 2010-09-25 15:44:08 +00:00
parent 21e22962d9
commit 02ced7b44c

View File

@ -54,8 +54,8 @@ using namespace gpu;
class CV_GpuArithmTest : public CvTest class CV_GpuArithmTest : public CvTest
{ {
public: public:
CV_GpuArithmTest(const char* test_name, const char* test_funcs); CV_GpuArithmTest(const char* test_name, const char* test_funcs) : CvTest(test_name, test_funcs) {}
virtual ~CV_GpuArithmTest(); virtual ~CV_GpuArithmTest() {}
protected: protected:
void run(int); void run(int);
@ -69,12 +69,6 @@ protected:
int CheckNorm(double d1, double d2); int CheckNorm(double d1, double d2);
}; };
CV_GpuArithmTest::CV_GpuArithmTest(const char* test_name, const char* test_funcs): CvTest(test_name, test_funcs)
{
}
CV_GpuArithmTest::~CV_GpuArithmTest() {}
int CV_GpuArithmTest::test(int type) int CV_GpuArithmTest::test(int type)
{ {
cv::Size sz(200, 200); cv::Size sz(200, 200);
@ -91,15 +85,11 @@ int CV_GpuArithmTest::CheckNorm(const Mat& m1, const Mat& m2)
double ret = norm(m1, m2, NORM_INF); double ret = norm(m1, m2, NORM_INF);
if (ret < std::numeric_limits<double>::epsilon()) if (ret < std::numeric_limits<double>::epsilon())
{
return CvTS::OK; return CvTS::OK;
}
else
{
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret); ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
return CvTS::FAIL_GENERIC; return CvTS::FAIL_GENERIC;
} }
}
int CV_GpuArithmTest::CheckNorm(const Scalar& s1, const Scalar& s2) int CV_GpuArithmTest::CheckNorm(const Scalar& s1, const Scalar& s2)
{ {
@ -113,23 +103,39 @@ int CV_GpuArithmTest::CheckNorm(double d1, double d2)
double ret = ::fabs(d1 - d2); double ret = ::fabs(d1 - d2);
if (ret < std::numeric_limits<double>::epsilon()) if (ret < std::numeric_limits<double>::epsilon())
{
return CvTS::OK; return CvTS::OK;
}
else
{
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret); ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
return CvTS::FAIL_GENERIC; return CvTS::FAIL_GENERIC;
} }
}
void CV_GpuArithmTest::run( int ) void CV_GpuArithmTest::run( int )
{ {
int testResult = CvTS::OK; int testResult = CvTS::OK;
try try
{ {
const int types[] = {CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1};
const char* type_names[] = {"CV_8UC1", "CV_8UC3", "CV_8UC4", "CV_32FC1"};
const int type_count = sizeof(types)/sizeof(types[0]);
//run tests //run tests
ts->printf(CvTS::LOG, "\n========Start test 8UC1========\n"); for (int t = 0; t < type_count; ++t)
{
ts->printf(CvTS::LOG, "========Start test %s========\n", type_names[t]);
if (CvTS::OK == test(types[t]))
ts->printf(CvTS::LOG, "SUCCESS\n");
else
{
ts->printf(CvTS::LOG, "FAIL\n");
testResult = CvTS::FAIL_MISMATCH;
}
}
///!!! author, please remove commented code if loop above is equivalent.
/*ts->printf(CvTS::LOG, "\n========Start test 8UC1========\n");
if (test(CV_8UC1) == CvTS::OK) if (test(CV_8UC1) == CvTS::OK)
ts->printf(CvTS::LOG, "\nSUCCESS\n"); ts->printf(CvTS::LOG, "\nSUCCESS\n");
else else
@ -163,7 +169,7 @@ void CV_GpuArithmTest::run( int )
{ {
ts->printf(CvTS::LOG, "\nFAIL\n"); ts->printf(CvTS::LOG, "\nFAIL\n");
testResult = CvTS::FAIL_GENERIC; testResult = CvTS::FAIL_GENERIC;
} }*/
} }
catch(const cv::Exception& e) catch(const cv::Exception& e)
{ {
@ -177,20 +183,12 @@ void CV_GpuArithmTest::run( int )
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Add // Add
class CV_GpuNppImageAddTest : public CV_GpuArithmTest
struct CV_GpuNppImageAddTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageAddTest() : CV_GpuArithmTest( "GPU-NppImageAdd", "add" ) {}
CV_GpuNppImageAddTest();
protected: virtual int test(const Mat& mat1, const Mat& mat2)
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageAddTest::CV_GpuNppImageAddTest(): CV_GpuArithmTest( "GPU-NppImageAdd", "add" )
{
}
int CV_GpuNppImageAddTest::test( const Mat& mat1, const Mat& mat2 )
{ {
if (mat1.type() != CV_8UC1 && mat1.type() != CV_8UC4 && mat1.type() != CV_32FC1) if (mat1.type() != CV_8UC1 && mat1.type() != CV_8UC4 && mat1.type() != CV_32FC1)
{ {
@ -208,25 +206,15 @@ int CV_GpuNppImageAddTest::test( const Mat& mat1, const Mat& mat2 )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageAddTest CV_GpuNppImageAdd_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Sub // Sub
class CV_GpuNppImageSubtractTest : public CV_GpuArithmTest struct CV_GpuNppImageSubtractTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageSubtractTest() : CV_GpuArithmTest( "GPU-NppImageSubtract", "subtract" ) {}
CV_GpuNppImageSubtractTest();
protected: int test( const Mat& mat1, const Mat& mat2 )
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageSubtractTest::CV_GpuNppImageSubtractTest(): CV_GpuArithmTest( "GPU-NppImageSubtract", "subtract" )
{
}
int CV_GpuNppImageSubtractTest::test( const Mat& mat1, const Mat& mat2 )
{ {
if (mat1.type() != CV_8UC1 && mat1.type() != CV_8UC4 && mat1.type() != CV_32FC1) if (mat1.type() != CV_8UC1 && mat1.type() != CV_8UC4 && mat1.type() != CV_32FC1)
{ {
@ -244,23 +232,13 @@ int CV_GpuNppImageSubtractTest::test( const Mat& mat1, const Mat& mat2 )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageSubtractTest CV_GpuNppImageSubtract_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// multiply // multiply
class CV_GpuNppImageMultiplyTest : public CV_GpuArithmTest struct CV_GpuNppImageMultiplyTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageMultiplyTest() : CV_GpuArithmTest( "GPU-NppImageMultiply", "multiply" ) {}
CV_GpuNppImageMultiplyTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageMultiplyTest::CV_GpuNppImageMultiplyTest(): CV_GpuArithmTest( "GPU-NppImageMultiply", "multiply" )
{
}
int CV_GpuNppImageMultiplyTest::test( const Mat& mat1, const Mat& mat2 ) int CV_GpuNppImageMultiplyTest::test( const Mat& mat1, const Mat& mat2 )
{ {
@ -280,23 +258,13 @@ int CV_GpuNppImageMultiplyTest::test( const Mat& mat1, const Mat& mat2 )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageMultiplyTest CV_GpuNppImageMultiply_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// divide // divide
class CV_GpuNppImageDivideTest : public CV_GpuArithmTest struct CV_GpuNppImageDivideTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageDivideTest() : CV_GpuArithmTest( "GPU-NppImageDivide", "divide" ) {}
CV_GpuNppImageDivideTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageDivideTest::CV_GpuNppImageDivideTest(): CV_GpuArithmTest( "GPU-NppImageDivide", "divide" )
{
}
int CV_GpuNppImageDivideTest::test( const Mat& mat1, const Mat& mat2 ) int CV_GpuNppImageDivideTest::test( const Mat& mat1, const Mat& mat2 )
{ {
@ -316,23 +284,13 @@ int CV_GpuNppImageDivideTest::test( const Mat& mat1, const Mat& mat2 )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageDivideTest CV_GpuNppImageDivide_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// transpose // transpose
class CV_GpuNppImageTransposeTest : public CV_GpuArithmTest struct CV_GpuNppImageTransposeTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageTransposeTest() : CV_GpuArithmTest( "GPU-NppImageTranspose", "transpose" ) {}
CV_GpuNppImageTransposeTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageTransposeTest::CV_GpuNppImageTransposeTest(): CV_GpuArithmTest( "GPU-NppImageTranspose", "transpose" )
{
}
int CV_GpuNppImageTransposeTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageTransposeTest::test( const Mat& mat1, const Mat& )
{ {
@ -351,23 +309,13 @@ int CV_GpuNppImageTransposeTest::test( const Mat& mat1, const Mat& )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageTransposeTest CV_GpuNppImageTranspose_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// absdiff // absdiff
class CV_GpuNppImageAbsdiffTest : public CV_GpuArithmTest struct CV_GpuNppImageAbsdiffTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageAbsdiffTest() : CV_GpuArithmTest( "GPU-NppImageAbsdiff", "absdiff" ) {}
CV_GpuNppImageAbsdiffTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageAbsdiffTest::CV_GpuNppImageAbsdiffTest(): CV_GpuArithmTest( "GPU-NppImageAbsdiff", "absdiff" )
{
}
int CV_GpuNppImageAbsdiffTest::test( const Mat& mat1, const Mat& mat2 ) int CV_GpuNppImageAbsdiffTest::test( const Mat& mat1, const Mat& mat2 )
{ {
@ -387,23 +335,13 @@ int CV_GpuNppImageAbsdiffTest::test( const Mat& mat1, const Mat& mat2 )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
CV_GpuNppImageAbsdiffTest CV_GpuNppImageAbsdiff_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// compare // compare
class CV_GpuNppImageCompareTest : public CV_GpuArithmTest struct CV_GpuNppImageCompareTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageCompareTest() : CV_GpuArithmTest( "GPU-NppImageCompare", "compare" ) {}
CV_GpuNppImageCompareTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageCompareTest::CV_GpuNppImageCompareTest(): CV_GpuArithmTest( "GPU-NppImageCompare", "compare" )
{
}
int CV_GpuNppImageCompareTest::test( const Mat& mat1, const Mat& mat2 ) int CV_GpuNppImageCompareTest::test( const Mat& mat1, const Mat& mat2 )
{ {
@ -437,23 +375,13 @@ int CV_GpuNppImageCompareTest::test( const Mat& mat1, const Mat& mat2 )
return test_res; return test_res;
} }
};
CV_GpuNppImageCompareTest CV_GpuNppImageCompare_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// meanStdDev // meanStdDev
class CV_GpuNppImageMeanStdDevTest : public CV_GpuArithmTest struct CV_GpuNppImageMeanStdDevTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageMeanStdDevTest() : CV_GpuArithmTest( "GPU-NppImageMeanStdDev", "meanStdDev" ) {}
CV_GpuNppImageMeanStdDevTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageMeanStdDevTest::CV_GpuNppImageMeanStdDevTest(): CV_GpuArithmTest( "GPU-NppImageMeanStdDev", "meanStdDev" )
{
}
int CV_GpuNppImageMeanStdDevTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageMeanStdDevTest::test( const Mat& mat1, const Mat& )
{ {
@ -488,23 +416,13 @@ int CV_GpuNppImageMeanStdDevTest::test( const Mat& mat1, const Mat& )
return test_res; return test_res;
} }
};
CV_GpuNppImageMeanStdDevTest CV_GpuNppImageMeanStdDev_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// norm // norm
class CV_GpuNppImageNormTest : public CV_GpuArithmTest struct CV_GpuNppImageNormTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageNormTest() : CV_GpuArithmTest( "GPU-NppImageNorm", "norm" ) {}
CV_GpuNppImageNormTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageNormTest::CV_GpuNppImageNormTest(): CV_GpuArithmTest( "GPU-NppImageNorm", "norm" )
{
}
int CV_GpuNppImageNormTest::test( const Mat& mat1, const Mat& mat2 ) int CV_GpuNppImageNormTest::test( const Mat& mat1, const Mat& mat2 )
{ {
@ -536,23 +454,13 @@ int CV_GpuNppImageNormTest::test( const Mat& mat1, const Mat& mat2 )
return test_res; return test_res;
} }
};
CV_GpuNppImageNormTest CV_GpuNppImageNorm_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// flip // flip
class CV_GpuNppImageFlipTest : public CV_GpuArithmTest struct CV_GpuNppImageFlipTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageFlipTest() : CV_GpuArithmTest( "GPU-NppImageFlip", "flip" ) {}
CV_GpuNppImageFlipTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageFlipTest::CV_GpuNppImageFlipTest(): CV_GpuArithmTest( "GPU-NppImageFlip", "flip" )
{
}
int CV_GpuNppImageFlipTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageFlipTest::test( const Mat& mat1, const Mat& )
{ {
@ -585,23 +493,13 @@ int CV_GpuNppImageFlipTest::test( const Mat& mat1, const Mat& )
return test_res; return test_res;
} }
};
CV_GpuNppImageFlipTest CV_GpuNppImageFlip_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// sum // sum
class CV_GpuNppImageSumTest : public CV_GpuArithmTest struct CV_GpuNppImageSumTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageSumTest() : CV_GpuArithmTest( "GPU-NppImageSum", "sum" ) {}
CV_GpuNppImageSumTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageSumTest::CV_GpuNppImageSumTest(): CV_GpuArithmTest( "GPU-NppImageSum", "sum" )
{
}
int CV_GpuNppImageSumTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageSumTest::test( const Mat& mat1, const Mat& )
{ {
@ -618,23 +516,13 @@ int CV_GpuNppImageSumTest::test( const Mat& mat1, const Mat& )
return CheckNorm(cpures, gpures); return CheckNorm(cpures, gpures);
} }
};
CV_GpuNppImageSumTest CV_GpuNppImageSum_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// minNax // minNax
class CV_GpuNppImageMinNaxTest : public CV_GpuArithmTest struct CV_GpuNppImageMinNaxTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageMinNaxTest() : CV_GpuArithmTest( "GPU-NppImageMinNax", "minNax" ) {}
CV_GpuNppImageMinNaxTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageMinNaxTest::CV_GpuNppImageMinNaxTest(): CV_GpuArithmTest( "GPU-NppImageMinNax", "minNax" )
{
}
int CV_GpuNppImageMinNaxTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageMinNaxTest::test( const Mat& mat1, const Mat& )
{ {
@ -653,23 +541,13 @@ int CV_GpuNppImageMinNaxTest::test( const Mat& mat1, const Mat& )
return (CheckNorm(cpumin, gpumin) == CvTS::OK && CheckNorm(cpumax, gpumax) == CvTS::OK) ? CvTS::OK : CvTS::FAIL_GENERIC; return (CheckNorm(cpumin, gpumin) == CvTS::OK && CheckNorm(cpumax, gpumax) == CvTS::OK) ? CvTS::OK : CvTS::FAIL_GENERIC;
} }
};
CV_GpuNppImageMinNaxTest CV_GpuNppImageMinNax_test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LUT // LUT
class CV_GpuNppImageLUTTest : public CV_GpuArithmTest struct CV_GpuNppImageLUTTest : public CV_GpuArithmTest
{ {
public: CV_GpuNppImageLUTTest() : CV_GpuArithmTest( "GPU-NppImageLUT", "LUT" ) {}
CV_GpuNppImageLUTTest();
protected:
virtual int test(const Mat& mat1, const Mat& mat2);
};
CV_GpuNppImageLUTTest::CV_GpuNppImageLUTTest(): CV_GpuArithmTest( "GPU-NppImageLUT", "LUT" )
{
}
int CV_GpuNppImageLUTTest::test( const Mat& mat1, const Mat& ) int CV_GpuNppImageLUTTest::test( const Mat& mat1, const Mat& )
{ {
@ -692,5 +570,24 @@ int CV_GpuNppImageLUTTest::test( const Mat& mat1, const Mat& )
return CheckNorm(cpuRes, gpuRes); return CheckNorm(cpuRes, gpuRes);
} }
};
// If we comment some tests, we may foget/miss to uncomment it after.
// Placing all test definitions in one place
// makes us know about what tests are commented.
CV_GpuNppImageAddTest CV_GpuNppImageAdd_test;
CV_GpuNppImageSubtractTest CV_GpuNppImageSubtract_test;
CV_GpuNppImageMultiplyTest CV_GpuNppImageMultiply_test;
CV_GpuNppImageDivideTest CV_GpuNppImageDivide_test;
CV_GpuNppImageTransposeTest CV_GpuNppImageTranspose_test;
CV_GpuNppImageAbsdiffTest CV_GpuNppImageAbsdiff_test;
CV_GpuNppImageCompareTest CV_GpuNppImageCompare_test;
CV_GpuNppImageMeanStdDevTest CV_GpuNppImageMeanStdDev_test;
CV_GpuNppImageNormTest CV_GpuNppImageNorm_test;
CV_GpuNppImageFlipTest CV_GpuNppImageFlip_test;
//CV_GpuNppImageSumTest CV_GpuNppImageSum_test;
CV_GpuNppImageMinNaxTest CV_GpuNppImageMinNax_test;
CV_GpuNppImageLUTTest CV_GpuNppImageLUT_test; CV_GpuNppImageLUTTest CV_GpuNppImageLUT_test;