Revert "Merge pull request #836 from jet47:gpu-modules"
This reverts commitfba72cb60d
, reversing changes made to02131ffb62
.
This commit is contained in:
131
modules/gpu/test/interpolation.hpp
Normal file
131
modules/gpu/test/interpolation.hpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_TEST_INTERPOLATION_HPP__
|
||||
#define __OPENCV_TEST_INTERPOLATION_HPP__
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
template <typename T> T readVal(const cv::Mat& src, int y, int x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
if (border_type == cv::BORDER_CONSTANT)
|
||||
return (y >= 0 && y < src.rows && x >= 0 && x < src.cols) ? src.at<T>(y, x * src.channels() + c) : cv::saturate_cast<T>(borderVal.val[c]);
|
||||
|
||||
return src.at<T>(cv::borderInterpolate(y, src.rows, border_type), cv::borderInterpolate(x, src.cols, border_type) * src.channels() + c);
|
||||
}
|
||||
|
||||
template <typename T> struct NearestInterpolator
|
||||
{
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
return readVal<T>(src, int(y), int(x), c, border_type, borderVal);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct LinearInterpolator
|
||||
{
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
int x1 = cvFloor(x);
|
||||
int y1 = cvFloor(y);
|
||||
int x2 = x1 + 1;
|
||||
int y2 = y1 + 1;
|
||||
|
||||
float res = 0;
|
||||
|
||||
res += readVal<T>(src, y1, x1, c, border_type, borderVal) * ((x2 - x) * (y2 - y));
|
||||
res += readVal<T>(src, y1, x2, c, border_type, borderVal) * ((x - x1) * (y2 - y));
|
||||
res += readVal<T>(src, y2, x1, c, border_type, borderVal) * ((x2 - x) * (y - y1));
|
||||
res += readVal<T>(src, y2, x2, c, border_type, borderVal) * ((x - x1) * (y - y1));
|
||||
|
||||
return cv::saturate_cast<T>(res);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct CubicInterpolator
|
||||
{
|
||||
static float bicubicCoeff(float x_)
|
||||
{
|
||||
float x = fabsf(x_);
|
||||
if (x <= 1.0f)
|
||||
{
|
||||
return x * x * (1.5f * x - 2.5f) + 1.0f;
|
||||
}
|
||||
else if (x < 2.0f)
|
||||
{
|
||||
return x * (x * (-0.5f * x + 2.5f) - 4.0f) + 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
const float xmin = ceilf(x - 2.0f);
|
||||
const float xmax = floorf(x + 2.0f);
|
||||
|
||||
const float ymin = ceilf(y - 2.0f);
|
||||
const float ymax = floorf(y + 2.0f);
|
||||
|
||||
float sum = 0.0f;
|
||||
float wsum = 0.0f;
|
||||
|
||||
for (float cy = ymin; cy <= ymax; cy += 1.0f)
|
||||
{
|
||||
for (float cx = xmin; cx <= xmax; cx += 1.0f)
|
||||
{
|
||||
const float w = bicubicCoeff(x - cx) * bicubicCoeff(y - cy);
|
||||
sum += w * readVal<T>(src, (int) floorf(cy), (int) floorf(cx), c, border_type, borderVal);
|
||||
wsum += w;
|
||||
}
|
||||
}
|
||||
|
||||
float res = (!wsum)? 0 : sum / wsum;
|
||||
|
||||
return cv::saturate_cast<T>(res);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __OPENCV_TEST_INTERPOLATION_HPP__
|
130
modules/gpu/test/main.cpp
Normal file
130
modules/gpu/test/main.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
const std::string keys =
|
||||
"{ h help ? | | Print help}"
|
||||
"{ i info | | Print information about system and exit }"
|
||||
"{ device | -1 | Device on which tests will be executed (-1 means all devices) }"
|
||||
"{ nvtest_output_level | none | NVidia test verbosity level (none, compact, full) }"
|
||||
;
|
||||
|
||||
CommandLineParser cmd(argc, (const char**)argv, keys);
|
||||
|
||||
if (cmd.has("help"))
|
||||
{
|
||||
cmd.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
printCudaInfo();
|
||||
|
||||
if (cmd.has("info"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device = cmd.get<int>("device");
|
||||
if (device < 0)
|
||||
{
|
||||
DeviceManager::instance().loadAll();
|
||||
|
||||
cout << "Run tests on all supported devices \n" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceManager::instance().load(device);
|
||||
|
||||
DeviceInfo info(device);
|
||||
cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl;
|
||||
}
|
||||
|
||||
string outputLevel = cmd.get<string>("nvtest_output_level");
|
||||
|
||||
if (outputLevel == "none")
|
||||
nvidiaTestOutputLevel = OutputLevelNone;
|
||||
else if (outputLevel == "compact")
|
||||
nvidiaTestOutputLevel = OutputLevelCompact;
|
||||
else if (outputLevel == "full")
|
||||
nvidiaTestOutputLevel = OutputLevelFull;
|
||||
|
||||
TS::ptr()->init("gpu");
|
||||
InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
catch (const exception& e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return -1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "Unknown error" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("OpenCV was built without CUDA support\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_CUDA
|
67
modules/gpu/test/main_test_nvidia.h
Normal file
67
modules/gpu/test/main_test_nvidia.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __main_test_nvidia_h__
|
||||
#define __main_test_nvidia_h__
|
||||
|
||||
enum OutputLevel
|
||||
{
|
||||
OutputLevelNone,
|
||||
OutputLevelCompact,
|
||||
OutputLevelFull
|
||||
};
|
||||
|
||||
extern OutputLevel nvidiaTestOutputLevel;
|
||||
|
||||
bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NPPST_RectStdDev(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NPPST_Resize(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NPPST_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NPPST_Transpose(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NCV_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NCV_Haar_Cascade_Loader(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NCV_Haar_Cascade_Application(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NCV_Hypotheses_Filtration(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel outputLevel);
|
||||
|
||||
#endif
|
172
modules/gpu/test/nvidia/NCVAutoTestLister.hpp
Normal file
172
modules/gpu/test/nvidia/NCVAutoTestLister.hpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _ncvautotestlister_hpp_
|
||||
#define _ncvautotestlister_hpp_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include <main_test_nvidia.h>
|
||||
//enum OutputLevel
|
||||
//{
|
||||
// OutputLevelNone,
|
||||
// OutputLevelCompact,
|
||||
// OutputLevelFull
|
||||
//};
|
||||
|
||||
class NCVAutoTestLister
|
||||
{
|
||||
public:
|
||||
|
||||
NCVAutoTestLister(std::string testSuiteName_, OutputLevel outputLevel_ = OutputLevelCompact, NcvBool bStopOnFirstFail_=false)
|
||||
:
|
||||
testSuiteName(testSuiteName_),
|
||||
outputLevel(outputLevel_),
|
||||
bStopOnFirstFail(bStopOnFirstFail_)
|
||||
{
|
||||
}
|
||||
|
||||
void add(INCVTest *test)
|
||||
{
|
||||
this->tests.push_back(test);
|
||||
}
|
||||
|
||||
bool invoke()
|
||||
{
|
||||
Ncv32u nPassed = 0;
|
||||
Ncv32u nFailed = 0;
|
||||
Ncv32u nFailedMem = 0;
|
||||
|
||||
if (outputLevel == OutputLevelCompact)
|
||||
{
|
||||
printf("Test suite '%s' with %d tests\n",
|
||||
testSuiteName.c_str(),
|
||||
(int)(this->tests.size()));
|
||||
}
|
||||
|
||||
for (Ncv32u i=0; i<this->tests.size(); i++)
|
||||
{
|
||||
INCVTest &curTest = *tests[i];
|
||||
|
||||
NCVTestReport curReport;
|
||||
bool res = curTest.executeTest(curReport);
|
||||
|
||||
if (outputLevel == OutputLevelFull)
|
||||
{
|
||||
printf("Test %3i %16s; Consumed mem GPU = %8d, CPU = %8d; %s\n",
|
||||
i,
|
||||
curTest.getName().c_str(),
|
||||
curReport.statsNums["MemGPU"],
|
||||
curReport.statsNums["MemCPU"],
|
||||
curReport.statsText["rcode"].c_str());
|
||||
}
|
||||
|
||||
if (res)
|
||||
{
|
||||
nPassed++;
|
||||
if (outputLevel == OutputLevelCompact)
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!curReport.statsText["rcode"].compare("FAILED"))
|
||||
{
|
||||
nFailed++;
|
||||
if (outputLevel == OutputLevelCompact)
|
||||
{
|
||||
printf("x");
|
||||
}
|
||||
if (bStopOnFirstFail)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nFailedMem++;
|
||||
if (outputLevel == OutputLevelCompact)
|
||||
{
|
||||
printf("m");
|
||||
}
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
if (outputLevel == OutputLevelCompact)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (outputLevel != OutputLevelNone)
|
||||
{
|
||||
printf("Test suite '%s' complete: %d total, %d passed, %d memory errors, %d failed\n\n",
|
||||
testSuiteName.c_str(),
|
||||
(int)(this->tests.size()),
|
||||
nPassed,
|
||||
nFailedMem,
|
||||
nFailed);
|
||||
}
|
||||
|
||||
bool passed = nFailed == 0 && nFailedMem == 0;
|
||||
return passed;
|
||||
}
|
||||
|
||||
~NCVAutoTestLister()
|
||||
{
|
||||
for (Ncv32u i=0; i<this->tests.size(); i++)
|
||||
{
|
||||
delete tests[i];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string testSuiteName;
|
||||
OutputLevel outputLevel;
|
||||
NcvBool bStopOnFirstFail;
|
||||
std::vector<INCVTest *> tests;
|
||||
};
|
||||
|
||||
#endif // _ncvautotestlister_hpp_
|
246
modules/gpu/test/nvidia/NCVTest.hpp
Normal file
246
modules/gpu/test/nvidia/NCVTest.hpp
Normal file
@@ -0,0 +1,246 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _ncvtest_hpp_
|
||||
#define _ncvtest_hpp_
|
||||
|
||||
#if defined _MSC_VER
|
||||
# pragma warning( disable : 4201 4408 4127 4100)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "NPP_staging.hpp"
|
||||
|
||||
|
||||
struct NCVTestReport
|
||||
{
|
||||
std::map<std::string, Ncv32u> statsNums;
|
||||
std::map<std::string, std::string> statsText;
|
||||
};
|
||||
|
||||
|
||||
class INCVTest
|
||||
{
|
||||
public:
|
||||
virtual bool executeTest(NCVTestReport &report) = 0;
|
||||
virtual std::string getName() const = 0;
|
||||
virtual ~INCVTest(){}
|
||||
};
|
||||
|
||||
|
||||
class NCVTestProvider : public INCVTest
|
||||
{
|
||||
public:
|
||||
|
||||
NCVTestProvider(std::string testName_)
|
||||
:
|
||||
testName(testName_)
|
||||
{
|
||||
int devId;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&this->devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
}
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual bool process() = 0;
|
||||
virtual bool deinit() = 0;
|
||||
virtual bool toString(std::ofstream &strOut) = 0;
|
||||
|
||||
virtual std::string getName() const
|
||||
{
|
||||
return this->testName;
|
||||
}
|
||||
|
||||
virtual ~NCVTestProvider()
|
||||
{
|
||||
deinitMemory();
|
||||
}
|
||||
|
||||
virtual bool executeTest(NCVTestReport &report)
|
||||
{
|
||||
bool res;
|
||||
report.statsText["rcode"] = "FAILED";
|
||||
|
||||
res = initMemory(report);
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = init();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinit();
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = process();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinit();
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = deinit();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
deinitMemory();
|
||||
|
||||
report.statsText["rcode"] = "Passed";
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
cudaDeviceProp devProp;
|
||||
std::auto_ptr<INCVMemAllocator> allocatorGPU;
|
||||
std::auto_ptr<INCVMemAllocator> allocatorCPU;
|
||||
|
||||
private:
|
||||
|
||||
std::string testName;
|
||||
|
||||
bool initMemory(NCVTestReport &report)
|
||||
{
|
||||
this->allocatorGPU.reset(new NCVMemStackAllocator(static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
this->allocatorCPU.reset(new NCVMemStackAllocator(static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
|
||||
if (!this->allocatorGPU.get()->isInitialized() ||
|
||||
!this->allocatorCPU.get()->isInitialized())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->process())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
Ncv32u maxGPUsize = (Ncv32u)this->allocatorGPU.get()->maxSize();
|
||||
Ncv32u maxCPUsize = (Ncv32u)this->allocatorCPU.get()->maxSize();
|
||||
|
||||
report.statsNums["MemGPU"] = maxGPUsize;
|
||||
report.statsNums["MemCPU"] = maxCPUsize;
|
||||
|
||||
this->allocatorGPU.reset(new NCVMemStackAllocator(NCVMemoryTypeDevice, maxGPUsize, static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
|
||||
this->allocatorCPU.reset(new NCVMemStackAllocator(NCVMemoryTypeHostPinned, maxCPUsize, static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
|
||||
if (!this->allocatorGPU.get()->isInitialized() ||
|
||||
!this->allocatorCPU.get()->isInitialized())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void deinitMemory()
|
||||
{
|
||||
this->allocatorGPU.reset();
|
||||
this->allocatorCPU.reset();
|
||||
}
|
||||
|
||||
void dumpToFile(NCVTestReport &report)
|
||||
{
|
||||
bool bReasonMem = (0 == report.statsText["rcode"].compare("Memory FAILED"));
|
||||
std::string fname = "TestDump_";
|
||||
fname += (bReasonMem ? "m_" : "") + this->testName + ".log";
|
||||
std::ofstream stream(fname.c_str(), std::ios::trunc | std::ios::out);
|
||||
if (!stream.is_open()) return;
|
||||
|
||||
stream << "NCV Test Failure Log: " << this->testName << std::endl;
|
||||
stream << "====================================================" << std::endl << std::endl;
|
||||
stream << "Test initialization report: " << std::endl;
|
||||
for (std::map<std::string,std::string>::iterator it=report.statsText.begin();
|
||||
it != report.statsText.end(); it++)
|
||||
{
|
||||
stream << it->first << "=" << it->second << std::endl;
|
||||
}
|
||||
for (std::map<std::string,Ncv32u>::iterator it=report.statsNums.begin();
|
||||
it != report.statsNums.end(); it++)
|
||||
{
|
||||
stream << it->first << "=" << it->second << std::endl;
|
||||
}
|
||||
stream << std::endl;
|
||||
|
||||
stream << "Test initialization parameters: " << std::endl;
|
||||
bool bSerializeRes = false;
|
||||
try
|
||||
{
|
||||
bSerializeRes = this->toString(stream);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
if (!bSerializeRes)
|
||||
{
|
||||
stream << "Couldn't retrieve object dump" << std::endl;
|
||||
}
|
||||
|
||||
stream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _ncvtest_hpp_
|
193
modules/gpu/test/nvidia/NCVTestSourceProvider.hpp
Normal file
193
modules/gpu/test/nvidia/NCVTestSourceProvider.hpp
Normal file
@@ -0,0 +1,193 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _ncvtestsourceprovider_hpp_
|
||||
#define _ncvtestsourceprovider_hpp_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "NCV.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
|
||||
template <class T>
|
||||
class NCVTestSourceProvider
|
||||
{
|
||||
public:
|
||||
|
||||
NCVTestSourceProvider(Ncv32u seed, T rangeLow, T rangeHigh, Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
:
|
||||
bInit(false)
|
||||
{
|
||||
ncvAssertPrintReturn(rangeLow < rangeHigh, "NCVTestSourceProvider ctor:: Invalid range", );
|
||||
|
||||
int devId;
|
||||
cudaDeviceProp devProp;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
|
||||
//Ncv32u maxWpitch = alignUp(maxWidth * sizeof(T), devProp.textureAlignment);
|
||||
|
||||
allocatorCPU.reset(new NCVMemNativeAllocator(NCVMemoryTypeHostPinned, static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
data.reset(new NCVMatrixAlloc<T>(*this->allocatorCPU.get(), maxWidth, maxHeight));
|
||||
ncvAssertPrintReturn(data.get()->isMemAllocated(), "NCVTestSourceProvider ctor:: Matrix not allocated", );
|
||||
|
||||
this->dataWidth = maxWidth;
|
||||
this->dataHeight = maxHeight;
|
||||
|
||||
srand(seed);
|
||||
|
||||
for (Ncv32u i=0; i<maxHeight; i++)
|
||||
{
|
||||
for (Ncv32u j=0; j<data.get()->stride(); j++)
|
||||
{
|
||||
data.get()->ptr()[i * data.get()->stride() + j] =
|
||||
(T)(((1.0 * rand()) / RAND_MAX) * (rangeHigh - rangeLow) + rangeLow);
|
||||
}
|
||||
}
|
||||
|
||||
this->bInit = true;
|
||||
}
|
||||
|
||||
NCVTestSourceProvider(std::string pgmFilename)
|
||||
:
|
||||
bInit(false)
|
||||
{
|
||||
ncvAssertPrintReturn(sizeof(T) == 1, "NCVTestSourceProvider ctor:: PGM constructor complies only with 8bit types", );
|
||||
|
||||
cv::Mat image = cv::imread(pgmFilename);
|
||||
ncvAssertPrintReturn(!image.empty(), "NCVTestSourceProvider ctor:: PGM file error", );
|
||||
|
||||
int devId;
|
||||
cudaDeviceProp devProp;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
|
||||
allocatorCPU.reset(new NCVMemNativeAllocator(NCVMemoryTypeHostPinned, static_cast<Ncv32u>(devProp.textureAlignment)));
|
||||
data.reset(new NCVMatrixAlloc<T>(*this->allocatorCPU.get(), image.cols, image.rows));
|
||||
ncvAssertPrintReturn(data.get()->isMemAllocated(), "NCVTestSourceProvider ctor:: Matrix not allocated", );
|
||||
|
||||
this->dataWidth = image.cols;
|
||||
this->dataHeight = image.rows;
|
||||
|
||||
cv::Mat hdr(image.size(), CV_8UC1, data.get()->ptr(), data.get()->pitch());
|
||||
image.copyTo(hdr);
|
||||
|
||||
this->bInit = true;
|
||||
}
|
||||
|
||||
NcvBool fill(NCVMatrix<T> &dst)
|
||||
{
|
||||
ncvAssertReturn(this->isInit() &&
|
||||
dst.memType() == allocatorCPU.get()->memType(), false);
|
||||
|
||||
if (dst.width() == 0 || dst.height() == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Ncv32u i=0; i<dst.height(); i++)
|
||||
{
|
||||
Ncv32u srcLine = i % this->dataHeight;
|
||||
|
||||
Ncv32u srcFullChunks = dst.width() / this->dataWidth;
|
||||
for (Ncv32u j=0; j<srcFullChunks; j++)
|
||||
{
|
||||
memcpy(dst.ptr() + i * dst.stride() + j * this->dataWidth,
|
||||
this->data.get()->ptr() + this->data.get()->stride() * srcLine,
|
||||
this->dataWidth * sizeof(T));
|
||||
}
|
||||
|
||||
Ncv32u srcLastChunk = dst.width() % this->dataWidth;
|
||||
memcpy(dst.ptr() + i * dst.stride() + srcFullChunks * this->dataWidth,
|
||||
this->data.get()->ptr() + this->data.get()->stride() * srcLine,
|
||||
srcLastChunk * sizeof(T));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NcvBool fill(NCVVector<T> &dst)
|
||||
{
|
||||
ncvAssertReturn(this->isInit() &&
|
||||
dst.memType() == allocatorCPU.get()->memType(), false);
|
||||
|
||||
if (dst.length() == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Ncv32u srcLen = this->dataWidth * this->dataHeight;
|
||||
|
||||
Ncv32u srcFullChunks = (Ncv32u)dst.length() / srcLen;
|
||||
for (Ncv32u j=0; j<srcFullChunks; j++)
|
||||
{
|
||||
memcpy(dst.ptr() + j * srcLen, this->data.get()->ptr(), srcLen * sizeof(T));
|
||||
}
|
||||
|
||||
Ncv32u srcLastChunk = dst.length() % srcLen;
|
||||
memcpy(dst.ptr() + srcFullChunks * srcLen, this->data.get()->ptr(), srcLastChunk * sizeof(T));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
~NCVTestSourceProvider()
|
||||
{
|
||||
data.reset();
|
||||
allocatorCPU.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
NcvBool isInit(void)
|
||||
{
|
||||
return this->bInit;
|
||||
}
|
||||
|
||||
NcvBool bInit;
|
||||
std::auto_ptr< INCVMemAllocator > allocatorCPU;
|
||||
std::auto_ptr< NCVMatrixAlloc<T> > data;
|
||||
Ncv32u dataWidth;
|
||||
Ncv32u dataHeight;
|
||||
};
|
||||
|
||||
#endif // _ncvtestsourceprovider_hpp_
|
164
modules/gpu/test/nvidia/TestCompact.cpp
Normal file
164
modules/gpu/test/nvidia/TestCompact.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestCompact.h"
|
||||
|
||||
|
||||
TestCompact::TestCompact(std::string testName_, NCVTestSourceProvider<Ncv32u> &src_,
|
||||
Ncv32u length_, Ncv32u badElem_, Ncv32u badElemPercentage_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
length(length_),
|
||||
badElem(badElem_),
|
||||
badElemPercentage(badElemPercentage_ > 100 ? 100 : badElemPercentage_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "length=" << length << std::endl;
|
||||
strOut << "badElem=" << badElem << std::endl;
|
||||
strOut << "badElemPercentage=" << badElemPercentage << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->length);
|
||||
ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecDst(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecDst(*this->allocatorGPU.get(), this->length);
|
||||
ncvAssertReturn(d_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> h_vecDst_d(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_vecSrc), false);
|
||||
for (Ncv32u i=0; i<this->length; i++)
|
||||
{
|
||||
Ncv32u tmp = (h_vecSrc.ptr()[i]) & 0xFF;
|
||||
tmp = tmp * 99 / 255;
|
||||
if (tmp < this->badElemPercentage)
|
||||
{
|
||||
h_vecSrc.ptr()[i] = this->badElem;
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_dstLen(*this->allocatorCPU.get(), 1);
|
||||
ncvAssertReturn(h_dstLen.isMemAllocated(), false);
|
||||
Ncv32u bufSize;
|
||||
ncvStat = nppsStCompactGetSize_32u(this->length, &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
Ncv32u h_outElemNum_h = 0;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
ncvStat = nppsStCompact_32u(d_vecSrc.ptr(), this->length,
|
||||
d_vecDst.ptr(), h_dstLen.ptr(), this->badElem,
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppsStCompact_32u_host(h_vecSrc.ptr(), this->length, h_vecDst.ptr(), &h_outElemNum_h, this->badElem);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (h_dstLen.ptr()[0] != h_outElemNum_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_outElemNum_h; i++)
|
||||
{
|
||||
if (h_vecDst.ptr()[i] != h_vecDst_d.ptr()[i])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
73
modules/gpu/test/nvidia/TestCompact.h
Normal file
73
modules/gpu/test/nvidia/TestCompact.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testhypothesescompact_h_
|
||||
#define _testhypothesescompact_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestCompact : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestCompact(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u length, Ncv32u badElem, Ncv32u badElemPercentage);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestCompact(const TestCompact&);
|
||||
TestCompact& operator=(const TestCompact&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u length;
|
||||
Ncv32u badElem;
|
||||
Ncv32u badElemPercentage;
|
||||
};
|
||||
|
||||
#endif // _testhypothesescompact_h_
|
199
modules/gpu/test/nvidia/TestDrawRects.cpp
Normal file
199
modules/gpu/test/nvidia/TestDrawRects.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestDrawRects.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestDrawRects<T>::TestDrawRects(std::string testName_, NCVTestSourceProvider<T> &src_,
|
||||
NCVTestSourceProvider<Ncv32u> &src32u_,
|
||||
Ncv32u width_, Ncv32u height_, Ncv32u numRects_, T color_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
src32u(src32u_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
numRects(numRects_),
|
||||
color(color_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
strOut << "numRects=" << numRects << std::endl;
|
||||
strOut << "color=" << color << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img_d(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img_d.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> d_rects(*this->allocatorGPU.get(), this->numRects);
|
||||
ncvAssertReturn(d_rects.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_rects(*this->allocatorCPU.get(), this->numRects);
|
||||
ncvAssertReturn(h_rects.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
//fill vector of rectangles with random rects covering the input
|
||||
NCVVectorReuse<Ncv32u> h_rects_as32u(h_rects.getSegment());
|
||||
ncvAssertReturn(h_rects_as32u.isMemReused(), false);
|
||||
ncvAssertReturn(this->src32u.fill(h_rects_as32u), false);
|
||||
for (Ncv32u i=0; i<this->numRects; i++)
|
||||
{
|
||||
h_rects.ptr()[i].x = (Ncv32u)(((1.0 * h_rects.ptr()[i].x) / RAND_MAX) * (this->width-2));
|
||||
h_rects.ptr()[i].y = (Ncv32u)(((1.0 * h_rects.ptr()[i].y) / RAND_MAX) * (this->height-2));
|
||||
h_rects.ptr()[i].width = (Ncv32u)(((1.0 * h_rects.ptr()[i].width) / RAND_MAX) * (this->width+10 - h_rects.ptr()[i].x));
|
||||
h_rects.ptr()[i].height = (Ncv32u)(((1.0 * h_rects.ptr()[i].height) / RAND_MAX) * (this->height+10 - h_rects.ptr()[i].y));
|
||||
}
|
||||
ncvStat = h_rects.copySolid(d_rects, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_32u_device((Ncv32u *)d_img.ptr(), d_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)d_rects.ptr(), this->numRects, this->color, 0);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_8u_device((Ncv8u *)d_img.ptr(), d_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)d_rects.ptr(), this->numRects, (Ncv8u)this->color, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect drawrects test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = d_img.copySolid(h_img_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_32u_host((Ncv32u *)h_img.ptr(), h_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)h_rects.ptr(), this->numRects, this->color);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_8u_host((Ncv8u *)h_img.ptr(), h_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)h_rects.ptr(), this->numRects, (Ncv8u)this->color);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect drawrects test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width(); j++)
|
||||
{
|
||||
if (h_img.ptr()[h_img.stride()*i+j] != h_img_d.ptr()[h_img_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestDrawRects<Ncv8u>;
|
||||
template class TestDrawRects<Ncv32u>;
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
76
modules/gpu/test/nvidia/TestDrawRects.h
Normal file
76
modules/gpu/test/nvidia/TestDrawRects.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testdrawrects_h_
|
||||
#define _testdrawrects_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
class TestDrawRects : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestDrawRects(std::string testName, NCVTestSourceProvider<T> &src, NCVTestSourceProvider<Ncv32u> &src32u,
|
||||
Ncv32u width, Ncv32u height, Ncv32u numRects, T color);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestDrawRects(const TestDrawRects&);
|
||||
TestDrawRects& operator=(const TestDrawRects&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
NCVTestSourceProvider<Ncv32u> &src32u;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
Ncv32u numRects;
|
||||
T color;
|
||||
};
|
||||
|
||||
#endif // _testdrawrects_h_
|
347
modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp
Normal file
347
modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp
Normal file
@@ -0,0 +1,347 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__arm__)
|
||||
#include <fpu_control.h>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
// http://www.christian-seiler.de/projekte/fpmath/
|
||||
class FpuControl
|
||||
{
|
||||
public:
|
||||
FpuControl();
|
||||
~FpuControl();
|
||||
|
||||
private:
|
||||
#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__arm__)
|
||||
fpu_control_t fpu_oldcw, fpu_cw;
|
||||
#elif defined(_WIN32) && !defined(_WIN64)
|
||||
unsigned int fpu_oldcw, fpu_cw;
|
||||
#endif
|
||||
};
|
||||
|
||||
FpuControl::FpuControl()
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__arm__)
|
||||
_FPU_GETCW(fpu_oldcw);
|
||||
fpu_cw = (fpu_oldcw & ~_FPU_EXTENDED & ~_FPU_DOUBLE & ~_FPU_SINGLE) | _FPU_SINGLE;
|
||||
_FPU_SETCW(fpu_cw);
|
||||
#elif defined(_WIN32) && !defined(_WIN64)
|
||||
_controlfp_s(&fpu_cw, 0, 0);
|
||||
fpu_oldcw = fpu_cw;
|
||||
_controlfp_s(&fpu_cw, _PC_24, _MCW_PC);
|
||||
#endif
|
||||
}
|
||||
|
||||
FpuControl::~FpuControl()
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__arm__)
|
||||
_FPU_SETCW(fpu_oldcw);
|
||||
#elif defined(_WIN32) && !defined(_WIN64)
|
||||
_controlfp_s(&fpu_cw, fpu_oldcw, _MCW_PC);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#include "TestHaarCascadeApplication.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHaarCascadeApplication::TestHaarCascadeApplication(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_,
|
||||
std::string cascadeName_, Ncv32u width_, Ncv32u height_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
cascadeName(cascadeName_),
|
||||
width(width_),
|
||||
height(height_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "cascadeName=" << cascadeName << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestHaarCascadeApplication::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u numStages, numNodes, numFeatures;
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> d_HaarStages(*this->allocatorGPU.get(), numStages);
|
||||
ncvAssertReturn(d_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> d_HaarNodes(*this->allocatorGPU.get(), numNodes);
|
||||
ncvAssertReturn(d_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> d_HaarFeatures(*this->allocatorGPU.get(), numFeatures);
|
||||
ncvAssertReturn(d_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
HaarClassifierCascadeDescriptor haar;
|
||||
haar.ClassifierSize.width = haar.ClassifierSize.height = 1;
|
||||
haar.bNeedsTiltedII = false;
|
||||
haar.NumClassifierRootNodes = numNodes;
|
||||
haar.NumClassifierTotalNodes = numNodes;
|
||||
haar.NumFeatures = numFeatures;
|
||||
haar.NumStages = numStages;
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarStages.copySolid(d_HaarStages, 0), false);
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarNodes.copySolid(d_HaarNodes, 0), false);
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarFeatures.copySolid(d_HaarFeatures, 0), false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
NcvSize32s srcRoi, srcIIRoi, searchRoi;
|
||||
srcRoi.width = this->width;
|
||||
srcRoi.height = this->height;
|
||||
srcIIRoi.width = srcRoi.width + 1;
|
||||
srcIIRoi.height = srcRoi.height + 1;
|
||||
searchRoi.width = srcIIRoi.width - haar.ClassifierSize.width;
|
||||
searchRoi.height = srcIIRoi.height - haar.ClassifierSize.height;
|
||||
if (searchRoi.width <= 0 || searchRoi.height <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
NcvSize32u searchRoiU(searchRoi.width, searchRoi.height);
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
Ncv32u integralWidth = this->width + 1;
|
||||
Ncv32u integralHeight = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> d_integralImage(*this->allocatorGPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(d_integralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> d_sqIntegralImage(*this->allocatorGPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(d_sqIntegralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_integralImage(*this->allocatorCPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(h_integralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_sqIntegralImage(*this->allocatorCPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(h_sqIntegralImage.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32f> d_rectStdDev(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_rectStdDev.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> d_pixelMask(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_pixelMask.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_rectStdDev(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_rectStdDev.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_pixelMask(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_pixelMask.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> d_hypotheses(*this->allocatorGPU.get(), this->width * this->height);
|
||||
ncvAssertReturn(d_hypotheses.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_hypotheses(*this->allocatorCPU.get(), this->width * this->height);
|
||||
ncvAssertReturn(h_hypotheses.isMemAllocated(), false);
|
||||
|
||||
NCVStatus nppStat;
|
||||
Ncv32u szTmpBufIntegral, szTmpBufSqIntegral;
|
||||
nppStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &szTmpBufIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
nppStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &szTmpBufSqIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpIIbuf(*this->allocatorGPU.get(), std::max(szTmpBufIntegral, szTmpBufSqIntegral));
|
||||
ncvAssertReturn(d_tmpIIbuf.isMemAllocated(), false);
|
||||
|
||||
Ncv32u detectionsOnThisScale_d = 0;
|
||||
Ncv32u detectionsOnThisScale_h = 0;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
nppStat = nppiStIntegral_8u32u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_integralImage.ptr(), d_integralImage.pitch(),
|
||||
NcvSize32u(d_img.width(), d_img.height()),
|
||||
d_tmpIIbuf.ptr(), szTmpBufIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
nppStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_sqIntegralImage.ptr(), d_sqIntegralImage.pitch(),
|
||||
NcvSize32u(d_img.width(), d_img.height()),
|
||||
d_tmpIIbuf.ptr(), szTmpBufSqIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
const NcvRect32u rect(
|
||||
HAAR_STDDEV_BORDER,
|
||||
HAAR_STDDEV_BORDER,
|
||||
haar.ClassifierSize.width - 2*HAAR_STDDEV_BORDER,
|
||||
haar.ClassifierSize.height - 2*HAAR_STDDEV_BORDER);
|
||||
nppStat = nppiStRectStdDev_32f_C1R(
|
||||
d_integralImage.ptr(), d_integralImage.pitch(),
|
||||
d_sqIntegralImage.ptr(), d_sqIntegralImage.pitch(),
|
||||
d_rectStdDev.ptr(), d_rectStdDev.pitch(),
|
||||
NcvSize32u(searchRoi.width, searchRoi.height), rect,
|
||||
1.0f, true);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_integralImage.copySolid(h_integralImage, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = d_rectStdDev.copySolid(h_rectStdDev, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
for (Ncv32u i=0; i<searchRoiU.height; i++)
|
||||
{
|
||||
for (Ncv32u j=0; j<h_pixelMask.stride(); j++)
|
||||
{
|
||||
if (j<searchRoiU.width)
|
||||
{
|
||||
h_pixelMask.ptr()[i*h_pixelMask.stride()+j] = (i << 16) | j;
|
||||
}
|
||||
else
|
||||
{
|
||||
h_pixelMask.ptr()[i*h_pixelMask.stride()+j] = OBJDET_MASK_ELEMENT_INVALID_32U;
|
||||
}
|
||||
}
|
||||
}
|
||||
ncvAssertReturn(cudaSuccess == cudaStreamSynchronize(0), false);
|
||||
|
||||
{
|
||||
// calculations here
|
||||
FpuControl fpu;
|
||||
(void) fpu;
|
||||
|
||||
ncvStat = ncvApplyHaarClassifierCascade_host(
|
||||
h_integralImage, h_rectStdDev, h_pixelMask,
|
||||
detectionsOnThisScale_h,
|
||||
haar, h_HaarStages, h_HaarNodes, h_HaarFeatures, false,
|
||||
searchRoiU, 1, 1.0f);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
}
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
int devId;
|
||||
ncvAssertCUDAReturn(cudaGetDevice(&devId), false);
|
||||
cudaDeviceProp _devProp;
|
||||
ncvAssertCUDAReturn(cudaGetDeviceProperties(&_devProp, devId), false);
|
||||
|
||||
ncvStat = ncvApplyHaarClassifierCascade_device(
|
||||
d_integralImage, d_rectStdDev, d_pixelMask,
|
||||
detectionsOnThisScale_d,
|
||||
haar, h_HaarStages, d_HaarStages, d_HaarNodes, d_HaarFeatures, false,
|
||||
searchRoiU, 1, 1.0f,
|
||||
*this->allocatorGPU.get(), *this->allocatorCPU.get(),
|
||||
_devProp, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> h_pixelMask_d(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_pixelMask_d.isMemAllocated(), false);
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvStat = d_pixelMask.copySolid(h_pixelMask_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
if (detectionsOnThisScale_d != detectionsOnThisScale_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::sort(h_pixelMask_d.ptr(), h_pixelMask_d.ptr() + detectionsOnThisScale_d);
|
||||
for (Ncv32u i=0; i<detectionsOnThisScale_d && bLoopVirgin; i++)
|
||||
{
|
||||
if (h_pixelMask.ptr()[i] != h_pixelMask_d.ptr()[i])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
73
modules/gpu/test/nvidia/TestHaarCascadeApplication.h
Normal file
73
modules/gpu/test/nvidia/TestHaarCascadeApplication.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testhaarcascadeapplication_h_
|
||||
#define _testhaarcascadeapplication_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHaarCascadeApplication : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHaarCascadeApplication(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
std::string cascadeName, Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestHaarCascadeApplication(const TestHaarCascadeApplication&);
|
||||
TestHaarCascadeApplication& operator=(const TestHaarCascadeApplication&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
std::string cascadeName;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testhaarcascadeapplication_h_
|
158
modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp
Normal file
158
modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestHaarCascadeLoader.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHaarCascadeLoader::TestHaarCascadeLoader(std::string testName_, std::string cascadeName_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
cascadeName(cascadeName_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "cascadeName=" << cascadeName << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u numStages, numNodes, numFeatures;
|
||||
Ncv32u numStages_2 = 0, numNodes_2 = 0, numFeatures_2 = 0;
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages_2(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages_2.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes_2(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes_2.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures_2(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures_2.isMemAllocated(), false);
|
||||
|
||||
HaarClassifierCascadeDescriptor haar;
|
||||
HaarClassifierCascadeDescriptor haar_2;
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
const std::string testNvbinName = "test.nvbin";
|
||||
ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarStoreNVBIN_host(testNvbinName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(testNvbinName, numStages_2, numNodes_2, numFeatures_2);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarLoadFromFile_host(testNvbinName, haar_2, h_HaarStages_2, h_HaarNodes_2, h_HaarFeatures_2);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
if (
|
||||
numStages_2 != numStages ||
|
||||
numNodes_2 != numNodes ||
|
||||
numFeatures_2 != numFeatures ||
|
||||
haar.NumStages != haar_2.NumStages ||
|
||||
haar.NumClassifierRootNodes != haar_2.NumClassifierRootNodes ||
|
||||
haar.NumClassifierTotalNodes != haar_2.NumClassifierTotalNodes ||
|
||||
haar.NumFeatures != haar_2.NumFeatures ||
|
||||
haar.ClassifierSize.width != haar_2.ClassifierSize.width ||
|
||||
haar.ClassifierSize.height != haar_2.ClassifierSize.height ||
|
||||
haar.bNeedsTiltedII != haar_2.bNeedsTiltedII ||
|
||||
haar.bHasStumpsOnly != haar_2.bHasStumpsOnly )
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
if (memcmp(h_HaarStages.ptr(), h_HaarStages_2.ptr(), haar.NumStages * sizeof(HaarStage64)) ||
|
||||
memcmp(h_HaarNodes.ptr(), h_HaarNodes_2.ptr(), haar.NumClassifierTotalNodes * sizeof(HaarClassifierNode128)) ||
|
||||
memcmp(h_HaarFeatures.ptr(), h_HaarFeatures_2.ptr(), haar.NumFeatures * sizeof(HaarFeature64)) )
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
@@ -40,6 +40,27 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#ifndef _testhaarcascadeloader_h_
|
||||
#define _testhaarcascadeloader_h_
|
||||
|
||||
CV_GPU_TEST_MAIN("gpu")
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHaarCascadeLoader : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHaarCascadeLoader(std::string testName, std::string cascadeName);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
std::string cascadeName;
|
||||
};
|
||||
|
||||
#endif // _testhaarcascadeloader_h_
|
211
modules/gpu/test/nvidia/TestHypothesesFilter.cpp
Normal file
211
modules/gpu/test/nvidia/TestHypothesesFilter.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestHypothesesFilter.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHypothesesFilter::TestHypothesesFilter(std::string testName_, NCVTestSourceProvider<Ncv32u> &src_,
|
||||
Ncv32u numDstRects_, Ncv32u minNeighbors_, Ncv32f eps_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
numDstRects(numDstRects_),
|
||||
minNeighbors(minNeighbors_),
|
||||
eps(eps_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "numDstRects=" << numDstRects << std::endl;
|
||||
strOut << "minNeighbors=" << minNeighbors << std::endl;
|
||||
strOut << "eps=" << eps << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::init()
|
||||
{
|
||||
this->canvasWidth = 4096;
|
||||
this->canvasHeight = 4096;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool compareRects(const NcvRect32u &r1, const NcvRect32u &r2, Ncv32f eps)
|
||||
{
|
||||
double delta = eps*(std::min(r1.width, r2.width) + std::min(r1.height, r2.height))*0.5;
|
||||
return std::abs((Ncv32s)r1.x - (Ncv32s)r2.x) <= delta &&
|
||||
std::abs((Ncv32s)r1.y - (Ncv32s)r2.y) <= delta &&
|
||||
std::abs((Ncv32s)r1.x + (Ncv32s)r1.width - (Ncv32s)r2.x - (Ncv32s)r2.width) <= delta &&
|
||||
std::abs((Ncv32s)r1.y + (Ncv32s)r1.height - (Ncv32s)r2.y - (Ncv32s)r2.height) <= delta;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator < (const NcvRect32u &a, const NcvRect32u &b)
|
||||
{
|
||||
return a.x < b.x;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_random32u(*this->allocatorCPU.get(), this->numDstRects * sizeof(NcvRect32u) / sizeof(Ncv32u));
|
||||
ncvAssertReturn(h_random32u.isMemAllocated(), false);
|
||||
|
||||
Ncv32u srcSlotSize = 2 * this->minNeighbors + 1;
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> h_vecSrc(*this->allocatorCPU.get(), this->numDstRects*srcSlotSize);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst_groundTruth(*this->allocatorCPU.get(), this->numDstRects);
|
||||
ncvAssertReturn(h_vecDst_groundTruth.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorCPU.get()->isCounting());
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_random32u), false);
|
||||
Ncv32u randCnt = 0;
|
||||
Ncv64f randVal;
|
||||
|
||||
for (Ncv32u i=0; i<this->numDstRects; i++)
|
||||
{
|
||||
h_vecDst_groundTruth.ptr()[i].x = i * this->canvasWidth / this->numDstRects + this->canvasWidth / (this->numDstRects * 4);
|
||||
h_vecDst_groundTruth.ptr()[i].y = i * this->canvasHeight / this->numDstRects + this->canvasHeight / (this->numDstRects * 4);
|
||||
h_vecDst_groundTruth.ptr()[i].width = this->canvasWidth / (this->numDstRects * 2);
|
||||
h_vecDst_groundTruth.ptr()[i].height = this->canvasHeight / (this->numDstRects * 2);
|
||||
|
||||
Ncv32u numNeighbors = this->minNeighbors + 1 + (Ncv32u)(((1.0 * h_random32u.ptr()[i]) * (this->minNeighbors + 1)) / 0xFFFFFFFF);
|
||||
numNeighbors = (numNeighbors > srcSlotSize) ? srcSlotSize : numNeighbors;
|
||||
|
||||
//fill in strong hypotheses (2 * ((1.0 * randVal) / 0xFFFFFFFF) - 1)
|
||||
for (Ncv32u j=0; j<numNeighbors; j++)
|
||||
{
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].x =
|
||||
h_vecDst_groundTruth.ptr()[i].x +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].width * this->eps * (randVal - 0.5));
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].y =
|
||||
h_vecDst_groundTruth.ptr()[i].y +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].height * this->eps * (randVal - 0.5));
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].width = h_vecDst_groundTruth.ptr()[i].width;
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].height = h_vecDst_groundTruth.ptr()[i].height;
|
||||
}
|
||||
|
||||
//generate weak hypotheses (to be removed in processing)
|
||||
for (Ncv32u j=numNeighbors; j<srcSlotSize; j++)
|
||||
{
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].x =
|
||||
this->canvasWidth + h_vecDst_groundTruth.ptr()[i].x +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].width * this->eps * (randVal - 0.5));
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].y =
|
||||
this->canvasHeight + h_vecDst_groundTruth.ptr()[i].y +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].height * this->eps * (randVal - 0.5));
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].width = h_vecDst_groundTruth.ptr()[i].width;
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].height = h_vecDst_groundTruth.ptr()[i].height;
|
||||
}
|
||||
}
|
||||
|
||||
//shuffle
|
||||
for (Ncv32u i=0; i<this->numDstRects*srcSlotSize-1; i++)
|
||||
{
|
||||
Ncv32u randValLocal = h_random32u.ptr()[randCnt++]; randCnt = randCnt % h_random32u.length();
|
||||
Ncv32u secondSwap = randValLocal % (this->numDstRects*srcSlotSize-1 - i);
|
||||
NcvRect32u tmp = h_vecSrc.ptr()[i + secondSwap];
|
||||
h_vecSrc.ptr()[i + secondSwap] = h_vecSrc.ptr()[i];
|
||||
h_vecSrc.ptr()[i] = tmp;
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
Ncv32u numHypothesesSrc = static_cast<Ncv32u>(h_vecSrc.length());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvStat = ncvGroupRectangles_host(h_vecSrc, numHypothesesSrc, this->minNeighbors, this->eps, NULL);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//verification
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (numHypothesesSrc != this->numDstRects)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<NcvRect32u> tmpRects(numHypothesesSrc);
|
||||
memcpy(&tmpRects[0], h_vecSrc.ptr(), numHypothesesSrc * sizeof(NcvRect32u));
|
||||
std::sort(tmpRects.begin(), tmpRects.end());
|
||||
for (Ncv32u i=0; i<numHypothesesSrc && bLoopVirgin; i++)
|
||||
{
|
||||
if (!compareRects(tmpRects[i], h_vecDst_groundTruth.ptr()[i], this->eps))
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
76
modules/gpu/test/nvidia/TestHypothesesFilter.h
Normal file
76
modules/gpu/test/nvidia/TestHypothesesFilter.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testhypothesesfilter_h_
|
||||
#define _testhypothesesfilter_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHypothesesFilter : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHypothesesFilter(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u numDstRects, Ncv32u minNeighbors, Ncv32f eps);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestHypothesesFilter(const TestHypothesesFilter&);
|
||||
TestHypothesesFilter& operator=(const TestHypothesesFilter&);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u numDstRects;
|
||||
Ncv32u minNeighbors;
|
||||
Ncv32f eps;
|
||||
|
||||
Ncv32u canvasWidth;
|
||||
Ncv32u canvasHeight;
|
||||
};
|
||||
|
||||
#endif // _testhypothesesfilter_h_
|
169
modules/gpu/test/nvidia/TestHypothesesGrow.cpp
Normal file
169
modules/gpu/test/nvidia/TestHypothesesGrow.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestHypothesesGrow.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHypothesesGrow::TestHypothesesGrow(std::string testName_, NCVTestSourceProvider<Ncv32u> &src_,
|
||||
Ncv32u rectWidth_, Ncv32u rectHeight_, Ncv32f rectScale_,
|
||||
Ncv32u maxLenSrc_, Ncv32u lenSrc_, Ncv32u maxLenDst_, Ncv32u lenDst_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
rectWidth(rectWidth_),
|
||||
rectHeight(rectHeight_),
|
||||
rectScale(rectScale_),
|
||||
maxLenSrc(maxLenSrc_),
|
||||
lenSrc(lenSrc_),
|
||||
maxLenDst(maxLenDst_),
|
||||
lenDst(lenDst_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "rectWidth=" << rectWidth << std::endl;
|
||||
strOut << "rectHeight=" << rectHeight << std::endl;
|
||||
strOut << "rectScale=" << rectScale << std::endl;
|
||||
strOut << "maxLenSrc=" << maxLenSrc << std::endl;
|
||||
strOut << "lenSrc=" << lenSrc << std::endl;
|
||||
strOut << "maxLenDst=" << maxLenDst << std::endl;
|
||||
strOut << "lenDst=" << lenDst << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->maxLenSrc);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->maxLenSrc);
|
||||
ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst(*this->allocatorCPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(h_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> d_vecDst(*this->allocatorGPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(d_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst_d(*this->allocatorCPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_vecSrc), false);
|
||||
memset(h_vecDst.ptr(), 0, h_vecDst.length() * sizeof(NcvRect32u));
|
||||
NCVVectorReuse<Ncv32u> h_vecDst_as32u(h_vecDst.getSegment(), lenDst * sizeof(NcvRect32u) / sizeof(Ncv32u));
|
||||
ncvAssertReturn(h_vecDst_as32u.isMemReused(), false);
|
||||
ncvAssertReturn(this->src.fill(h_vecDst_as32u), false);
|
||||
memcpy(h_vecDst_d.ptr(), h_vecDst.ptr(), h_vecDst.length() * sizeof(NcvRect32u));
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = h_vecDst.copySolid(d_vecDst, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
Ncv32u h_outElemNum_d = 0;
|
||||
Ncv32u h_outElemNum_h = 0;
|
||||
NCV_SKIP_COND_BEGIN
|
||||
h_outElemNum_d = this->lenDst;
|
||||
ncvStat = ncvGrowDetectionsVector_device(d_vecSrc, this->lenSrc,
|
||||
d_vecDst, h_outElemNum_d, this->maxLenDst,
|
||||
this->rectWidth, this->rectHeight, this->rectScale, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
h_outElemNum_h = this->lenDst;
|
||||
ncvStat = ncvGrowDetectionsVector_host(h_vecSrc, this->lenSrc,
|
||||
h_vecDst, h_outElemNum_h, this->maxLenDst,
|
||||
this->rectWidth, this->rectHeight, this->rectScale);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (h_outElemNum_d != h_outElemNum_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (memcmp(h_vecDst.ptr(), h_vecDst_d.ptr(), this->maxLenDst * sizeof(NcvRect32u)))
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
78
modules/gpu/test/nvidia/TestHypothesesGrow.h
Normal file
78
modules/gpu/test/nvidia/TestHypothesesGrow.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testhypothesesgrow_h_
|
||||
#define _testhypothesesgrow_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHypothesesGrow : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHypothesesGrow(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u rectWidth, Ncv32u rectHeight, Ncv32f rectScale,
|
||||
Ncv32u maxLenSrc, Ncv32u lenSrc, Ncv32u maxLenDst, Ncv32u lenDst);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestHypothesesGrow(const TestHypothesesGrow&);
|
||||
TestHypothesesGrow& operator=(const TestHypothesesGrow&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u rectWidth;
|
||||
Ncv32u rectHeight;
|
||||
Ncv32f rectScale;
|
||||
Ncv32u maxLenSrc;
|
||||
Ncv32u lenSrc;
|
||||
Ncv32u maxLenDst;
|
||||
Ncv32u lenDst;
|
||||
};
|
||||
|
||||
#endif // _testhypothesesgrow_h_
|
220
modules/gpu/test/nvidia/TestIntegralImage.cpp
Normal file
220
modules/gpu/test/nvidia/TestIntegralImage.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <math.h>
|
||||
#include "TestIntegralImage.h"
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
TestIntegralImage<T_in, T_out>::TestIntegralImage(std::string testName_, NCVTestSourceProvider<T_in> &src_,
|
||||
Ncv32u width_, Ncv32u height_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
width(width_),
|
||||
height(height_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T_in)=" << sizeof(T_in) << std::endl;
|
||||
strOut << "sizeof(T_out)=" << sizeof(T_out) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u widthII = this->width + 1;
|
||||
Ncv32u heightII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<T_in> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_in> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(d_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> h_imgII_d(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSize;
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegralGetSize_32f32f(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegral_8u32u_C1R((Ncv8u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegral_32f32f_C1R((Ncv32f *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32f *)d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
ncvStat = d_imgII.copySolid(h_imgII_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegral_8u32u_C1R_host((Ncv8u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegral_32f32f_C1R_host((Ncv32f *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32f *)h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++)
|
||||
{
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
if (h_imgII.ptr()[h_imgII.stride()*i+j] != h_imgII_d.ptr()[h_imgII_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
if (fabsf((float)h_imgII.ptr()[h_imgII.stride()*i+j] - (float)h_imgII_d.ptr()[h_imgII_d.stride()*i+j]) > 0.01f)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestIntegralImage<Ncv8u, Ncv32u>;
|
||||
template class TestIntegralImage<Ncv32f, Ncv32f>;
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
72
modules/gpu/test/nvidia/TestIntegralImage.h
Normal file
72
modules/gpu/test/nvidia/TestIntegralImage.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testintegralimage_h_
|
||||
#define _testintegralimage_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
class TestIntegralImage : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestIntegralImage(std::string testName, NCVTestSourceProvider<T_in> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestIntegralImage(const TestIntegralImage&);
|
||||
TestIntegralImage& operator=(const TestIntegralImage&);
|
||||
|
||||
NCVTestSourceProvider<T_in> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testintegralimage_h_
|
152
modules/gpu/test/nvidia/TestIntegralImageSquared.cpp
Normal file
152
modules/gpu/test/nvidia/TestIntegralImageSquared.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "TestIntegralImageSquared.h"
|
||||
|
||||
|
||||
TestIntegralImageSquared::TestIntegralImageSquared(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_,
|
||||
Ncv32u width_, Ncv32u height_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
width(width_),
|
||||
height(height_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u widthSII = this->width + 1;
|
||||
Ncv32u heightSII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(d_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII_d(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSize;
|
||||
ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_imgSII.copySolid(h_imgSII_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++)
|
||||
{
|
||||
if (h_imgSII.ptr()[h_imgSII.stride()*i+j] != h_imgSII_d.ptr()[h_imgSII_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
71
modules/gpu/test/nvidia/TestIntegralImageSquared.h
Normal file
71
modules/gpu/test/nvidia/TestIntegralImageSquared.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testintegralimagesquared_h_
|
||||
#define _testintegralimagesquared_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestIntegralImageSquared : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestIntegralImageSquared(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestIntegralImageSquared(const TestIntegralImageSquared&);
|
||||
TestIntegralImageSquared& operator=(const TestIntegralImageSquared&);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testintegralimagesquared_h_
|
215
modules/gpu/test/nvidia/TestRectStdDev.cpp
Normal file
215
modules/gpu/test/nvidia/TestRectStdDev.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestRectStdDev.h"
|
||||
|
||||
|
||||
TestRectStdDev::TestRectStdDev(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_,
|
||||
Ncv32u width_, Ncv32u height_, NcvRect32u rect_, Ncv32f scaleFactor_,
|
||||
NcvBool bTextureCache_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
rect(rect_),
|
||||
scaleFactor(scaleFactor_),
|
||||
bTextureCache(bTextureCache_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
strOut << "rect=[" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << "]\n";
|
||||
strOut << "scaleFactor=" << scaleFactor << std::endl;
|
||||
strOut << "bTextureCache=" << bTextureCache << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32s _normWidth = (Ncv32s)this->width - this->rect.x - this->rect.width + 1;
|
||||
Ncv32s _normHeight = (Ncv32s)this->height - this->rect.y - this->rect.height + 1;
|
||||
if (_normWidth <= 0 || _normHeight <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Ncv32u normWidth = (Ncv32u)_normWidth;
|
||||
Ncv32u normHeight = (Ncv32u)_normHeight;
|
||||
NcvSize32u szNormRoi(normWidth, normHeight);
|
||||
|
||||
Ncv32u widthII = this->width + 1;
|
||||
Ncv32u heightII = this->height + 1;
|
||||
Ncv32u widthSII = this->width + 1;
|
||||
Ncv32u heightSII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(d_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(d_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32f> d_norm(*this->allocatorGPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(d_norm.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_norm(*this->allocatorCPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(h_norm.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_norm_d(*this->allocatorCPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(h_norm_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSizeII, bufSizeSII;
|
||||
ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSizeII, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSizeSII, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
Ncv32u bufSize = bufSizeII > bufSizeSII ? bufSizeII : bufSizeSII;
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStIntegral_8u32u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStRectStdDev_32f_C1R(d_imgII.ptr(), d_imgII.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
d_norm.ptr(), d_norm.pitch(),
|
||||
szNormRoi, this->rect,
|
||||
this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_norm.copySolid(h_norm_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStIntegral_8u32u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStRectStdDev_32f_C1R_host(h_imgII.ptr(), h_imgII.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
h_norm.ptr(), h_norm.pitch(),
|
||||
szNormRoi, this->rect,
|
||||
this->scaleFactor);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_norm.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_norm.width(); j++)
|
||||
{
|
||||
Ncv64f absErr = fabs(h_norm.ptr()[h_norm.stride()*i+j] - h_norm_d.ptr()[h_norm_d.stride()*i+j]);
|
||||
Ncv64f relErr = absErr / h_norm.ptr()[h_norm.stride()*i+j];
|
||||
|
||||
if (relErr > relEPS)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
76
modules/gpu/test/nvidia/TestRectStdDev.h
Normal file
76
modules/gpu/test/nvidia/TestRectStdDev.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testrectstddev_h_
|
||||
#define _testrectstddev_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestRectStdDev : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestRectStdDev(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height, NcvRect32u rect, Ncv32f scaleFactor,
|
||||
NcvBool bTextureCache);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestRectStdDev(const TestRectStdDev&);
|
||||
TestRectStdDev& operator=(const TestRectStdDev&);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
NcvRect32u rect;
|
||||
Ncv32f scaleFactor;
|
||||
|
||||
NcvBool bTextureCache;
|
||||
};
|
||||
|
||||
#endif // _testrectstddev_h_
|
196
modules/gpu/test/nvidia/TestResize.cpp
Normal file
196
modules/gpu/test/nvidia/TestResize.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestResize.h"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestResize<T>::TestResize(std::string testName_, NCVTestSourceProvider<T> &src_,
|
||||
Ncv32u width_, Ncv32u height_, Ncv32u scaleFactor_, NcvBool bTextureCache_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
width(width_),
|
||||
height(height_),
|
||||
scaleFactor(scaleFactor_),
|
||||
bTextureCache(bTextureCache_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "scaleFactor=" << scaleFactor << std::endl;
|
||||
strOut << "bTextureCache=" << bTextureCache << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32s smallWidth = this->width / this->scaleFactor;
|
||||
Ncv32s smallHeight = this->height / this->scaleFactor;
|
||||
if (smallWidth == 0 || smallHeight == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
NcvSize32u srcSize(this->width, this->height);
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<T> d_small(*this->allocatorGPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(d_small.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_small(*this->allocatorCPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(h_small.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_small_d(*this->allocatorCPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(h_small_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStDecimate_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_small.ptr(), d_small.pitch(),
|
||||
srcSize, this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStDecimate_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv64u *)d_small.ptr(), d_small.pitch(),
|
||||
srcSize, this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
ncvStat = d_small.copySolid(h_small_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStDecimate_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_small.ptr(), h_small.pitch(),
|
||||
srcSize, this->scaleFactor);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStDecimate_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv64u *)h_small.ptr(), h_small.pitch(),
|
||||
srcSize, this->scaleFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_small.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_small.width(); j++)
|
||||
{
|
||||
if (h_small.ptr()[h_small.stride()*i+j] != h_small_d.ptr()[h_small_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestResize<Ncv32u>;
|
||||
template class TestResize<Ncv64u>;
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
74
modules/gpu/test/nvidia/TestResize.h
Normal file
74
modules/gpu/test/nvidia/TestResize.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testresize_h_
|
||||
#define _testresize_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
template <class T>
|
||||
class TestResize : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestResize(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height, Ncv32u scaleFactor, NcvBool bTextureCache);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestResize(const TestResize&);
|
||||
TestResize& operator=(const TestResize&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
Ncv32u scaleFactor;
|
||||
|
||||
NcvBool bTextureCache;
|
||||
};
|
||||
|
||||
#endif // _testresize_h_
|
183
modules/gpu/test/nvidia/TestTranspose.cpp
Normal file
183
modules/gpu/test/nvidia/TestTranspose.cpp
Normal 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.
|
||||
// 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*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestTranspose.h"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestTranspose<T>::TestTranspose(std::string testName_, NCVTestSourceProvider<T> &src_,
|
||||
Ncv32u width_, Ncv32u height_)
|
||||
:
|
||||
NCVTestProvider(testName_),
|
||||
src(src_),
|
||||
width(width_),
|
||||
height(height_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NcvSize32u srcSize(this->width, this->height);
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<T> d_dst(*this->allocatorGPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(d_dst.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_dst(*this->allocatorCPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(h_dst.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_dst_d(*this->allocatorCPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(h_dst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_dst.ptr(), d_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv64u *)d_dst.ptr(), d_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect transpose test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
ncvStat = d_dst.copySolid(h_dst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_dst.ptr(), h_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv64u *)h_dst.ptr(), h_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < this->width; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < this->height; j++)
|
||||
{
|
||||
if (h_dst.ptr()[h_dst.stride()*i+j] != h_dst_d.ptr()[h_dst_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestTranspose<Ncv32u>;
|
||||
template class TestTranspose<Ncv64u>;
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
73
modules/gpu/test/nvidia/TestTranspose.h
Normal file
73
modules/gpu/test/nvidia/TestTranspose.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _testtranspose_h_
|
||||
#define _testtranspose_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
class TestTranspose : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestTranspose(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestTranspose(const TestTranspose&);
|
||||
TestTranspose& operator=(const TestTranspose&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testtranspose_h_
|
484
modules/gpu/test/nvidia/main_nvidia.cpp
Normal file
484
modules/gpu/test/nvidia/main_nvidia.cpp
Normal file
@@ -0,0 +1,484 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
# pragma warning (disable : 4408 4201 4100)
|
||||
#endif
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "NCV.hpp"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
#include "TestIntegralImage.h"
|
||||
#include "TestIntegralImageSquared.h"
|
||||
#include "TestRectStdDev.h"
|
||||
#include "TestResize.h"
|
||||
#include "TestCompact.h"
|
||||
#include "TestTranspose.h"
|
||||
|
||||
#include "TestDrawRects.h"
|
||||
#include "TestHypothesesGrow.h"
|
||||
#include "TestHypothesesFilter.h"
|
||||
#include "TestHaarCascadeLoader.h"
|
||||
#include "TestHaarCascadeApplication.h"
|
||||
|
||||
#include "NCVAutoTestLister.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
#include "main_test_nvidia.h"
|
||||
|
||||
static std::string path;
|
||||
|
||||
namespace {
|
||||
|
||||
template <class T_in, class T_out>
|
||||
void generateIntegralTests(NCVAutoTestLister &testLister,
|
||||
NCVTestSourceProvider<T_in> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "LinIntImgW%dH%d", i, 2);
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, i, 2));
|
||||
}
|
||||
for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "LinIntImgW%dH%d", 2, i);
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, 2, i));
|
||||
}
|
||||
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>("LinIntImg_VGA", src, 640, 480));
|
||||
}
|
||||
|
||||
void generateSquaredIntegralTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "SqIntImgW%dH%d", i, 32);
|
||||
testLister.add(new TestIntegralImageSquared(testName, src, i, 32));
|
||||
}
|
||||
for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "SqIntImgW%dH%d", 32, i);
|
||||
testLister.add(new TestIntegralImageSquared(testName, src, 32, i));
|
||||
}
|
||||
|
||||
testLister.add(new TestIntegralImageSquared("SqLinIntImg_VGA", src, 640, 480));
|
||||
}
|
||||
|
||||
void generateRectStdDevTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
NcvRect32u rect(1,1,18,18);
|
||||
|
||||
for (Ncv32f _i=32; _i<maxHeight/2 && _i < maxWidth/2; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "RectStdDevW%dH%d", i*2, i);
|
||||
testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1, true));
|
||||
testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1.5, false));
|
||||
testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 1, false));
|
||||
testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 2.5, true));
|
||||
}
|
||||
|
||||
testLister.add(new TestRectStdDev("RectStdDev_VGA", src, 640, 480, rect, 1, true));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void generateResizeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
|
||||
{
|
||||
for (Ncv32u i=2; i<10; ++i)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestResize_VGA_s%d", i);
|
||||
testLister.add(new TestResize<T>(testName, src, 640, 480, i, true));
|
||||
testLister.add(new TestResize<T>(testName, src, 640, 480, i, false));
|
||||
}
|
||||
|
||||
for (Ncv32u i=2; i<10; ++i)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestResize_1080_s%d", i);
|
||||
testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, true));
|
||||
testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, false));
|
||||
}
|
||||
}
|
||||
|
||||
void generateNPPSTVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
//compaction
|
||||
for (Ncv32f _i=256.0; _i<maxLength; _i*=1.5f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 30));
|
||||
}
|
||||
for (Ncv32u i=1; i<260; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 70));
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 0));
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 100));
|
||||
}
|
||||
for (Ncv32u i=256*256-10; i<256*256+10; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 40));
|
||||
}
|
||||
for (Ncv32u i=256*256*256-2; i<256*256*256+2; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0x00000000, 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void generateTransposeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
|
||||
{
|
||||
for (int i=2; i<64; i+=4)
|
||||
{
|
||||
for (int j=2; j<64; j+=4)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestTranspose_%dx%d", i, j);
|
||||
testLister.add(new TestTranspose<T>(testName, src, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=1; i<128; i+=1)
|
||||
{
|
||||
for (int j=1; j<2; j+=1)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestTranspose_%dx%d", i, j);
|
||||
testLister.add(new TestTranspose<T>(testName, src, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_VGA", src, 640, 480));
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_HD1080", src, 1920, 1080));
|
||||
|
||||
//regression tests
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_reg_0", src, 1072, 375));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void generateDrawRectsTests(NCVAutoTestLister &testLister,
|
||||
NCVTestSourceProvider<T> &src,
|
||||
NCVTestSourceProvider<Ncv32u> &src32u,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=16.0; _i<maxWidth; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
Ncv32u j = maxHeight * i / maxWidth;
|
||||
if (!j) continue;
|
||||
char testName[80];
|
||||
sprintf(testName, "DrawRectsW%dH%d", i, j);
|
||||
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFFFFFFFF));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintCheck(false, "Attempted to instantiate non-existing DrawRects test suite");
|
||||
}
|
||||
}
|
||||
|
||||
//test VGA
|
||||
testLister.add(new TestDrawRects<T>("DrawRects_VGA", src, src32u, 640, 480, 640*480/1000, (T)0xFF));
|
||||
}
|
||||
|
||||
void generateVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
//growth
|
||||
for (Ncv32f _i=10.0; _i<maxLength; _i*=1.5f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "VectorGrow%d", i);
|
||||
testLister.add(new TestHypothesesGrow(testName, src, 20, 20, 2.2f, i, i/2, i, i/4));
|
||||
testLister.add(new TestHypothesesGrow(testName, src, 10, 42, 1.2f, i, i, i, 0));
|
||||
}
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow01b", src, 10, 42, 1.2f, 10, 0, 10, 1));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow11b", src, 10, 42, 1.2f, 10, 1, 10, 1));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow10b", src, 10, 42, 1.2f, 10, 1, 10, 0));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow00b", src, 10, 42, 1.2f, 10, 0, 10, 0));
|
||||
}
|
||||
|
||||
void generateHypothesesFiltrationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxLength; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "HypFilter%d", i);
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 3, 0.2f));
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 0, 0.2f));
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 1, 0.1f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void generateHaarLoaderTests(NCVAutoTestLister &testLister)
|
||||
{
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_eye.xml", path + "haarcascade_eye.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt.xml", path + "haarcascade_frontalface_alt.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt2.xml", path + "haarcascade_frontalface_alt2.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt_tree.xml", path + "haarcascade_frontalface_alt_tree.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_eye_tree_eyeglasses.xml", path + "haarcascade_eye_tree_eyeglasses.xml"));
|
||||
}
|
||||
|
||||
void generateHaarApplicationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
(void)maxHeight;
|
||||
for (Ncv32u i=100; i<512; i+=41)
|
||||
{
|
||||
for (Ncv32u j=100; j<128; j+=25)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "HaarAppl%d_%d", i, j);
|
||||
testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", j, i));
|
||||
}
|
||||
}
|
||||
for (Ncv32f _i=20.0; _i<maxWidth; _i*=1.5f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "HaarAppl%d", i);
|
||||
testLister.add(new TestHaarCascadeApplication(testName, src, path + "haarcascade_frontalface_alt.xml", i, i));
|
||||
}
|
||||
}
|
||||
|
||||
static void devNullOutput(const cv::String& msg)
|
||||
{
|
||||
(void)msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path.c_str();
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerII("NPPST Integral Image", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
|
||||
NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 2048, 2048);
|
||||
|
||||
generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 2048, 2048);
|
||||
generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 2048, 2048);
|
||||
|
||||
return testListerII.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerSII("NPPST Squared Integral Image", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
|
||||
|
||||
generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 2048, 2048);
|
||||
|
||||
return testListerSII.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_RectStdDev(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerRStdDev("NPPST RectStdDev", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
|
||||
|
||||
generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 2048, 2048);
|
||||
|
||||
return testListerRStdDev.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_Resize(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerResize("NPPST Resize", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
|
||||
NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, -1, 2048, 2048);
|
||||
|
||||
generateResizeTests(testListerResize, testSrcRandom_32u);
|
||||
generateResizeTests(testListerResize, testSrcRandom_64u);
|
||||
|
||||
return testListerResize.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerNPPSTVectorOperations("NPPST Vector Operations", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
|
||||
|
||||
generateNPPSTVectorTests(testListerNPPSTVectorOperations, testSrcRandom_32u, 2048*2048);
|
||||
|
||||
return testListerNPPSTVectorOperations.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NPPST_Transpose(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerTranspose("NPPST Transpose", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
|
||||
NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, -1, 2048, 2048);
|
||||
|
||||
generateTransposeTests(testListerTranspose, testSrcRandom_32u);
|
||||
generateTransposeTests(testListerTranspose, testSrcRandom_64u);
|
||||
|
||||
return testListerTranspose.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NCV_Vector_Operations(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerVectorOperations("Vector Operations", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
|
||||
|
||||
generateVectorTests(testListerVectorOperations, testSrcRandom_32u, 2048*2048);
|
||||
|
||||
return testListerVectorOperations.invoke();
|
||||
|
||||
}
|
||||
|
||||
bool nvidia_NCV_Haar_Cascade_Loader(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerHaarLoader("Haar Cascade Loader", outputLevel);
|
||||
|
||||
generateHaarLoaderTests(testListerHaarLoader);
|
||||
|
||||
return testListerHaarLoader.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NCV_Haar_Cascade_Application(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerHaarAppl("Haar Cascade Application", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> testSrcFacesVGA_8u(path + "group_1_640x480_VGA.pgm");
|
||||
|
||||
generateHaarApplicationTests(testListerHaarAppl, testSrcFacesVGA_8u, 640, 480);
|
||||
|
||||
return testListerHaarAppl.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NCV_Hypotheses_Filtration(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerHypFiltration("Hypotheses Filtration", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 2048, 2048);
|
||||
|
||||
generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 512);
|
||||
|
||||
return testListerHypFiltration.invoke();
|
||||
}
|
||||
|
||||
bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel outputLevel)
|
||||
{
|
||||
path = test_data_path;
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerVisualize("Visualization", outputLevel);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 2048, 2048);
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, RAND_MAX, 2048, 2048);
|
||||
|
||||
generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 2048, 2048);
|
||||
generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 2048, 2048);
|
||||
|
||||
return testListerVisualize.invoke();
|
||||
}
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
405
modules/gpu/test/test_bgfg.cpp
Normal file
405
modules/gpu/test/test_bgfg.cpp
Normal file
@@ -0,0 +1,405 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/legacy.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
#if defined(HAVE_XINE) || \
|
||||
defined(HAVE_GSTREAMER) || \
|
||||
defined(HAVE_QUICKTIME) || \
|
||||
defined(HAVE_AVFOUNDATION) || \
|
||||
defined(HAVE_FFMPEG) || \
|
||||
defined(WIN32) /* assume that we have ffmpeg */
|
||||
|
||||
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
|
||||
#else
|
||||
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FGDStatModel
|
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
|
||||
|
||||
namespace cv
|
||||
{
|
||||
template<> void Ptr<CvBGStatModel>::delete_obj()
|
||||
{
|
||||
cvReleaseBGStatModel(&obj);
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
int out_cn;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
||||
|
||||
out_cn = GET_PARAM(2);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(FGDStatModel, Update)
|
||||
{
|
||||
cv::VideoCapture cap(inputFile);
|
||||
ASSERT_TRUE(cap.isOpened());
|
||||
|
||||
cv::Mat frame;
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
IplImage ipl_frame = frame;
|
||||
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
|
||||
|
||||
cv::gpu::GpuMat d_frame(frame);
|
||||
cv::gpu::FGDStatModel d_model(out_cn);
|
||||
d_model.create(d_frame);
|
||||
|
||||
cv::Mat h_background;
|
||||
cv::Mat h_foreground;
|
||||
cv::Mat h_background3;
|
||||
|
||||
cv::Mat backgroundDiff;
|
||||
cv::Mat foregroundDiff;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
ipl_frame = frame;
|
||||
int gold_count = cvUpdateBGStatModel(&ipl_frame, model);
|
||||
|
||||
d_frame.upload(frame);
|
||||
|
||||
int count = d_model.update(d_frame);
|
||||
|
||||
ASSERT_EQ(gold_count, count);
|
||||
|
||||
cv::Mat gold_background = cv::cvarrToMat(model->background);
|
||||
cv::Mat gold_foreground = cv::cvarrToMat(model->foreground);
|
||||
|
||||
if (out_cn == 3)
|
||||
d_model.background.download(h_background3);
|
||||
else
|
||||
{
|
||||
d_model.background.download(h_background);
|
||||
cv::cvtColor(h_background, h_background3, cv::COLOR_BGRA2BGR);
|
||||
}
|
||||
d_model.foreground.download(h_foreground);
|
||||
|
||||
ASSERT_MAT_NEAR(gold_background, h_background3, 1.0);
|
||||
ASSERT_MAT_NEAR(gold_foreground, h_foreground, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, FGDStatModel, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi")),
|
||||
testing::Values(Channels(3), Channels(4))));
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// MOG
|
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(UseGray, bool)
|
||||
IMPLEMENT_PARAM_CLASS(LearningRate, double)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(MOG, cv::gpu::DeviceInfo, std::string, UseGray, LearningRate, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
bool useGray;
|
||||
double learningRate;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
||||
|
||||
useGray = GET_PARAM(2);
|
||||
|
||||
learningRate = GET_PARAM(3);
|
||||
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(MOG, Update)
|
||||
{
|
||||
cv::VideoCapture cap(inputFile);
|
||||
ASSERT_TRUE(cap.isOpened());
|
||||
|
||||
cv::Mat frame;
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
cv::gpu::MOG_GPU mog;
|
||||
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
|
||||
|
||||
cv::Ptr<cv::BackgroundSubtractorMOG> mog_gold = cv::createBackgroundSubtractorMOG();
|
||||
cv::Mat foreground_gold;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
if (useGray)
|
||||
{
|
||||
cv::Mat temp;
|
||||
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
|
||||
cv::swap(temp, frame);
|
||||
}
|
||||
|
||||
mog(loadMat(frame, useRoi), foreground, (float)learningRate);
|
||||
|
||||
mog_gold->apply(frame, foreground_gold, learningRate);
|
||||
|
||||
ASSERT_MAT_NEAR(foreground_gold, foreground, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, MOG, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi")),
|
||||
testing::Values(UseGray(true), UseGray(false)),
|
||||
testing::Values(LearningRate(0.0), LearningRate(0.01)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// MOG2
|
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(MOG2, cv::gpu::DeviceInfo, std::string, UseGray, DetectShadow, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
bool useGray;
|
||||
bool detectShadow;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
||||
useGray = GET_PARAM(2);
|
||||
detectShadow = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(MOG2, Update)
|
||||
{
|
||||
cv::VideoCapture cap(inputFile);
|
||||
ASSERT_TRUE(cap.isOpened());
|
||||
|
||||
cv::Mat frame;
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
cv::gpu::MOG2_GPU mog2;
|
||||
mog2.bShadowDetection = detectShadow;
|
||||
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
|
||||
|
||||
cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2();
|
||||
mog2_gold->setDetectShadows(detectShadow);
|
||||
cv::Mat foreground_gold;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
if (useGray)
|
||||
{
|
||||
cv::Mat temp;
|
||||
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
|
||||
cv::swap(temp, frame);
|
||||
}
|
||||
|
||||
mog2(loadMat(frame, useRoi), foreground);
|
||||
|
||||
mog2_gold->apply(frame, foreground_gold);
|
||||
|
||||
if (detectShadow)
|
||||
{
|
||||
ASSERT_MAT_SIMILAR(foreground_gold, foreground, 1e-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_MAT_NEAR(foreground_gold, foreground, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GPU_TEST_P(MOG2, getBackgroundImage)
|
||||
{
|
||||
if (useGray)
|
||||
return;
|
||||
|
||||
cv::VideoCapture cap(inputFile);
|
||||
ASSERT_TRUE(cap.isOpened());
|
||||
|
||||
cv::Mat frame;
|
||||
|
||||
cv::gpu::MOG2_GPU mog2;
|
||||
mog2.bShadowDetection = detectShadow;
|
||||
cv::gpu::GpuMat foreground;
|
||||
|
||||
cv::Ptr<cv::BackgroundSubtractorMOG2> mog2_gold = cv::createBackgroundSubtractorMOG2();
|
||||
mog2_gold->setDetectShadows(detectShadow);
|
||||
cv::Mat foreground_gold;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
mog2(loadMat(frame, useRoi), foreground);
|
||||
|
||||
mog2_gold->apply(frame, foreground_gold);
|
||||
}
|
||||
|
||||
cv::gpu::GpuMat background = createMat(frame.size(), frame.type(), useRoi);
|
||||
mog2.getBackgroundImage(background);
|
||||
|
||||
cv::Mat background_gold;
|
||||
mog2_gold->getBackgroundImage(background_gold);
|
||||
|
||||
ASSERT_MAT_NEAR(background_gold, background, 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, MOG2, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi")),
|
||||
testing::Values(UseGray(true), UseGray(false)),
|
||||
testing::Values(DetectShadow(true), DetectShadow(false)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// GMG
|
||||
|
||||
PARAM_TEST_CASE(GMG, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
||||
{
|
||||
};
|
||||
|
||||
GPU_TEST_P(GMG, Accuracy)
|
||||
{
|
||||
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
const cv::Size size = GET_PARAM(1);
|
||||
const int depth = GET_PARAM(2);
|
||||
const int channels = GET_PARAM(3);
|
||||
const bool useRoi = GET_PARAM(4);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
const cv::Mat zeros(size, CV_8UC1, cv::Scalar::all(0));
|
||||
const cv::Mat fullfg(size, CV_8UC1, cv::Scalar::all(255));
|
||||
|
||||
cv::Mat frame = randomMat(size, type, 0, 100);
|
||||
cv::gpu::GpuMat d_frame = loadMat(frame, useRoi);
|
||||
|
||||
cv::gpu::GMG_GPU gmg;
|
||||
gmg.numInitializationFrames = 5;
|
||||
gmg.smoothingRadius = 0;
|
||||
gmg.initialize(d_frame.size(), 0, 255);
|
||||
|
||||
cv::gpu::GpuMat d_fgmask = createMat(size, CV_8UC1, useRoi);
|
||||
|
||||
for (int i = 0; i < gmg.numInitializationFrames; ++i)
|
||||
{
|
||||
gmg(d_frame, d_fgmask);
|
||||
|
||||
// fgmask should be entirely background during training
|
||||
ASSERT_MAT_NEAR(zeros, d_fgmask, 0);
|
||||
}
|
||||
|
||||
frame = randomMat(size, type, 160, 255);
|
||||
d_frame = loadMat(frame, useRoi);
|
||||
gmg(d_frame, d_fgmask);
|
||||
|
||||
// now fgmask should be entirely foreground
|
||||
ASSERT_MAT_NEAR(fullfg, d_fgmask, 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, GMG, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8U), MatType(CV_16U), MatType(CV_32F)),
|
||||
testing::Values(Channels(1), Channels(3), Channels(4)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
@@ -46,6 +46,123 @@
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// StereoBM
|
||||
|
||||
struct StereoBM : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(StereoBM, Regression)
|
||||
{
|
||||
cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE);
|
||||
|
||||
ASSERT_FALSE(left_image.empty());
|
||||
ASSERT_FALSE(right_image.empty());
|
||||
ASSERT_FALSE(disp_gold.empty());
|
||||
|
||||
cv::gpu::StereoBM_GPU bm(0, 128, 19);
|
||||
cv::gpu::GpuMat disp;
|
||||
|
||||
bm(loadMat(left_image), loadMat(right_image), disp);
|
||||
|
||||
EXPECT_MAT_NEAR(disp_gold, disp, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBM, ALL_DEVICES);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// StereoBeliefPropagation
|
||||
|
||||
struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(StereoBeliefPropagation, Regression)
|
||||
{
|
||||
cv::Mat left_image = readImage("stereobp/aloe-L.png");
|
||||
cv::Mat right_image = readImage("stereobp/aloe-R.png");
|
||||
cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
|
||||
|
||||
ASSERT_FALSE(left_image.empty());
|
||||
ASSERT_FALSE(right_image.empty());
|
||||
ASSERT_FALSE(disp_gold.empty());
|
||||
|
||||
cv::gpu::StereoBeliefPropagation bp(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
|
||||
cv::gpu::GpuMat disp;
|
||||
|
||||
bp(loadMat(left_image), loadMat(right_image), disp);
|
||||
|
||||
cv::Mat h_disp(disp);
|
||||
h_disp.convertTo(h_disp, disp_gold.depth());
|
||||
|
||||
EXPECT_MAT_NEAR(disp_gold, h_disp, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBeliefPropagation, ALL_DEVICES);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// StereoConstantSpaceBP
|
||||
|
||||
struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(StereoConstantSpaceBP, Regression)
|
||||
{
|
||||
cv::Mat left_image = readImage("csstereobp/aloe-L.png");
|
||||
cv::Mat right_image = readImage("csstereobp/aloe-R.png");
|
||||
|
||||
cv::Mat disp_gold;
|
||||
|
||||
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
|
||||
disp_gold = readImage("csstereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
|
||||
else
|
||||
disp_gold = readImage("csstereobp/aloe-disp_CC1X.png", cv::IMREAD_GRAYSCALE);
|
||||
|
||||
ASSERT_FALSE(left_image.empty());
|
||||
ASSERT_FALSE(right_image.empty());
|
||||
ASSERT_FALSE(disp_gold.empty());
|
||||
|
||||
cv::gpu::StereoConstantSpaceBP csbp(128, 16, 4, 4);
|
||||
cv::gpu::GpuMat disp;
|
||||
|
||||
csbp(loadMat(left_image), loadMat(right_image), disp);
|
||||
|
||||
cv::Mat h_disp(disp);
|
||||
h_disp.convertTo(h_disp, disp_gold.depth());
|
||||
|
||||
EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoConstantSpaceBP, ALL_DEVICES);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// transformPoints
|
||||
|
||||
@@ -187,4 +304,45 @@ GPU_TEST_P(SolvePnPRansac, Accuracy)
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// reprojectImageTo3D
|
||||
|
||||
PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(ReprojectImageTo3D, Accuracy)
|
||||
{
|
||||
cv::Mat disp = randomMat(size, depth, 5.0, 30.0);
|
||||
cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::reprojectImageTo3D(disp, dst_gold, Q, false);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatDepth(CV_8U), MatDepth(CV_16S)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
||||
|
2503
modules/gpu/test/test_color.cpp
Normal file
2503
modules/gpu/test/test_color.cpp
Normal file
File diff suppressed because it is too large
Load Diff
106
modules/gpu/test/test_copy_make_border.cpp
Normal file
106
modules/gpu/test/test_copy_make_border.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(Border, int)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, Border, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int border;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
border = GET_PARAM(3);
|
||||
borderType = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(CopyMakeBorder, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Scalar val = randomScalar(0, 255);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi);
|
||||
cv::gpu::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC3),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC1),
|
||||
MatType(CV_16UC3),
|
||||
MatType(CV_16UC4),
|
||||
MatType(CV_32FC1),
|
||||
MatType(CV_32FC3),
|
||||
MatType(CV_32FC4)),
|
||||
testing::Values(Border(1), Border(10), Border(50)),
|
||||
ALL_BORDER_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
3610
modules/gpu/test/test_core.cpp
Normal file
3610
modules/gpu/test/test_core.cpp
Normal file
File diff suppressed because it is too large
Load Diff
185
modules/gpu/test/test_denoising.cpp
Normal file
185
modules/gpu/test/test_denoising.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// BilateralFilter
|
||||
|
||||
PARAM_TEST_CASE(BilateralFilter, cv::gpu::DeviceInfo, cv::Size, MatType)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int kernel_size;
|
||||
float sigma_color;
|
||||
float sigma_spatial;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
|
||||
kernel_size = 5;
|
||||
sigma_color = 10.f;
|
||||
sigma_spatial = 3.5f;
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BilateralFilter, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
src.convertTo(src, type);
|
||||
cv::gpu::GpuMat dst;
|
||||
|
||||
cv::gpu::bilateralFilter(loadMat(src), dst, kernel_size, sigma_color, sigma_spatial);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::bilateralFilter(src, dst_gold, kernel_size, sigma_color, sigma_spatial);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Denoising, BilateralFilter, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(cv::Size(128, 128), cv::Size(113, 113), cv::Size(639, 481)),
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_32FC1), MatType(CV_32FC3))
|
||||
));
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Brute Force Non local means
|
||||
|
||||
struct BruteForceNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BruteForceNonLocalMeans, Regression)
|
||||
{
|
||||
using cv::gpu::GpuMat;
|
||||
|
||||
cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
|
||||
ASSERT_FALSE(bgr.empty());
|
||||
|
||||
cv::Mat gray;
|
||||
cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);
|
||||
|
||||
GpuMat dbgr, dgray;
|
||||
cv::gpu::nonLocalMeans(GpuMat(bgr), dbgr, 20);
|
||||
cv::gpu::nonLocalMeans(GpuMat(gray), dgray, 20);
|
||||
|
||||
#if 0
|
||||
dumpImage("denoising/nlm_denoised_lena_bgr.png", cv::Mat(dbgr));
|
||||
dumpImage("denoising/nlm_denoised_lena_gray.png", cv::Mat(dgray));
|
||||
#endif
|
||||
|
||||
cv::Mat bgr_gold = readImage("denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
|
||||
cv::Mat gray_gold = readImage("denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
|
||||
|
||||
EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4);
|
||||
EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Denoising, BruteForceNonLocalMeans, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Fast Force Non local means
|
||||
|
||||
struct FastNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(FastNonLocalMeans, Regression)
|
||||
{
|
||||
using cv::gpu::GpuMat;
|
||||
|
||||
cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
|
||||
ASSERT_FALSE(bgr.empty());
|
||||
|
||||
cv::Mat gray;
|
||||
cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);
|
||||
|
||||
GpuMat dbgr, dgray;
|
||||
cv::gpu::FastNonLocalMeansDenoising fnlmd;
|
||||
|
||||
fnlmd.simpleMethod(GpuMat(gray), dgray, 20);
|
||||
fnlmd.labMethod(GpuMat(bgr), dbgr, 20, 10);
|
||||
|
||||
#if 0
|
||||
dumpImage("denoising/fnlm_denoised_lena_bgr.png", cv::Mat(dbgr));
|
||||
dumpImage("denoising/fnlm_denoised_lena_gray.png", cv::Mat(dgray));
|
||||
#endif
|
||||
|
||||
cv::Mat bgr_gold = readImage("denoising/fnlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
|
||||
cv::Mat gray_gold = readImage("denoising/fnlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
|
||||
|
||||
EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);
|
||||
EXPECT_MAT_NEAR(gray_gold, dgray, 1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Denoising, FastNonLocalMeans, ALL_DEVICES);
|
||||
|
||||
#endif // HAVE_CUDA
|
703
modules/gpu/test/test_features2d.cpp
Normal file
703
modules/gpu/test/test_features2d.cpp
Normal file
@@ -0,0 +1,703 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FAST
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(FAST_Threshold, int)
|
||||
IMPLEMENT_PARAM_CLASS(FAST_NonmaxSupression, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(FAST, cv::gpu::DeviceInfo, FAST_Threshold, FAST_NonmaxSupression)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
int threshold;
|
||||
bool nonmaxSupression;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
threshold = GET_PARAM(1);
|
||||
nonmaxSupression = GET_PARAM(2);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(FAST, Accuracy)
|
||||
{
|
||||
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(image.empty());
|
||||
|
||||
cv::gpu::FAST_GPU fast(threshold);
|
||||
fast.nonmaxSupression = nonmaxSupression;
|
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
fast(loadMat(image), cv::gpu::GpuMat(), keypoints);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
fast(loadMat(image), cv::gpu::GpuMat(), keypoints);
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints_gold;
|
||||
cv::FAST(image, keypoints_gold, threshold, nonmaxSupression);
|
||||
|
||||
ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Features2D, FAST, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(FAST_Threshold(25), FAST_Threshold(50)),
|
||||
testing::Values(FAST_NonmaxSupression(false), FAST_NonmaxSupression(true))));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ORB
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(ORB_FeaturesCount, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_ScaleFactor, float)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_LevelsCount, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_EdgeThreshold, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_firstLevel, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_WTA_K, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_PatchSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(ORB_BlurForDescriptor, bool)
|
||||
}
|
||||
|
||||
CV_ENUM(ORB_ScoreType, ORB::HARRIS_SCORE, ORB::FAST_SCORE)
|
||||
|
||||
PARAM_TEST_CASE(ORB, cv::gpu::DeviceInfo, ORB_FeaturesCount, ORB_ScaleFactor, ORB_LevelsCount, ORB_EdgeThreshold, ORB_firstLevel, ORB_WTA_K, ORB_ScoreType, ORB_PatchSize, ORB_BlurForDescriptor)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
int nFeatures;
|
||||
float scaleFactor;
|
||||
int nLevels;
|
||||
int edgeThreshold;
|
||||
int firstLevel;
|
||||
int WTA_K;
|
||||
int scoreType;
|
||||
int patchSize;
|
||||
bool blurForDescriptor;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
nFeatures = GET_PARAM(1);
|
||||
scaleFactor = GET_PARAM(2);
|
||||
nLevels = GET_PARAM(3);
|
||||
edgeThreshold = GET_PARAM(4);
|
||||
firstLevel = GET_PARAM(5);
|
||||
WTA_K = GET_PARAM(6);
|
||||
scoreType = GET_PARAM(7);
|
||||
patchSize = GET_PARAM(8);
|
||||
blurForDescriptor = GET_PARAM(9);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(ORB, Accuracy)
|
||||
{
|
||||
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(image.empty());
|
||||
|
||||
cv::Mat mask(image.size(), CV_8UC1, cv::Scalar::all(1));
|
||||
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
|
||||
|
||||
cv::gpu::ORB_GPU orb(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
|
||||
orb.blurForDescriptor = blurForDescriptor;
|
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
cv::gpu::GpuMat descriptors;
|
||||
orb(loadMat(image), loadMat(mask), keypoints, descriptors);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
cv::gpu::GpuMat descriptors;
|
||||
orb(loadMat(image), loadMat(mask), keypoints, descriptors);
|
||||
|
||||
cv::ORB orb_gold(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints_gold;
|
||||
cv::Mat descriptors_gold;
|
||||
orb_gold(image, mask, keypoints_gold, descriptors_gold);
|
||||
|
||||
cv::BFMatcher matcher(cv::NORM_HAMMING);
|
||||
std::vector<cv::DMatch> matches;
|
||||
matcher.match(descriptors_gold, cv::Mat(descriptors), matches);
|
||||
|
||||
int matchedCount = getMatchedPointsCount(keypoints_gold, keypoints, matches);
|
||||
double matchedRatio = static_cast<double>(matchedCount) / keypoints.size();
|
||||
|
||||
EXPECT_GT(matchedRatio, 0.35);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Features2D, ORB, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(ORB_FeaturesCount(1000)),
|
||||
testing::Values(ORB_ScaleFactor(1.2f)),
|
||||
testing::Values(ORB_LevelsCount(4), ORB_LevelsCount(8)),
|
||||
testing::Values(ORB_EdgeThreshold(31)),
|
||||
testing::Values(ORB_firstLevel(0), ORB_firstLevel(2)),
|
||||
testing::Values(ORB_WTA_K(2), ORB_WTA_K(3), ORB_WTA_K(4)),
|
||||
testing::Values(ORB_ScoreType(cv::ORB::HARRIS_SCORE)),
|
||||
testing::Values(ORB_PatchSize(31), ORB_PatchSize(29)),
|
||||
testing::Values(ORB_BlurForDescriptor(false), ORB_BlurForDescriptor(true))));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BruteForceMatcher
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(DescriptorSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(UseMask, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, NormCode, DescriptorSize, UseMask)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
int normCode;
|
||||
int dim;
|
||||
bool useMask;
|
||||
|
||||
int queryDescCount;
|
||||
int countFactor;
|
||||
|
||||
cv::Mat query, train;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
normCode = GET_PARAM(1);
|
||||
dim = GET_PARAM(2);
|
||||
useMask = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
queryDescCount = 300; // must be even number because we split train data in some cases in two
|
||||
countFactor = 4; // do not change it
|
||||
|
||||
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
|
||||
|
||||
cv::Mat queryBuf, trainBuf;
|
||||
|
||||
// Generate query descriptors randomly.
|
||||
// Descriptor vector elements are integer values.
|
||||
queryBuf.create(queryDescCount, dim, CV_32SC1);
|
||||
rng.fill(queryBuf, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
|
||||
queryBuf.convertTo(queryBuf, CV_32FC1);
|
||||
|
||||
// Generate train decriptors as follows:
|
||||
// copy each query descriptor to train set countFactor times
|
||||
// and perturb some one element of the copied descriptors in
|
||||
// in ascending order. General boundaries of the perturbation
|
||||
// are (0.f, 1.f).
|
||||
trainBuf.create(queryDescCount * countFactor, dim, CV_32FC1);
|
||||
float step = 1.f / countFactor;
|
||||
for (int qIdx = 0; qIdx < queryDescCount; qIdx++)
|
||||
{
|
||||
cv::Mat queryDescriptor = queryBuf.row(qIdx);
|
||||
for (int c = 0; c < countFactor; c++)
|
||||
{
|
||||
int tIdx = qIdx * countFactor + c;
|
||||
cv::Mat trainDescriptor = trainBuf.row(tIdx);
|
||||
queryDescriptor.copyTo(trainDescriptor);
|
||||
int elem = rng(dim);
|
||||
float diff = rng.uniform(step * c, step * (c + 1));
|
||||
trainDescriptor.at<float>(0, elem) += diff;
|
||||
}
|
||||
}
|
||||
|
||||
queryBuf.convertTo(query, CV_32F);
|
||||
trainBuf.convertTo(train, CV_32F);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, Match_Single)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
cv::gpu::GpuMat mask;
|
||||
if (useMask)
|
||||
{
|
||||
mask.create(query.rows, train.rows, CV_8UC1);
|
||||
mask.setTo(cv::Scalar::all(1));
|
||||
}
|
||||
|
||||
std::vector<cv::DMatch> matches;
|
||||
matcher.match(loadMat(query), loadMat(train), matches, mask);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
cv::DMatch match = matches[i];
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor) || (match.imgIdx != 0))
|
||||
badCount++;
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, Match_Collection)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
cv::gpu::GpuMat d_train(train);
|
||||
|
||||
// make add() twice to test such case
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
|
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<cv::gpu::GpuMat> masks(2);
|
||||
for (int mi = 0; mi < 2; mi++)
|
||||
{
|
||||
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows/2, CV_8UC1, cv::Scalar::all(1));
|
||||
for (int di = 0; di < queryDescCount/2; di++)
|
||||
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
|
||||
}
|
||||
|
||||
std::vector<cv::DMatch> matches;
|
||||
if (useMask)
|
||||
matcher.match(cv::gpu::GpuMat(query), matches, masks);
|
||||
else
|
||||
matcher.match(cv::gpu::GpuMat(query), matches);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
int shift = useMask ? 1 : 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
cv::DMatch match = matches[i];
|
||||
|
||||
if ((int)i < queryDescCount / 2)
|
||||
{
|
||||
bool validQueryIdx = (match.queryIdx == (int)i);
|
||||
bool validTrainIdx = (match.trainIdx == (int)i * countFactor + shift);
|
||||
bool validImgIdx = (match.imgIdx == 0);
|
||||
if (!validQueryIdx || !validTrainIdx || !validImgIdx)
|
||||
badCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool validQueryIdx = (match.queryIdx == (int)i);
|
||||
bool validTrainIdx = (match.trainIdx == ((int)i - queryDescCount / 2) * countFactor + shift);
|
||||
bool validImgIdx = (match.imgIdx == 1);
|
||||
if (!validQueryIdx || !validTrainIdx || !validImgIdx)
|
||||
badCount++;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, KnnMatch_2_Single)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const int knn = 2;
|
||||
|
||||
cv::gpu::GpuMat mask;
|
||||
if (useMask)
|
||||
{
|
||||
mask.create(query.rows, train.rows, CV_8UC1);
|
||||
mask.setTo(cv::Scalar::all(1));
|
||||
}
|
||||
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != knn)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for (int k = 0; k < knn; k++)
|
||||
{
|
||||
cv::DMatch match = matches[i][k];
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
|
||||
localBadCount++;
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, KnnMatch_3_Single)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const int knn = 3;
|
||||
|
||||
cv::gpu::GpuMat mask;
|
||||
if (useMask)
|
||||
{
|
||||
mask.create(query.rows, train.rows, CV_8UC1);
|
||||
mask.setTo(cv::Scalar::all(1));
|
||||
}
|
||||
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != knn)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for (int k = 0; k < knn; k++)
|
||||
{
|
||||
cv::DMatch match = matches[i][k];
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
|
||||
localBadCount++;
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, KnnMatch_2_Collection)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const int knn = 2;
|
||||
|
||||
cv::gpu::GpuMat d_train(train);
|
||||
|
||||
// make add() twice to test such case
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
|
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<cv::gpu::GpuMat> masks(2);
|
||||
for (int mi = 0; mi < 2; mi++ )
|
||||
{
|
||||
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
|
||||
for (int di = 0; di < queryDescCount / 2; di++)
|
||||
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
|
||||
}
|
||||
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
|
||||
if (useMask)
|
||||
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
|
||||
else
|
||||
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
int shift = useMask ? 1 : 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != knn)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for (int k = 0; k < knn; k++)
|
||||
{
|
||||
cv::DMatch match = matches[i][k];
|
||||
{
|
||||
if ((int)i < queryDescCount / 2)
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
|
||||
localBadCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, KnnMatch_3_Collection)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const int knn = 3;
|
||||
|
||||
cv::gpu::GpuMat d_train(train);
|
||||
|
||||
// make add() twice to test such case
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
|
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<cv::gpu::GpuMat> masks(2);
|
||||
for (int mi = 0; mi < 2; mi++ )
|
||||
{
|
||||
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
|
||||
for (int di = 0; di < queryDescCount / 2; di++)
|
||||
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
|
||||
}
|
||||
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
|
||||
if (useMask)
|
||||
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
|
||||
else
|
||||
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
int shift = useMask ? 1 : 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != knn)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for (int k = 0; k < knn; k++)
|
||||
{
|
||||
cv::DMatch match = matches[i][k];
|
||||
{
|
||||
if ((int)i < queryDescCount / 2)
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
|
||||
localBadCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, RadiusMatch_Single)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const float radius = 1.f / countFactor;
|
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::gpu::GpuMat mask;
|
||||
if (useMask)
|
||||
{
|
||||
mask.create(query.rows, train.rows, CV_8UC1);
|
||||
mask.setTo(cv::Scalar::all(1));
|
||||
}
|
||||
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius, mask);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != 1)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
cv::DMatch match = matches[i][0];
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0))
|
||||
badCount++;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
}
|
||||
|
||||
GPU_TEST_P(BruteForceMatcher, RadiusMatch_Collection)
|
||||
{
|
||||
cv::gpu::BFMatcher_GPU matcher(normCode);
|
||||
|
||||
const int n = 3;
|
||||
const float radius = 1.f / countFactor * n;
|
||||
|
||||
cv::gpu::GpuMat d_train(train);
|
||||
|
||||
// make add() twice to test such case
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
|
||||
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
|
||||
|
||||
// prepare masks (make first nearest match illegal)
|
||||
std::vector<cv::gpu::GpuMat> masks(2);
|
||||
for (int mi = 0; mi < 2; mi++)
|
||||
{
|
||||
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
|
||||
for (int di = 0; di < queryDescCount / 2; di++)
|
||||
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
|
||||
}
|
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius, masks);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector< std::vector<cv::DMatch> > matches;
|
||||
|
||||
if (useMask)
|
||||
matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius, masks);
|
||||
else
|
||||
matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius);
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
|
||||
|
||||
int badCount = 0;
|
||||
int shift = useMask ? 1 : 0;
|
||||
int needMatchCount = useMask ? n-1 : n;
|
||||
for (size_t i = 0; i < matches.size(); i++)
|
||||
{
|
||||
if ((int)matches[i].size() != needMatchCount)
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for (int k = 0; k < needMatchCount; k++)
|
||||
{
|
||||
cv::DMatch match = matches[i][k];
|
||||
{
|
||||
if ((int)i < queryDescCount / 2)
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
|
||||
localBadCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, badCount);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(NormCode(cv::NORM_L1), NormCode(cv::NORM_L2)),
|
||||
testing::Values(DescriptorSize(57), DescriptorSize(64), DescriptorSize(83), DescriptorSize(128), DescriptorSize(179), DescriptorSize(256), DescriptorSize(304)),
|
||||
testing::Values(UseMask(false), UseMask(true))));
|
||||
|
||||
#endif // HAVE_CUDA
|
577
modules/gpu/test/test_filters.cpp
Normal file
577
modules/gpu/test/test_filters.cpp
Normal file
@@ -0,0 +1,577 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(KSize, cv::Size)
|
||||
IMPLEMENT_PARAM_CLASS(Anchor, cv::Point)
|
||||
IMPLEMENT_PARAM_CLASS(Deriv_X, int)
|
||||
IMPLEMENT_PARAM_CLASS(Deriv_Y, int)
|
||||
IMPLEMENT_PARAM_CLASS(Iterations, int)
|
||||
|
||||
cv::Mat getInnerROI(cv::InputArray m_, cv::Size ksize)
|
||||
{
|
||||
cv::Mat m = getMat(m_);
|
||||
cv::Rect roi(ksize.width, ksize.height, m.cols - 2 * ksize.width, m.rows - 2 * ksize.height);
|
||||
return m(roi);
|
||||
}
|
||||
|
||||
cv::Mat getInnerROI(cv::InputArray m, int ksize)
|
||||
{
|
||||
return getInnerROI(m, cv::Size(ksize, ksize));
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Blur
|
||||
|
||||
PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
cv::Size ksize;
|
||||
cv::Point anchor;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
ksize = GET_PARAM(3);
|
||||
anchor = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Blur, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::blur(loadMat(src, useRoi), dst, ksize, anchor);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::blur(src, dst_gold, ksize, anchor);
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Blur, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
|
||||
testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7))),
|
||||
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Sobel
|
||||
|
||||
PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, KSize, Deriv_X, Deriv_Y, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int cn;
|
||||
cv::Size ksize;
|
||||
int dx;
|
||||
int dy;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
cn = GET_PARAM(3);
|
||||
ksize = GET_PARAM(4);
|
||||
dx = GET_PARAM(5);
|
||||
dy = GET_PARAM(6);
|
||||
borderType = GET_PARAM(7);
|
||||
useRoi = GET_PARAM(8);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
type = CV_MAKE_TYPE(depth, cn);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Sobel, Accuracy)
|
||||
{
|
||||
if (dx == 0 && dy == 0)
|
||||
return;
|
||||
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::Sobel(loadMat(src, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::Sobel(src, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType);
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Sobel, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32F)),
|
||||
IMAGE_CHANNELS,
|
||||
testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7))),
|
||||
testing::Values(Deriv_X(0), Deriv_X(1), Deriv_X(2)),
|
||||
testing::Values(Deriv_Y(0), Deriv_Y(1), Deriv_Y(2)),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101),
|
||||
BorderType(cv::BORDER_REPLICATE),
|
||||
BorderType(cv::BORDER_CONSTANT),
|
||||
BorderType(cv::BORDER_REFLECT)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Scharr
|
||||
|
||||
PARAM_TEST_CASE(Scharr, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, Deriv_X, Deriv_Y, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int cn;
|
||||
int dx;
|
||||
int dy;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
cn = GET_PARAM(3);
|
||||
dx = GET_PARAM(4);
|
||||
dy = GET_PARAM(5);
|
||||
borderType = GET_PARAM(6);
|
||||
useRoi = GET_PARAM(7);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
type = CV_MAKE_TYPE(depth, cn);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Scharr, Accuracy)
|
||||
{
|
||||
if (dx + dy != 1)
|
||||
return;
|
||||
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::Scharr(loadMat(src, useRoi), dst, -1, dx, dy, 1.0, borderType);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::Scharr(src, dst_gold, -1, dx, dy, 1.0, 0.0, borderType);
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, cv::Size(3, 3)), getInnerROI(dst, cv::Size(3, 3)), CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Scharr, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32F)),
|
||||
IMAGE_CHANNELS,
|
||||
testing::Values(Deriv_X(0), Deriv_X(1)),
|
||||
testing::Values(Deriv_Y(0), Deriv_Y(1)),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101),
|
||||
BorderType(cv::BORDER_REPLICATE),
|
||||
BorderType(cv::BORDER_CONSTANT),
|
||||
BorderType(cv::BORDER_REFLECT)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GaussianBlur
|
||||
|
||||
PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, KSize, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int cn;
|
||||
cv::Size ksize;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
cn = GET_PARAM(3);
|
||||
ksize = GET_PARAM(4);
|
||||
borderType = GET_PARAM(5);
|
||||
useRoi = GET_PARAM(6);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
type = CV_MAKE_TYPE(depth, cn);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(GaussianBlur, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
double sigma1 = randomDouble(0.1, 1.0);
|
||||
double sigma2 = randomDouble(0.1, 1.0);
|
||||
|
||||
if (ksize.height > 16 && !supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::GaussianBlur(loadMat(src), dst, ksize, sigma1, sigma2, borderType);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::GaussianBlur(loadMat(src, useRoi), dst, ksize, sigma1, sigma2, borderType);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::GaussianBlur(src, dst_gold, ksize, sigma1, sigma2, borderType);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, GaussianBlur, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32F)),
|
||||
IMAGE_CHANNELS,
|
||||
testing::Values(KSize(cv::Size(3, 3)),
|
||||
KSize(cv::Size(5, 5)),
|
||||
KSize(cv::Size(7, 7)),
|
||||
KSize(cv::Size(9, 9)),
|
||||
KSize(cv::Size(11, 11)),
|
||||
KSize(cv::Size(13, 13)),
|
||||
KSize(cv::Size(15, 15)),
|
||||
KSize(cv::Size(17, 17)),
|
||||
KSize(cv::Size(19, 19)),
|
||||
KSize(cv::Size(21, 21)),
|
||||
KSize(cv::Size(23, 23)),
|
||||
KSize(cv::Size(25, 25)),
|
||||
KSize(cv::Size(27, 27)),
|
||||
KSize(cv::Size(29, 29)),
|
||||
KSize(cv::Size(31, 31))),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101),
|
||||
BorderType(cv::BORDER_REPLICATE),
|
||||
BorderType(cv::BORDER_CONSTANT),
|
||||
BorderType(cv::BORDER_REFLECT)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Laplacian
|
||||
|
||||
PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
cv::Size ksize;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
ksize = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Laplacian, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::Laplacian(loadMat(src, useRoi), dst, -1, ksize.width);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::Laplacian(src, dst_gold, -1, ksize.width);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() < CV_32F ? 0.0 : 1e-3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Laplacian, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)),
|
||||
testing::Values(KSize(cv::Size(1, 1)), KSize(cv::Size(3, 3))),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Erode
|
||||
|
||||
PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iterations, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
cv::Point anchor;
|
||||
int iterations;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
anchor = GET_PARAM(3);
|
||||
iterations = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Erode, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::erode(loadMat(src, useRoi), dst, kernel, anchor, iterations);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::erode(src, dst_gold, kernel, anchor, iterations);
|
||||
|
||||
cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Erode, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
|
||||
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
|
||||
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Dilate
|
||||
|
||||
PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iterations, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
cv::Point anchor;
|
||||
int iterations;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
anchor = GET_PARAM(3);
|
||||
iterations = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Dilate, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::dilate(loadMat(src, useRoi), dst, kernel, anchor, iterations);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::dilate(src, dst_gold, kernel, anchor, iterations);
|
||||
|
||||
cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Dilate, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
|
||||
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
|
||||
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// MorphEx
|
||||
|
||||
CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT)
|
||||
|
||||
PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp, Anchor, Iterations, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int morphOp;
|
||||
cv::Point anchor;
|
||||
int iterations;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
morphOp = GET_PARAM(3);
|
||||
anchor = GET_PARAM(4);
|
||||
iterations = GET_PARAM(5);
|
||||
useRoi = GET_PARAM(6);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(MorphEx, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::morphologyEx(loadMat(src, useRoi), dst, morphOp, kernel, anchor, iterations);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::morphologyEx(src, dst_gold, morphOp, kernel, anchor, iterations);
|
||||
|
||||
cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2);
|
||||
|
||||
EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, MorphEx, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
|
||||
MorphOp::all(),
|
||||
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
|
||||
testing::Values(Iterations(1), Iterations(2), Iterations(3)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Filter2D
|
||||
|
||||
PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
cv::Size ksize;
|
||||
cv::Point anchor;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
cv::Mat img;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
ksize = GET_PARAM(3);
|
||||
anchor = GET_PARAM(4);
|
||||
borderType = GET_PARAM(5);
|
||||
useRoi = GET_PARAM(6);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Filter2D, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::filter2D(loadMat(src, useRoi), dst, -1, kernel, anchor, borderType);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::filter2D(src, dst_gold, -1, kernel, anchor, 0, borderType);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC4)),
|
||||
testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7)), KSize(cv::Size(11, 11)), KSize(cv::Size(13, 13)), KSize(cv::Size(15, 15))),
|
||||
testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
255
modules/gpu/test/test_hough.cpp
Normal file
255
modules/gpu/test/test_hough.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// HoughLines
|
||||
|
||||
PARAM_TEST_CASE(HoughLines, cv::gpu::DeviceInfo, cv::Size, UseRoi)
|
||||
{
|
||||
static void generateLines(cv::Mat& img)
|
||||
{
|
||||
img.setTo(cv::Scalar::all(0));
|
||||
|
||||
cv::line(img, cv::Point(20, 0), cv::Point(20, img.rows), cv::Scalar::all(255));
|
||||
cv::line(img, cv::Point(0, 50), cv::Point(img.cols, 50), cv::Scalar::all(255));
|
||||
cv::line(img, cv::Point(0, 0), cv::Point(img.cols, img.rows), cv::Scalar::all(255));
|
||||
cv::line(img, cv::Point(img.cols, 0), cv::Point(0, img.rows), cv::Scalar::all(255));
|
||||
}
|
||||
|
||||
static void drawLines(cv::Mat& dst, const std::vector<cv::Vec2f>& lines)
|
||||
{
|
||||
dst.setTo(cv::Scalar::all(0));
|
||||
|
||||
for (size_t i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
float rho = lines[i][0], theta = lines[i][1];
|
||||
cv::Point pt1, pt2;
|
||||
double a = std::cos(theta), b = std::sin(theta);
|
||||
double x0 = a*rho, y0 = b*rho;
|
||||
pt1.x = cvRound(x0 + 1000*(-b));
|
||||
pt1.y = cvRound(y0 + 1000*(a));
|
||||
pt2.x = cvRound(x0 - 1000*(-b));
|
||||
pt2.y = cvRound(y0 - 1000*(a));
|
||||
cv::line(dst, pt1, pt2, cv::Scalar::all(255));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(HoughLines, Accuracy)
|
||||
{
|
||||
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
const cv::Size size = GET_PARAM(1);
|
||||
const bool useRoi = GET_PARAM(2);
|
||||
|
||||
const float rho = 1.0f;
|
||||
const float theta = (float) (1.5 * CV_PI / 180.0);
|
||||
const int threshold = 100;
|
||||
|
||||
cv::Mat src(size, CV_8UC1);
|
||||
generateLines(src);
|
||||
|
||||
cv::gpu::GpuMat d_lines;
|
||||
cv::gpu::HoughLines(loadMat(src, useRoi), d_lines, rho, theta, threshold);
|
||||
|
||||
std::vector<cv::Vec2f> lines;
|
||||
cv::gpu::HoughLinesDownload(d_lines, lines);
|
||||
|
||||
cv::Mat dst(size, CV_8UC1);
|
||||
drawLines(dst, lines);
|
||||
|
||||
ASSERT_MAT_NEAR(src, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughLines, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// HoughCircles
|
||||
|
||||
PARAM_TEST_CASE(HoughCircles, cv::gpu::DeviceInfo, cv::Size, UseRoi)
|
||||
{
|
||||
static void drawCircles(cv::Mat& dst, const std::vector<cv::Vec3f>& circles, bool fill)
|
||||
{
|
||||
dst.setTo(cv::Scalar::all(0));
|
||||
|
||||
for (size_t i = 0; i < circles.size(); ++i)
|
||||
cv::circle(dst, cv::Point2f(circles[i][0], circles[i][1]), (int)circles[i][2], cv::Scalar::all(255), fill ? -1 : 1);
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(HoughCircles, Accuracy)
|
||||
{
|
||||
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
const cv::Size size = GET_PARAM(1);
|
||||
const bool useRoi = GET_PARAM(2);
|
||||
|
||||
const float dp = 2.0f;
|
||||
const float minDist = 0.0f;
|
||||
const int minRadius = 10;
|
||||
const int maxRadius = 20;
|
||||
const int cannyThreshold = 100;
|
||||
const int votesThreshold = 20;
|
||||
|
||||
std::vector<cv::Vec3f> circles_gold(4);
|
||||
circles_gold[0] = cv::Vec3i(20, 20, minRadius);
|
||||
circles_gold[1] = cv::Vec3i(90, 87, minRadius + 3);
|
||||
circles_gold[2] = cv::Vec3i(30, 70, minRadius + 8);
|
||||
circles_gold[3] = cv::Vec3i(80, 10, maxRadius);
|
||||
|
||||
cv::Mat src(size, CV_8UC1);
|
||||
drawCircles(src, circles_gold, true);
|
||||
|
||||
cv::gpu::GpuMat d_circles;
|
||||
cv::gpu::HoughCircles(loadMat(src, useRoi), d_circles, cv::HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
|
||||
|
||||
std::vector<cv::Vec3f> circles;
|
||||
cv::gpu::HoughCirclesDownload(d_circles, circles);
|
||||
|
||||
ASSERT_FALSE(circles.empty());
|
||||
|
||||
for (size_t i = 0; i < circles.size(); ++i)
|
||||
{
|
||||
cv::Vec3f cur = circles[i];
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (size_t j = 0; j < circles_gold.size(); ++j)
|
||||
{
|
||||
cv::Vec3f gold = circles_gold[j];
|
||||
|
||||
if (std::fabs(cur[0] - gold[0]) < 5 && std::fabs(cur[1] - gold[1]) < 5 && std::fabs(cur[2] - gold[2]) < 5)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_TRUE(found);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughCircles, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GeneralizedHough
|
||||
|
||||
PARAM_TEST_CASE(GeneralizedHough, cv::gpu::DeviceInfo, UseRoi)
|
||||
{
|
||||
};
|
||||
|
||||
GPU_TEST_P(GeneralizedHough, POSITION)
|
||||
{
|
||||
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
const bool useRoi = GET_PARAM(1);
|
||||
|
||||
cv::Mat templ = readImage("../cv/shared/templ.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(templ.empty());
|
||||
|
||||
cv::Point templCenter(templ.cols / 2, templ.rows / 2);
|
||||
|
||||
const size_t gold_count = 3;
|
||||
cv::Point pos_gold[gold_count];
|
||||
pos_gold[0] = cv::Point(templCenter.x + 10, templCenter.y + 10);
|
||||
pos_gold[1] = cv::Point(2 * templCenter.x + 40, templCenter.y + 10);
|
||||
pos_gold[2] = cv::Point(2 * templCenter.x + 40, 2 * templCenter.y + 40);
|
||||
|
||||
cv::Mat image(templ.rows * 3, templ.cols * 3, CV_8UC1, cv::Scalar::all(0));
|
||||
for (size_t i = 0; i < gold_count; ++i)
|
||||
{
|
||||
cv::Rect rec(pos_gold[i].x - templCenter.x, pos_gold[i].y - templCenter.y, templ.cols, templ.rows);
|
||||
cv::Mat imageROI = image(rec);
|
||||
templ.copyTo(imageROI);
|
||||
}
|
||||
|
||||
cv::Ptr<cv::gpu::GeneralizedHough_GPU> hough = cv::gpu::GeneralizedHough_GPU::create(cv::GeneralizedHough::GHT_POSITION);
|
||||
hough->set("votesThreshold", 200);
|
||||
|
||||
hough->setTemplate(loadMat(templ, useRoi));
|
||||
|
||||
cv::gpu::GpuMat d_pos;
|
||||
hough->detect(loadMat(image, useRoi), d_pos);
|
||||
|
||||
std::vector<cv::Vec4f> pos;
|
||||
hough->download(d_pos, pos);
|
||||
|
||||
ASSERT_EQ(gold_count, pos.size());
|
||||
|
||||
for (size_t i = 0; i < gold_count; ++i)
|
||||
{
|
||||
cv::Point gold = pos_gold[i];
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (size_t j = 0; j < pos.size(); ++j)
|
||||
{
|
||||
cv::Point2f p(pos[j][0], pos[j][1]);
|
||||
|
||||
if (::fabs(p.x - gold.x) < 2 && ::fabs(p.y - gold.y) < 2)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_TRUE(found);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, GeneralizedHough, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
1200
modules/gpu/test/test_imgproc.cpp
Normal file
1200
modules/gpu/test/test_imgproc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
152
modules/gpu/test/test_nvidia.cpp
Normal file
152
modules/gpu/test/test_nvidia.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
OutputLevel nvidiaTestOutputLevel = OutputLevelNone;
|
||||
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
|
||||
struct NVidiaTest : TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
std::string _path;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
_path = TS::ptr()->get_data_path().c_str();
|
||||
_path = _path + "haarcascade/";
|
||||
}
|
||||
};
|
||||
|
||||
struct NPPST : NVidiaTest {};
|
||||
struct NCV : NVidiaTest {};
|
||||
|
||||
GPU_TEST_P(NPPST, Integral)
|
||||
{
|
||||
bool res = nvidia_NPPST_Integral_Image(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NPPST, SquaredIntegral)
|
||||
{
|
||||
bool res = nvidia_NPPST_Squared_Integral_Image(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NPPST, RectStdDev)
|
||||
{
|
||||
bool res = nvidia_NPPST_RectStdDev(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NPPST, Resize)
|
||||
{
|
||||
bool res = nvidia_NPPST_Resize(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NPPST, VectorOperations)
|
||||
{
|
||||
bool res = nvidia_NPPST_Vector_Operations(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NPPST, Transpose)
|
||||
{
|
||||
bool res = nvidia_NPPST_Transpose(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NCV, VectorOperations)
|
||||
{
|
||||
bool res = nvidia_NCV_Vector_Operations(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NCV, HaarCascadeLoader)
|
||||
{
|
||||
bool res = nvidia_NCV_Haar_Cascade_Loader(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NCV, HaarCascadeApplication)
|
||||
{
|
||||
bool res = nvidia_NCV_Haar_Cascade_Application(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NCV, HypothesesFiltration)
|
||||
{
|
||||
bool res = nvidia_NCV_Hypotheses_Filtration(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
GPU_TEST_P(NCV, Visualization)
|
||||
{
|
||||
// this functionality doesn't used in gpu module
|
||||
bool res = nvidia_NCV_Visualization(_path, nvidiaTestOutputLevel);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_NVidia, NPPST, ALL_DEVICES);
|
||||
INSTANTIATE_TEST_CASE_P(GPU_NVidia, NCV, ALL_DEVICES);
|
||||
|
||||
#endif // HAVE_CUDA
|
630
modules/gpu/test/test_optflow.cpp
Normal file
630
modules/gpu/test/test_optflow.cpp
Normal file
@@ -0,0 +1,630 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/legacy.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// BroxOpticalFlow
|
||||
|
||||
//#define BROX_DUMP
|
||||
|
||||
struct BroxOpticalFlow : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BroxOpticalFlow, Regression)
|
||||
{
|
||||
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
|
||||
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
|
||||
|
||||
cv::gpu::GpuMat u;
|
||||
cv::gpu::GpuMat v;
|
||||
brox(loadMat(frame0), loadMat(frame1), u, v);
|
||||
|
||||
std::string fname(cvtest::TS::ptr()->get_data_path());
|
||||
if (devInfo.majorVersion() >= 2)
|
||||
fname += "opticalflow/brox_optical_flow_cc20.bin";
|
||||
else
|
||||
fname += "opticalflow/brox_optical_flow.bin";
|
||||
|
||||
#ifndef BROX_DUMP
|
||||
std::ifstream f(fname.c_str(), std::ios_base::binary);
|
||||
|
||||
int rows, cols;
|
||||
|
||||
f.read((char*) &rows, sizeof(rows));
|
||||
f.read((char*) &cols, sizeof(cols));
|
||||
|
||||
cv::Mat u_gold(rows, cols, CV_32FC1);
|
||||
|
||||
for (int i = 0; i < u_gold.rows; ++i)
|
||||
f.read(u_gold.ptr<char>(i), u_gold.cols * sizeof(float));
|
||||
|
||||
cv::Mat v_gold(rows, cols, CV_32FC1);
|
||||
|
||||
for (int i = 0; i < v_gold.rows; ++i)
|
||||
f.read(v_gold.ptr<char>(i), v_gold.cols * sizeof(float));
|
||||
|
||||
EXPECT_MAT_NEAR(u_gold, u, 0);
|
||||
EXPECT_MAT_NEAR(v_gold, v, 0);
|
||||
#else
|
||||
std::ofstream f(fname.c_str(), std::ios_base::binary);
|
||||
|
||||
f.write((char*) &u.rows, sizeof(u.rows));
|
||||
f.write((char*) &u.cols, sizeof(u.cols));
|
||||
|
||||
cv::Mat h_u(u);
|
||||
cv::Mat h_v(v);
|
||||
|
||||
for (int i = 0; i < u.rows; ++i)
|
||||
f.write(h_u.ptr<char>(i), u.cols * sizeof(float));
|
||||
|
||||
for (int i = 0; i < v.rows; ++i)
|
||||
f.write(h_v.ptr<char>(i), v.cols * sizeof(float));
|
||||
#endif
|
||||
}
|
||||
|
||||
GPU_TEST_P(BroxOpticalFlow, OpticalFlowNan)
|
||||
{
|
||||
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::Mat r_frame0, r_frame1;
|
||||
cv::resize(frame0, r_frame0, cv::Size(1380,1000));
|
||||
cv::resize(frame1, r_frame1, cv::Size(1380,1000));
|
||||
|
||||
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
|
||||
5 /*inner_iterations*/, 150 /*outer_iterations*/, 10 /*solver_iterations*/);
|
||||
|
||||
cv::gpu::GpuMat u;
|
||||
cv::gpu::GpuMat v;
|
||||
brox(loadMat(r_frame0), loadMat(r_frame1), u, v);
|
||||
|
||||
cv::Mat h_u, h_v;
|
||||
u.download(h_u);
|
||||
v.download(h_v);
|
||||
|
||||
EXPECT_TRUE(cv::checkRange(h_u));
|
||||
EXPECT_TRUE(cv::checkRange(h_v));
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, BroxOpticalFlow, ALL_DEVICES);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// GoodFeaturesToTrack
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(MinDistance, double)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
double minDistance;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
minDistance = GET_PARAM(1);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(GoodFeaturesToTrack, Accuracy)
|
||||
{
|
||||
cv::Mat image = readImage("opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(image.empty());
|
||||
|
||||
int maxCorners = 1000;
|
||||
double qualityLevel = 0.01;
|
||||
|
||||
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance);
|
||||
|
||||
cv::gpu::GpuMat d_pts;
|
||||
detector(loadMat(image), d_pts);
|
||||
|
||||
ASSERT_FALSE(d_pts.empty());
|
||||
|
||||
std::vector<cv::Point2f> pts(d_pts.cols);
|
||||
cv::Mat pts_mat(1, d_pts.cols, CV_32FC2, (void*) &pts[0]);
|
||||
d_pts.download(pts_mat);
|
||||
|
||||
std::vector<cv::Point2f> pts_gold;
|
||||
cv::goodFeaturesToTrack(image, pts_gold, maxCorners, qualityLevel, minDistance);
|
||||
|
||||
ASSERT_EQ(pts_gold.size(), pts.size());
|
||||
|
||||
size_t mistmatch = 0;
|
||||
for (size_t i = 0; i < pts.size(); ++i)
|
||||
{
|
||||
cv::Point2i a = pts_gold[i];
|
||||
cv::Point2i b = pts[i];
|
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1;
|
||||
|
||||
if (!eq)
|
||||
++mistmatch;
|
||||
}
|
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / pts.size();
|
||||
|
||||
ASSERT_LE(bad_ratio, 0.01);
|
||||
}
|
||||
|
||||
GPU_TEST_P(GoodFeaturesToTrack, EmptyCorners)
|
||||
{
|
||||
int maxCorners = 1000;
|
||||
double qualityLevel = 0.01;
|
||||
|
||||
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance);
|
||||
|
||||
cv::gpu::GpuMat src(100, 100, CV_8UC1, cv::Scalar::all(0));
|
||||
cv::gpu::GpuMat corners(1, maxCorners, CV_32FC2);
|
||||
|
||||
detector(src, corners);
|
||||
|
||||
ASSERT_TRUE(corners.empty());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(MinDistance(0.0), MinDistance(3.0))));
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// PyrLKOpticalFlow
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(UseGray, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(PyrLKOpticalFlow, cv::gpu::DeviceInfo, UseGray)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
bool useGray;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
useGray = GET_PARAM(1);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(PyrLKOpticalFlow, Sparse)
|
||||
{
|
||||
cv::Mat frame0 = readImage("opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::Mat gray_frame;
|
||||
if (useGray)
|
||||
gray_frame = frame0;
|
||||
else
|
||||
cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY);
|
||||
|
||||
std::vector<cv::Point2f> pts;
|
||||
cv::goodFeaturesToTrack(gray_frame, pts, 1000, 0.01, 0.0);
|
||||
|
||||
cv::gpu::GpuMat d_pts;
|
||||
cv::Mat pts_mat(1, (int) pts.size(), CV_32FC2, (void*) &pts[0]);
|
||||
d_pts.upload(pts_mat);
|
||||
|
||||
cv::gpu::PyrLKOpticalFlow pyrLK;
|
||||
|
||||
cv::gpu::GpuMat d_nextPts;
|
||||
cv::gpu::GpuMat d_status;
|
||||
pyrLK.sparse(loadMat(frame0), loadMat(frame1), d_pts, d_nextPts, d_status);
|
||||
|
||||
std::vector<cv::Point2f> nextPts(d_nextPts.cols);
|
||||
cv::Mat nextPts_mat(1, d_nextPts.cols, CV_32FC2, (void*) &nextPts[0]);
|
||||
d_nextPts.download(nextPts_mat);
|
||||
|
||||
std::vector<unsigned char> status(d_status.cols);
|
||||
cv::Mat status_mat(1, d_status.cols, CV_8UC1, (void*) &status[0]);
|
||||
d_status.download(status_mat);
|
||||
|
||||
std::vector<cv::Point2f> nextPts_gold;
|
||||
std::vector<unsigned char> status_gold;
|
||||
cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts_gold, status_gold, cv::noArray());
|
||||
|
||||
ASSERT_EQ(nextPts_gold.size(), nextPts.size());
|
||||
ASSERT_EQ(status_gold.size(), status.size());
|
||||
|
||||
size_t mistmatch = 0;
|
||||
for (size_t i = 0; i < nextPts.size(); ++i)
|
||||
{
|
||||
cv::Point2i a = nextPts[i];
|
||||
cv::Point2i b = nextPts_gold[i];
|
||||
|
||||
if (status[i] != status_gold[i])
|
||||
{
|
||||
++mistmatch;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status[i])
|
||||
{
|
||||
bool eq = std::abs(a.x - b.x) <= 1 && std::abs(a.y - b.y) <= 1;
|
||||
|
||||
if (!eq)
|
||||
++mistmatch;
|
||||
}
|
||||
}
|
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / nextPts.size();
|
||||
|
||||
ASSERT_LE(bad_ratio, 0.01);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, PyrLKOpticalFlow, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(UseGray(true), UseGray(false))));
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FarnebackOpticalFlow
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(PyrScale, double)
|
||||
IMPLEMENT_PARAM_CLASS(PolyN, int)
|
||||
CV_FLAGS(FarnebackOptFlowFlags, 0, OPTFLOW_FARNEBACK_GAUSSIAN)
|
||||
IMPLEMENT_PARAM_CLASS(UseInitFlow, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(FarnebackOpticalFlow, cv::gpu::DeviceInfo, PyrScale, PolyN, FarnebackOptFlowFlags, UseInitFlow)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
double pyrScale;
|
||||
int polyN;
|
||||
int flags;
|
||||
bool useInitFlow;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
pyrScale = GET_PARAM(1);
|
||||
polyN = GET_PARAM(2);
|
||||
flags = GET_PARAM(3);
|
||||
useInitFlow = GET_PARAM(4);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(FarnebackOpticalFlow, Accuracy)
|
||||
{
|
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
double polySigma = polyN <= 5 ? 1.1 : 1.5;
|
||||
|
||||
cv::gpu::FarnebackOpticalFlow farn;
|
||||
farn.pyrScale = pyrScale;
|
||||
farn.polyN = polyN;
|
||||
farn.polySigma = polySigma;
|
||||
farn.flags = flags;
|
||||
|
||||
cv::gpu::GpuMat d_flowx, d_flowy;
|
||||
farn(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy);
|
||||
|
||||
cv::Mat flow;
|
||||
if (useInitFlow)
|
||||
{
|
||||
cv::Mat flowxy[] = {cv::Mat(d_flowx), cv::Mat(d_flowy)};
|
||||
cv::merge(flowxy, 2, flow);
|
||||
|
||||
farn.flags |= cv::OPTFLOW_USE_INITIAL_FLOW;
|
||||
farn(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy);
|
||||
}
|
||||
|
||||
cv::calcOpticalFlowFarneback(
|
||||
frame0, frame1, flow, farn.pyrScale, farn.numLevels, farn.winSize,
|
||||
farn.numIters, farn.polyN, farn.polySigma, farn.flags);
|
||||
|
||||
std::vector<cv::Mat> flowxy;
|
||||
cv::split(flow, flowxy);
|
||||
|
||||
EXPECT_MAT_SIMILAR(flowxy[0], d_flowx, 0.1);
|
||||
EXPECT_MAT_SIMILAR(flowxy[1], d_flowy, 0.1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(PyrScale(0.3), PyrScale(0.5), PyrScale(0.8)),
|
||||
testing::Values(PolyN(5), PolyN(7)),
|
||||
testing::Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)),
|
||||
testing::Values(UseInitFlow(false), UseInitFlow(true))));
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// OpticalFlowDual_TVL1
|
||||
|
||||
PARAM_TEST_CASE(OpticalFlowDual_TVL1, cv::gpu::DeviceInfo, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
useRoi = GET_PARAM(1);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(OpticalFlowDual_TVL1, Accuracy)
|
||||
{
|
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::gpu::OpticalFlowDual_TVL1_GPU d_alg;
|
||||
cv::gpu::GpuMat d_flowx = createMat(frame0.size(), CV_32FC1, useRoi);
|
||||
cv::gpu::GpuMat d_flowy = createMat(frame0.size(), CV_32FC1, useRoi);
|
||||
d_alg(loadMat(frame0, useRoi), loadMat(frame1, useRoi), d_flowx, d_flowy);
|
||||
|
||||
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
|
||||
alg->set("medianFiltering", 1);
|
||||
alg->set("innerIterations", 1);
|
||||
alg->set("outerIterations", d_alg.iterations);
|
||||
cv::Mat flow;
|
||||
alg->calc(frame0, frame1, flow);
|
||||
cv::Mat gold[2];
|
||||
cv::split(flow, gold);
|
||||
|
||||
EXPECT_MAT_SIMILAR(gold[0], d_flowx, 4e-3);
|
||||
EXPECT_MAT_SIMILAR(gold[1], d_flowy, 4e-3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowDual_TVL1, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// OpticalFlowBM
|
||||
|
||||
namespace
|
||||
{
|
||||
void calcOpticalFlowBM(const cv::Mat& prev, const cv::Mat& curr,
|
||||
cv::Size bSize, cv::Size shiftSize, cv::Size maxRange, int usePrevious,
|
||||
cv::Mat& velx, cv::Mat& vely)
|
||||
{
|
||||
cv::Size sz((curr.cols - bSize.width + shiftSize.width)/shiftSize.width, (curr.rows - bSize.height + shiftSize.height)/shiftSize.height);
|
||||
|
||||
velx.create(sz, CV_32FC1);
|
||||
vely.create(sz, CV_32FC1);
|
||||
|
||||
CvMat cvprev = prev;
|
||||
CvMat cvcurr = curr;
|
||||
|
||||
CvMat cvvelx = velx;
|
||||
CvMat cvvely = vely;
|
||||
|
||||
cvCalcOpticalFlowBM(&cvprev, &cvcurr, bSize, shiftSize, maxRange, usePrevious, &cvvelx, &cvvely);
|
||||
}
|
||||
}
|
||||
|
||||
struct OpticalFlowBM : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
};
|
||||
|
||||
GPU_TEST_P(OpticalFlowBM, Accuracy)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo = GetParam();
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::Size block_size(16, 16);
|
||||
cv::Size shift_size(1, 1);
|
||||
cv::Size max_range(16, 16);
|
||||
|
||||
cv::gpu::GpuMat d_velx, d_vely, buf;
|
||||
cv::gpu::calcOpticalFlowBM(loadMat(frame0), loadMat(frame1),
|
||||
block_size, shift_size, max_range, false,
|
||||
d_velx, d_vely, buf);
|
||||
|
||||
cv::Mat velx, vely;
|
||||
calcOpticalFlowBM(frame0, frame1, block_size, shift_size, max_range, false, velx, vely);
|
||||
|
||||
EXPECT_MAT_NEAR(velx, d_velx, 0);
|
||||
EXPECT_MAT_NEAR(vely, d_vely, 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowBM, ALL_DEVICES);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FastOpticalFlowBM
|
||||
|
||||
namespace
|
||||
{
|
||||
void FastOpticalFlowBM_gold(const cv::Mat_<uchar>& I0, const cv::Mat_<uchar>& I1, cv::Mat_<float>& velx, cv::Mat_<float>& vely, int search_window, int block_window)
|
||||
{
|
||||
velx.create(I0.size());
|
||||
vely.create(I0.size());
|
||||
|
||||
int search_radius = search_window / 2;
|
||||
int block_radius = block_window / 2;
|
||||
|
||||
for (int y = 0; y < I0.rows; ++y)
|
||||
{
|
||||
for (int x = 0; x < I0.cols; ++x)
|
||||
{
|
||||
int bestDist = std::numeric_limits<int>::max();
|
||||
int bestDx = 0;
|
||||
int bestDy = 0;
|
||||
|
||||
for (int dy = -search_radius; dy <= search_radius; ++dy)
|
||||
{
|
||||
for (int dx = -search_radius; dx <= search_radius; ++dx)
|
||||
{
|
||||
int dist = 0;
|
||||
|
||||
for (int by = -block_radius; by <= block_radius; ++by)
|
||||
{
|
||||
for (int bx = -block_radius; bx <= block_radius; ++bx)
|
||||
{
|
||||
int I0_val = I0(cv::borderInterpolate(y + by, I0.rows, cv::BORDER_DEFAULT), cv::borderInterpolate(x + bx, I0.cols, cv::BORDER_DEFAULT));
|
||||
int I1_val = I1(cv::borderInterpolate(y + dy + by, I0.rows, cv::BORDER_DEFAULT), cv::borderInterpolate(x + dx + bx, I0.cols, cv::BORDER_DEFAULT));
|
||||
|
||||
dist += std::abs(I0_val - I1_val);
|
||||
}
|
||||
}
|
||||
|
||||
if (dist < bestDist)
|
||||
{
|
||||
bestDist = dist;
|
||||
bestDx = dx;
|
||||
bestDy = dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
velx(y, x) = (float) bestDx;
|
||||
vely(y, x) = (float) bestDy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double calc_rmse(const cv::Mat_<float>& flow1, const cv::Mat_<float>& flow2)
|
||||
{
|
||||
double sum = 0.0;
|
||||
|
||||
for (int y = 0; y < flow1.rows; ++y)
|
||||
{
|
||||
for (int x = 0; x < flow1.cols; ++x)
|
||||
{
|
||||
double diff = flow1(y, x) - flow2(y, x);
|
||||
sum += diff * diff;
|
||||
}
|
||||
}
|
||||
|
||||
return std::sqrt(sum / flow1.size().area());
|
||||
}
|
||||
}
|
||||
|
||||
struct FastOpticalFlowBM : testing::TestWithParam<cv::gpu::DeviceInfo>
|
||||
{
|
||||
};
|
||||
|
||||
GPU_TEST_P(FastOpticalFlowBM, Accuracy)
|
||||
{
|
||||
const double MAX_RMSE = 0.6;
|
||||
|
||||
int search_window = 15;
|
||||
int block_window = 5;
|
||||
|
||||
cv::gpu::DeviceInfo devInfo = GetParam();
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame0.empty());
|
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame1.empty());
|
||||
|
||||
cv::Size smallSize(320, 240);
|
||||
cv::Mat frame0_small;
|
||||
cv::Mat frame1_small;
|
||||
|
||||
cv::resize(frame0, frame0_small, smallSize);
|
||||
cv::resize(frame1, frame1_small, smallSize);
|
||||
|
||||
cv::gpu::GpuMat d_flowx;
|
||||
cv::gpu::GpuMat d_flowy;
|
||||
cv::gpu::FastOpticalFlowBM fastBM;
|
||||
|
||||
fastBM(loadMat(frame0_small), loadMat(frame1_small), d_flowx, d_flowy, search_window, block_window);
|
||||
|
||||
cv::Mat_<float> flowx;
|
||||
cv::Mat_<float> flowy;
|
||||
FastOpticalFlowBM_gold(frame0_small, frame1_small, flowx, flowy, search_window, block_window);
|
||||
|
||||
double err;
|
||||
|
||||
err = calc_rmse(flowx, cv::Mat(d_flowx));
|
||||
EXPECT_LE(err, MAX_RMSE);
|
||||
|
||||
err = calc_rmse(flowy, cv::Mat(d_flowy));
|
||||
EXPECT_LE(err, MAX_RMSE);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, FastOpticalFlowBM, ALL_DEVICES);
|
||||
|
||||
#endif // HAVE_CUDA
|
@@ -51,15 +51,32 @@
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/gpu_test.hpp"
|
||||
|
||||
#include "opencv2/gpu.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/opengl.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/video.hpp"
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/gpu_test.hpp"
|
||||
#include "opencv2/gpu.hpp"
|
||||
|
||||
#include "interpolation.hpp"
|
||||
#include "main_test_nvidia.h"
|
||||
|
||||
#include "opencv2/core/gpu_private.hpp"
|
||||
|
||||
#endif
|
||||
|
129
modules/gpu/test/test_pyramids.cpp
Normal file
129
modules/gpu/test/test_pyramids.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// pyrDown
|
||||
|
||||
PARAM_TEST_CASE(PyrDown, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(PyrDown, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size((size.width + 1) / 2, (size.height + 1) / 2), type, useRoi);
|
||||
cv::gpu::pyrDown(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::pyrDown(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrDown, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// pyrUp
|
||||
|
||||
PARAM_TEST_CASE(PyrUp, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(PyrUp, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(size.width * 2, size.height * 2), type, useRoi);
|
||||
cv::gpu::pyrUp(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::pyrUp(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrUp, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
180
modules/gpu/test/test_remap.cpp
Normal file
180
modules/gpu/test/test_remap.cpp
Normal 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.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, template <typename> class Interpolator> void remapImpl(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
const int cn = src.channels();
|
||||
|
||||
cv::Size dsize = xmap.size();
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
|
||||
for (int y = 0; y < dsize.height; ++y)
|
||||
{
|
||||
for (int x = 0; x < dsize.width; ++x)
|
||||
{
|
||||
for (int c = 0; c < cn; ++c)
|
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ymap.at<float>(y, x), xmap.at<float>(y, x), c, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remapGold(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal);
|
||||
|
||||
static const func_t nearest_funcs[] =
|
||||
{
|
||||
remapImpl<unsigned char, NearestInterpolator>,
|
||||
remapImpl<signed char, NearestInterpolator>,
|
||||
remapImpl<unsigned short, NearestInterpolator>,
|
||||
remapImpl<short, NearestInterpolator>,
|
||||
remapImpl<int, NearestInterpolator>,
|
||||
remapImpl<float, NearestInterpolator>
|
||||
};
|
||||
|
||||
static const func_t linear_funcs[] =
|
||||
{
|
||||
remapImpl<unsigned char, LinearInterpolator>,
|
||||
remapImpl<signed char, LinearInterpolator>,
|
||||
remapImpl<unsigned short, LinearInterpolator>,
|
||||
remapImpl<short, LinearInterpolator>,
|
||||
remapImpl<int, LinearInterpolator>,
|
||||
remapImpl<float, LinearInterpolator>
|
||||
};
|
||||
|
||||
static const func_t cubic_funcs[] =
|
||||
{
|
||||
remapImpl<unsigned char, CubicInterpolator>,
|
||||
remapImpl<signed char, CubicInterpolator>,
|
||||
remapImpl<unsigned short, CubicInterpolator>,
|
||||
remapImpl<short, CubicInterpolator>,
|
||||
remapImpl<int, CubicInterpolator>,
|
||||
remapImpl<float, CubicInterpolator>
|
||||
};
|
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
|
||||
|
||||
funcs[interpolation][src.depth()](src, xmap, ymap, dst, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int interpolation;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
cv::Mat xmap;
|
||||
cv::Mat ymap;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
interpolation = GET_PARAM(3);
|
||||
borderType = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
// rotation matrix
|
||||
|
||||
const double aplha = CV_PI / 4;
|
||||
static double M[2][3] = { {std::cos(aplha), -std::sin(aplha), size.width / 2.0},
|
||||
{std::sin(aplha), std::cos(aplha), 0.0}};
|
||||
|
||||
xmap.create(size, CV_32FC1);
|
||||
ymap.create(size, CV_32FC1);
|
||||
|
||||
for (int y = 0; y < size.height; ++y)
|
||||
{
|
||||
for (int x = 0; x < size.width; ++x)
|
||||
{
|
||||
xmap.at<float>(y, x) = static_cast<float>(M[0][0] * x + M[0][1] * y + M[0][2]);
|
||||
ymap.at<float>(y, x) = static_cast<float>(M[1][0] * x + M[1][1] * y + M[1][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Remap, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(xmap.size(), type, useRoi);
|
||||
cv::gpu::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Remap, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
250
modules/gpu/test/test_resize.cpp
Normal file
250
modules/gpu/test/test_resize.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, template <typename> class Interpolator>
|
||||
void resizeImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
|
||||
{
|
||||
const int cn = src.channels();
|
||||
|
||||
cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy));
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
|
||||
float ifx = static_cast<float>(1.0 / fx);
|
||||
float ify = static_cast<float>(1.0 / fy);
|
||||
|
||||
for (int y = 0; y < dsize.height; ++y)
|
||||
{
|
||||
for (int x = 0; x < dsize.width; ++x)
|
||||
{
|
||||
for (int c = 0; c < cn; ++c)
|
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, y * ify, x * ifx, c, cv::BORDER_REPLICATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resizeGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy, int interpolation)
|
||||
{
|
||||
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy);
|
||||
|
||||
static const func_t nearest_funcs[] =
|
||||
{
|
||||
resizeImpl<unsigned char, NearestInterpolator>,
|
||||
resizeImpl<signed char, NearestInterpolator>,
|
||||
resizeImpl<unsigned short, NearestInterpolator>,
|
||||
resizeImpl<short, NearestInterpolator>,
|
||||
resizeImpl<int, NearestInterpolator>,
|
||||
resizeImpl<float, NearestInterpolator>
|
||||
};
|
||||
|
||||
|
||||
static const func_t linear_funcs[] =
|
||||
{
|
||||
resizeImpl<unsigned char, LinearInterpolator>,
|
||||
resizeImpl<signed char, LinearInterpolator>,
|
||||
resizeImpl<unsigned short, LinearInterpolator>,
|
||||
resizeImpl<short, LinearInterpolator>,
|
||||
resizeImpl<int, LinearInterpolator>,
|
||||
resizeImpl<float, LinearInterpolator>
|
||||
};
|
||||
|
||||
static const func_t cubic_funcs[] =
|
||||
{
|
||||
resizeImpl<unsigned char, CubicInterpolator>,
|
||||
resizeImpl<signed char, CubicInterpolator>,
|
||||
resizeImpl<unsigned short, CubicInterpolator>,
|
||||
resizeImpl<short, CubicInterpolator>,
|
||||
resizeImpl<int, CubicInterpolator>,
|
||||
resizeImpl<float, CubicInterpolator>
|
||||
};
|
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
|
||||
|
||||
funcs[interpolation][src.depth()](src, dst, fx, fy);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
double coeff;
|
||||
int interpolation;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
coeff = GET_PARAM(3);
|
||||
interpolation = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Resize, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
|
||||
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
resizeGold(src, dst_gold, coeff, coeff, interpolation);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
testing::Values(0.3, 0.5, 1.5, 2.0),
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
/////////////////
|
||||
|
||||
PARAM_TEST_CASE(ResizeSameAsHost, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
double coeff;
|
||||
int interpolation;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
coeff = GET_PARAM(3);
|
||||
interpolation = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
// downscaling only: used for classifiers
|
||||
GPU_TEST_P(ResizeSameAsHost, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
|
||||
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
testing::Values(0.3, 0.5),
|
||||
testing::Values(Interpolation(cv::INTER_AREA), Interpolation(cv::INTER_NEAREST)), //, Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
double coeff;
|
||||
int interpolation;
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
coeff = GET_PARAM(2);
|
||||
interpolation = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(ResizeNPP, Accuracy)
|
||||
{
|
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
|
||||
ASSERT_FALSE(src.empty());
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
resizeGold(src, dst_gold, coeff, coeff, interpolation);
|
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
|
||||
testing::Values(0.3, 0.5, 1.5, 2.0),
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR))));
|
||||
|
||||
#endif // HAVE_CUDA
|
93
modules/gpu/test/test_threshold.cpp
Normal file
93
modules/gpu/test/test_threshold.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
|
||||
|
||||
PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int threshOp;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
threshOp = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(Threshold, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
double maxVal = randomDouble(20.0, 127.0);
|
||||
double thresh = randomDouble(0.0, maxVal);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(src.size(), src.type(), useRoi);
|
||||
cv::gpu::threshold(loadMat(src, useRoi), dst, thresh, maxVal, threshOp);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::threshold(src, dst_gold, thresh, maxVal, threshOp);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Threshold, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_16SC1), MatType(CV_32FC1)),
|
||||
ThreshOp::all(),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
#endif // HAVE_CUDA
|
153
modules/gpu/test/test_video.cpp
Normal file
153
modules/gpu/test/test_video.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#if defined(HAVE_CUDA) && defined(HAVE_NVCUVID)
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// VideoReader
|
||||
|
||||
PARAM_TEST_CASE(VideoReader, cv::gpu::DeviceInfo, std::string)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
inputFile = GET_PARAM(1);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile;
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(VideoReader, Regression)
|
||||
{
|
||||
cv::gpu::VideoReader_GPU reader(inputFile);
|
||||
ASSERT_TRUE(reader.isOpened());
|
||||
|
||||
cv::gpu::GpuMat frame;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
ASSERT_TRUE(reader.read(frame));
|
||||
ASSERT_FALSE(frame.empty());
|
||||
}
|
||||
|
||||
reader.close();
|
||||
ASSERT_FALSE(reader.isOpened());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoReader, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// VideoWriter
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
PARAM_TEST_CASE(VideoWriter, cv::gpu::DeviceInfo, std::string)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
inputFile = GET_PARAM(1);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + std::string("video/") + inputFile;
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(VideoWriter, Regression)
|
||||
{
|
||||
std::string outputFile = cv::tempfile(".avi");
|
||||
const double FPS = 25.0;
|
||||
|
||||
cv::VideoCapture reader(inputFile);
|
||||
ASSERT_TRUE(reader.isOpened());
|
||||
|
||||
cv::gpu::VideoWriter_GPU d_writer;
|
||||
|
||||
cv::Mat frame;
|
||||
cv::gpu::GpuMat d_frame;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
reader >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
d_frame.upload(frame);
|
||||
|
||||
if (!d_writer.isOpened())
|
||||
d_writer.open(outputFile, frame.size(), FPS);
|
||||
|
||||
d_writer.write(d_frame);
|
||||
}
|
||||
|
||||
reader.release();
|
||||
d_writer.close();
|
||||
|
||||
reader.open(outputFile);
|
||||
ASSERT_TRUE(reader.isOpened());
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
reader >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoWriter, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#endif // defined(HAVE_CUDA) && defined(HAVE_NVCUVID)
|
280
modules/gpu/test/test_warp_affine.cpp
Normal file
280
modules/gpu/test/test_warp_affine.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
namespace
|
||||
{
|
||||
cv::Mat createTransfomMatrix(cv::Size srcSize, double angle)
|
||||
{
|
||||
cv::Mat M(2, 3, CV_64FC1);
|
||||
|
||||
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2;
|
||||
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0;
|
||||
|
||||
return M;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test buildWarpAffineMaps
|
||||
|
||||
PARAM_TEST_CASE(BuildWarpAffineMaps, cv::gpu::DeviceInfo, cv::Size, Inverse)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
bool inverse;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
inverse = GET_PARAM(2);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BuildWarpAffineMaps, Accuracy)
|
||||
{
|
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
|
||||
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
|
||||
|
||||
cv::gpu::GpuMat xmap, ymap;
|
||||
cv::gpu::buildWarpAffineMaps(M, inverse, size, xmap, ymap);
|
||||
|
||||
int interpolation = cv::INTER_NEAREST;
|
||||
int borderMode = cv::BORDER_CONSTANT;
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
|
||||
cv::Mat dst;
|
||||
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::warpAffine(src, dst_gold, M, size, flags, borderMode);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpAffineMaps, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
DIRECT_INVERSE));
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, template <typename> class Interpolator> void warpAffineImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
const int cn = src.channels();
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
|
||||
for (int y = 0; y < dsize.height; ++y)
|
||||
{
|
||||
for (int x = 0; x < dsize.width; ++x)
|
||||
{
|
||||
float xcoo = static_cast<float>(M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2));
|
||||
float ycoo = static_cast<float>(M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2));
|
||||
|
||||
for (int c = 0; c < cn; ++c)
|
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void warpAffineGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal);
|
||||
|
||||
static const func_t nearest_funcs[] =
|
||||
{
|
||||
warpAffineImpl<unsigned char, NearestInterpolator>,
|
||||
warpAffineImpl<signed char, NearestInterpolator>,
|
||||
warpAffineImpl<unsigned short, NearestInterpolator>,
|
||||
warpAffineImpl<short, NearestInterpolator>,
|
||||
warpAffineImpl<int, NearestInterpolator>,
|
||||
warpAffineImpl<float, NearestInterpolator>
|
||||
};
|
||||
|
||||
static const func_t linear_funcs[] =
|
||||
{
|
||||
warpAffineImpl<unsigned char, LinearInterpolator>,
|
||||
warpAffineImpl<signed char, LinearInterpolator>,
|
||||
warpAffineImpl<unsigned short, LinearInterpolator>,
|
||||
warpAffineImpl<short, LinearInterpolator>,
|
||||
warpAffineImpl<int, LinearInterpolator>,
|
||||
warpAffineImpl<float, LinearInterpolator>
|
||||
};
|
||||
|
||||
static const func_t cubic_funcs[] =
|
||||
{
|
||||
warpAffineImpl<unsigned char, CubicInterpolator>,
|
||||
warpAffineImpl<signed char, CubicInterpolator>,
|
||||
warpAffineImpl<unsigned short, CubicInterpolator>,
|
||||
warpAffineImpl<short, CubicInterpolator>,
|
||||
warpAffineImpl<int, CubicInterpolator>,
|
||||
warpAffineImpl<float, CubicInterpolator>
|
||||
};
|
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
|
||||
|
||||
if (inverse)
|
||||
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal);
|
||||
else
|
||||
{
|
||||
cv::Mat iM;
|
||||
cv::invertAffineTransform(M, iM);
|
||||
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool inverse;
|
||||
int interpolation;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
inverse = GET_PARAM(3);
|
||||
interpolation = GET_PARAM(4);
|
||||
borderType = GET_PARAM(5);
|
||||
useRoi = GET_PARAM(6);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(WarpAffine, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::warpAffine(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
warpAffineGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffine, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
DIRECT_INVERSE,
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(WarpAffineNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolation)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
int type;
|
||||
bool inverse;
|
||||
int interpolation;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
inverse = GET_PARAM(2);
|
||||
interpolation = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(WarpAffineNPP, Accuracy)
|
||||
{
|
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
|
||||
ASSERT_FALSE(src.empty());
|
||||
|
||||
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::warpAffine(loadMat(src), dst, M, src.size(), flags);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
warpAffineGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
|
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffineNPP, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
DIRECT_INVERSE,
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
|
||||
|
||||
#endif // HAVE_CUDA
|
283
modules/gpu/test/test_warp_perspective.cpp
Normal file
283
modules/gpu/test/test_warp_perspective.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
|
||||
namespace
|
||||
{
|
||||
cv::Mat createTransfomMatrix(cv::Size srcSize, double angle)
|
||||
{
|
||||
cv::Mat M(3, 3, CV_64FC1);
|
||||
|
||||
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2;
|
||||
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0;
|
||||
M.at<double>(2, 0) = 0.0 ; M.at<double>(2, 1) = 0.0 ; M.at<double>(2, 2) = 1.0;
|
||||
|
||||
return M;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test buildWarpPerspectiveMaps
|
||||
|
||||
PARAM_TEST_CASE(BuildWarpPerspectiveMaps, cv::gpu::DeviceInfo, cv::Size, Inverse)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
bool inverse;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
inverse = GET_PARAM(2);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(BuildWarpPerspectiveMaps, Accuracy)
|
||||
{
|
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
|
||||
|
||||
cv::gpu::GpuMat xmap, ymap;
|
||||
cv::gpu::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap);
|
||||
|
||||
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
|
||||
int interpolation = cv::INTER_NEAREST;
|
||||
int borderMode = cv::BORDER_CONSTANT;
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
|
||||
cv::Mat dst;
|
||||
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::warpPerspective(src, dst_gold, M, size, flags, borderMode);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpPerspectiveMaps, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
DIRECT_INVERSE));
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, template <typename> class Interpolator> void warpPerspectiveImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
const int cn = src.channels();
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
|
||||
for (int y = 0; y < dsize.height; ++y)
|
||||
{
|
||||
for (int x = 0; x < dsize.width; ++x)
|
||||
{
|
||||
float coeff = static_cast<float>(M.at<double>(2, 0) * x + M.at<double>(2, 1) * y + M.at<double>(2, 2));
|
||||
|
||||
float xcoo = static_cast<float>((M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2)) / coeff);
|
||||
float ycoo = static_cast<float>((M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2)) / coeff);
|
||||
|
||||
for (int c = 0; c < cn; ++c)
|
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void warpPerspectiveGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal)
|
||||
{
|
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal);
|
||||
|
||||
static const func_t nearest_funcs[] =
|
||||
{
|
||||
warpPerspectiveImpl<unsigned char, NearestInterpolator>,
|
||||
warpPerspectiveImpl<signed char, NearestInterpolator>,
|
||||
warpPerspectiveImpl<unsigned short, NearestInterpolator>,
|
||||
warpPerspectiveImpl<short, NearestInterpolator>,
|
||||
warpPerspectiveImpl<int, NearestInterpolator>,
|
||||
warpPerspectiveImpl<float, NearestInterpolator>
|
||||
};
|
||||
|
||||
static const func_t linear_funcs[] =
|
||||
{
|
||||
warpPerspectiveImpl<unsigned char, LinearInterpolator>,
|
||||
warpPerspectiveImpl<signed char, LinearInterpolator>,
|
||||
warpPerspectiveImpl<unsigned short, LinearInterpolator>,
|
||||
warpPerspectiveImpl<short, LinearInterpolator>,
|
||||
warpPerspectiveImpl<int, LinearInterpolator>,
|
||||
warpPerspectiveImpl<float, LinearInterpolator>
|
||||
};
|
||||
|
||||
static const func_t cubic_funcs[] =
|
||||
{
|
||||
warpPerspectiveImpl<unsigned char, CubicInterpolator>,
|
||||
warpPerspectiveImpl<signed char, CubicInterpolator>,
|
||||
warpPerspectiveImpl<unsigned short, CubicInterpolator>,
|
||||
warpPerspectiveImpl<short, CubicInterpolator>,
|
||||
warpPerspectiveImpl<int, CubicInterpolator>,
|
||||
warpPerspectiveImpl<float, CubicInterpolator>
|
||||
};
|
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
|
||||
|
||||
if (inverse)
|
||||
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal);
|
||||
else
|
||||
{
|
||||
cv::Mat iM;
|
||||
cv::invert(M, iM);
|
||||
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, BorderType, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool inverse;
|
||||
int interpolation;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
inverse = GET_PARAM(3);
|
||||
interpolation = GET_PARAM(4);
|
||||
borderType = GET_PARAM(5);
|
||||
useRoi = GET_PARAM(6);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(WarpPerspective, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::gpu::warpPerspective(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
warpPerspectiveGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspective, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
DIRECT_INVERSE,
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
|
||||
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(WarpPerspectiveNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolation)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
int type;
|
||||
bool inverse;
|
||||
int interpolation;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
inverse = GET_PARAM(2);
|
||||
interpolation = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
GPU_TEST_P(WarpPerspectiveNPP, Accuracy)
|
||||
{
|
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
|
||||
ASSERT_FALSE(src.empty());
|
||||
|
||||
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
|
||||
int flags = interpolation;
|
||||
if (inverse)
|
||||
flags |= cv::WARP_INVERSE_MAP;
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::warpPerspective(loadMat(src), dst, M, src.size(), flags);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
warpPerspectiveGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
|
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspectiveNPP, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
|
||||
DIRECT_INVERSE,
|
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
|
||||
|
||||
#endif // HAVE_CUDA
|
Reference in New Issue
Block a user