Commit d1b4b5f0 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored gpu module tests

parent 6e3142f0
......@@ -124,6 +124,8 @@ namespace cv
// Checks whether the GPU module can be run on the given device
bool isCompatible() const;
int deviceID() const { return device_id_; }
private:
void query();
void queryMemory(size_t& free_memory, size_t& total_memory) const;
......@@ -517,14 +519,14 @@ namespace cv
//! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream = Stream::Null());
//! multiplies matrix to a scalar (c = a * s)
//! supports CV_32FC1 and CV_32FC2 type
//! supports CV_32FC1 type
CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c, Stream& stream = Stream::Null());
//! computes element-wise quotient of the two arrays (c = a / b)
//! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream = Stream::Null());
//! computes element-wise quotient of matrix and scalar (c = a / s)
//! supports CV_32FC1 and CV_32FC2 type
//! supports CV_32FC1 type
CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c, Stream& stream = Stream::Null());
//! computes exponent of each matrix element (b = e**a)
......@@ -1412,9 +1414,9 @@ namespace cv
void radiusMatch(const GpuMat& queryDescs, std::vector< std::vector<DMatch> >& matches, float maxDistance,
const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
private:
DistType distType;
private:
std::vector<GpuMat> trainDescCollection;
};
......
This diff is collapsed.
......@@ -646,9 +646,9 @@ namespace cv { namespace gpu { namespace bfmatcher
matchCached_caller<16, 16, 64, true, Dist>(queryDescs, train, mask, trainIdx, imgIdx, distance, stream);
else if (queryDescs.cols < 128)
matchCached_caller<16, 16, 128, false, Dist>(queryDescs, train, mask, trainIdx, imgIdx, distance, stream);
else if (queryDescs.cols == 128)
else if (queryDescs.cols == 128 && cc_12)
matchCached_caller<16, 16, 128, true, Dist>(queryDescs, train, mask, trainIdx, imgIdx, distance, stream);
else if (queryDescs.cols < 256)
else if (queryDescs.cols < 256 && cc_12)
matchCached_caller<16, 16, 256, false, Dist>(queryDescs, train, mask, trainIdx, imgIdx, distance, stream);
else if (queryDescs.cols == 256 && cc_12)
matchCached_caller<16, 16, 256, true, Dist>(queryDescs, train, mask, trainIdx, imgIdx, distance, stream);
......
......@@ -82,7 +82,9 @@ namespace cv { namespace gpu { namespace mathfunc
{
static __device__ __forceinline__ void calc(int x, int y, float x_data, float y_data, float* dst, size_t dst_step, float scale)
{
dst[y * dst_step + x] = scale * atan2f(y_data, x_data);
float angle = atan2f(y_data, x_data);
angle += (angle < 0) * 2.0 * CV_PI;
dst[y * dst_step + x] = scale * angle;
}
};
template <typename Mag, typename Angle>
......
......@@ -211,22 +211,42 @@ void cv::gpu::subtract(const GpuMat& src, const Scalar& sc, GpuMat& dst, Stream&
void cv::gpu::multiply(const GpuMat& src, const Scalar& sc, GpuMat& dst, Stream& stream)
{
typedef void (*caller_t)(const GpuMat& src, const Scalar& sc, GpuMat& dst, cudaStream_t stream);
static const caller_t callers[] = {0, NppArithmScalar<1, nppiMulC_32f_C1R>::calc, NppArithmScalar<2, nppiMulC_32fc_C1R>::calc};
CV_Assert(src.type() == CV_32FC1);
CV_Assert(src.type() == CV_32FC1 || src.type() == CV_32FC2);
dst.create(src.size(), src.type());
callers[src.channels()](src, sc, dst, StreamAccessor::getStream(stream));
NppiSize sz;
sz.width = src.cols;
sz.height = src.rows;
cudaStream_t cudaStream = StreamAccessor::getStream(stream);
NppStreamHandler h(cudaStream);
nppSafeCall( nppiMulC_32f_C1R(src.ptr<Npp32f>(), src.step, (Npp32f)sc[0], dst.ptr<Npp32f>(), dst.step, sz) );
if (cudaStream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
void cv::gpu::divide(const GpuMat& src, const Scalar& sc, GpuMat& dst, Stream& stream)
{
typedef void (*caller_t)(const GpuMat& src, const Scalar& sc, GpuMat& dst, cudaStream_t stream);
static const caller_t callers[] = {0, NppArithmScalar<1, nppiDivC_32f_C1R>::calc, NppArithmScalar<2, nppiDivC_32fc_C1R>::calc};
CV_Assert(src.type() == CV_32FC1);
CV_Assert(src.type() == CV_32FC1 || src.type() == CV_32FC2);
dst.create(src.size(), src.type());
callers[src.channels()](src, sc, dst, StreamAccessor::getStream(stream));
NppiSize sz;
sz.width = src.cols;
sz.height = src.rows;
cudaStream_t cudaStream = StreamAccessor::getStream(stream);
NppStreamHandler h(cudaStream);
nppSafeCall( nppiDivC_32f_C1R(src.ptr<Npp32f>(), src.step, (Npp32f)sc[0], dst.ptr<Npp32f>(), dst.step, sz) );
if (cudaStream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
......
......@@ -15,15 +15,22 @@
#include "NCVTest.hpp"
enum OutputLevel
{
OutputLevelNone,
OutputLevelCompact,
OutputLevelFull
};
class NCVAutoTestLister
{
public:
NCVAutoTestLister(std::string testSuiteName, NcvBool bStopOnFirstFail=false, NcvBool bCompactOutput=true)
NCVAutoTestLister(std::string testSuiteName, OutputLevel outputLevel = OutputLevelCompact, NcvBool bStopOnFirstFail=false)
:
testSuiteName(testSuiteName),
bStopOnFirstFail(bStopOnFirstFail),
bCompactOutput(bCompactOutput)
outputLevel(outputLevel),
bStopOnFirstFail(bStopOnFirstFail)
{
}
......@@ -38,7 +45,7 @@ public:
Ncv32u nFailed = 0;
Ncv32u nFailedMem = 0;
if (bCompactOutput)
if (outputLevel == OutputLevelCompact)
{
printf("Test suite '%s' with %d tests\n",
testSuiteName.c_str(),
......@@ -52,7 +59,7 @@ public:
NCVTestReport curReport;
bool res = curTest.executeTest(curReport);
if (!bCompactOutput)
if (outputLevel == OutputLevelFull)
{
printf("Test %3i %16s; Consumed mem GPU = %8d, CPU = %8d; %s\n",
i,
......@@ -65,7 +72,7 @@ public:
if (res)
{
nPassed++;
if (bCompactOutput)
if (outputLevel == OutputLevelCompact)
{
printf(".");
}
......@@ -75,7 +82,7 @@ public:
if (!curReport.statsText["rcode"].compare("FAILED"))
{
nFailed++;
if (bCompactOutput)
if (outputLevel == OutputLevelCompact)
{
printf("x");
}
......@@ -87,7 +94,7 @@ public:
else
{
nFailedMem++;
if (bCompactOutput)
if (outputLevel == OutputLevelCompact)
{
printf("m");
}
......@@ -95,17 +102,20 @@ public:
}
fflush(stdout);
}
if (bCompactOutput)
if (outputLevel == OutputLevelCompact)
{
printf("\n");
}
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);
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;
......@@ -121,9 +131,9 @@ public:
private:
NcvBool bStopOnFirstFail;
NcvBool bCompactOutput;
std::string testSuiteName;
OutputLevel outputLevel;
NcvBool bStopOnFirstFail;
std::vector<INCVTest *> tests;
};
......
......@@ -288,70 +288,162 @@ static void devNullOutput(const char *msg)
}
bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
{
path = test_data_path;
ncvSetDebugOutputHandler(devNullOutput);
bool main_nvidia(const std::string& test_data_path)
NCVAutoTestLister testListerII("NPPST Integral Image", outputLevel);
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 4096, 4096);
NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 4096, 4096);
generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 4096, 4096);
generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 4096, 4096);
return testListerII.invoke();
}
bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
{
path = test_data_path;
ncvSetDebugOutputHandler(devNullOutput);
printf("Testing NVIDIA Computer Vision SDK\n");
printf("==================================\n");
NCVAutoTestLister testListerSII("NPPST Squared Integral Image", outputLevel);
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 4096, 4096);
generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 4096, 4096);
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, 4096, 4096);
NCVAutoTestLister testListerII("NPPST Integral Image" );//,,true, false);
NCVAutoTestLister testListerSII("NPPST Squared Integral Image" );//,,true, false);
NCVAutoTestLister testListerRStdDev("NPPST RectStdDev" );//,,true, false);
NCVAutoTestLister testListerResize("NPPST Resize" );//,,true, false);
NCVAutoTestLister testListerNPPSTVectorOperations("NPPST Vector Operations" );//,,true, false);
NCVAutoTestLister testListerTranspose("NPPST Transpose" );//,,true, false);
generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 4096, 4096);
NCVAutoTestLister testListerVectorOperations("Vector Operations" );//,,true, false);
NCVAutoTestLister testListerHaarLoader("Haar Cascade Loader" );//,,true, false);
NCVAutoTestLister testListerHaarAppl("Haar Cascade Application" );//,,true, false);
NCVAutoTestLister testListerHypFiltration("Hypotheses Filtration" );//,,true, false);
NCVAutoTestLister testListerVisualize("Visualization" );//,,true, false);
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);
printf("Initializing data source providers\n");
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 4096, 4096);
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 4096, 4096);
NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, -1, 4096, 4096);
NCVTestSourceProvider<Ncv8u> testSrcFacesVGA_8u(path + "group_1_640x480_VGA.pgm");
NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 4096, 4096);
printf("Generating NPPST test suites\n");
generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 4096, 4096);
generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 4096, 4096);
generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 4096, 4096);
generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 4096, 4096);
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, 4096, 4096);
generateNPPSTVectorTests(testListerNPPSTVectorOperations, testSrcRandom_32u, 4096*4096);
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, 4096, 4096);
NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, -1, 4096, 4096);
generateTransposeTests(testListerTranspose, testSrcRandom_32u);
generateTransposeTests(testListerTranspose, testSrcRandom_64u);
printf("Generating NCV test suites\n");
generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 4096, 4096);
generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 4096, 4096);
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, 4096, 4096);
generateVectorTests(testListerVectorOperations, testSrcRandom_32u, 4096*4096);
generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 1024);
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, 1280, 720);
// Indicate if at least one test failed
bool passed = true;
// Invoke all tests
passed &= testListerII.invoke();
passed &= testListerSII.invoke();
passed &= testListerRStdDev.invoke();
passed &= testListerResize.invoke();
passed &= testListerNPPSTVectorOperations.invoke();
passed &= testListerTranspose.invoke();
passed &= testListerVisualize.invoke();
passed &= testListerVectorOperations.invoke();
passed &= testListerHypFiltration.invoke();
passed &= testListerHaarLoader.invoke();
passed &= testListerHaarAppl.invoke();
return passed;
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, 4096, 4096);
generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 1024);
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, 4096, 4096);
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 4096, 4096);
generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 4096, 4096);
generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 4096, 4096);
return testListerVisualize.invoke();
}
This diff is collapsed.
This diff is collapsed.
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
TEST(blendLinear, accuracy_on_8U)
{
RNG& rng = cvtest::TS::ptr()->get_rng();
Size size(200 + cvtest::randInt(rng) % 1000,
200 + cvtest::randInt(rng) % 1000);
for (int cn = 1; cn <= 4; ++cn)
{
Mat img1 = cvtest::randomMat(rng, size, CV_MAKE_TYPE(CV_8U, cn), 0, 255, false);
Mat img2 = cvtest::randomMat(rng, size, CV_MAKE_TYPE(CV_8U, cn), 0, 255, false);
Mat weights1 = cvtest::randomMat(rng, size, CV_32F, 0, 1, false);
Mat weights2 = cvtest::randomMat(rng, size, CV_32F, 0, 1, false);
Mat result_gold(size, CV_MAKE_TYPE(CV_8U, cn));
for (int y = 0; y < size.height; ++y)
for (int x = 0; x < size.width * cn; ++x)
{
float w1 = weights1.at<float>(y, x / cn);
float w2 = weights2.at<float>(y, x / cn);
result_gold.at<uchar>(y, x) = static_cast<uchar>(
(img1.at<uchar>(y, x) * w1 + img2.at<uchar>(y, x) * w2) / (w1 + w2 + 1e-5f));
}
GpuMat d_result;
blendLinear(GpuMat(img1), GpuMat(img2), GpuMat(weights1), GpuMat(weights2), d_result);
ASSERT_LE(cvtest::norm(result_gold, Mat(d_result), NORM_INF), 1)
<< "rows=" << size.height << ", cols=" << size.width << ", cn=" << cn;
}
}
TEST(blendLinear, accuracy_on_32F)
{
RNG& rng = cvtest::TS::ptr()->get_rng();
Size size(200 + cvtest::randInt(rng) % 1000,
200 + cvtest::randInt(rng) % 1000);
for (int cn = 1; cn <= 4; ++cn)
{
Mat img1 = cvtest::randomMat(rng, size, CV_MAKE_TYPE(CV_32F, cn), 0, 1, false);
Mat img2 = cvtest::randomMat(rng, size, CV_MAKE_TYPE(CV_32F, cn), 0, 1, false);
Mat weights1 = cvtest::randomMat(rng, size, CV_32F, 0, 1, false);
Mat weights2 = cvtest::randomMat(rng, size, CV_32F, 0, 1, false);
Mat result_gold(size, CV_MAKE_TYPE(CV_32F, cn));
for (int y = 0; y < size.height; ++y)
for (int x = 0; x < size.width * cn; ++x)
{
float w1 = weights1.at<float>(y, x / cn);
float w2 = weights2.at<float>(y, x / cn);
result_gold.at<float>(y, x) =
(img1.at<float>(y, x) * w1 + img2.at<float>(y, x) * w2) / (w1 + w2 + 1e-5f);
}
GpuMat d_result;
blendLinear(GpuMat(img1), GpuMat(img2), GpuMat(weights1), GpuMat(weights2), d_result);
ASSERT_LE(cvtest::norm(result_gold, Mat(d_result), NORM_INF), 1e-3)
<< "rows=" << size.height << ", cols=" << size.width << ", cn=" << cn;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
using namespace cv;
using namespace std;
using namespace gpu;
class CV_GpuMatOpSetToTest : public cvtest::BaseTest
{
public:
CV_GpuMatOpSetToTest();
~CV_GpuMatOpSetToTest() {}
protected:
void run(int);
bool testSetTo(cv::Mat& cpumat, gpu::GpuMat& gpumat, const cv::Mat& cpumask = cv::Mat(), const cv::gpu::GpuMat& gpumask = cv::gpu::GpuMat());
private:
int rows;
int cols;
Scalar s;
};
CV_GpuMatOpSetToTest::CV_GpuMatOpSetToTest()
{
rows = 35;
cols = 67;
s.val[0] = 127.0;
s.val[1] = 127.0;
s.val[2] = 127.0;
s.val[3] = 127.0;
}
bool CV_GpuMatOpSetToTest::testSetTo(cv::Mat& cpumat, gpu::GpuMat& gpumat, const cv::Mat& cpumask, const cv::gpu::GpuMat& gpumask)
{
cpumat.setTo(s, cpumask);
gpumat.setTo(s, gpumask);
double ret = norm(cpumat, (Mat)gpumat, NORM_INF);
if (ret < std::numeric_limits<double>::epsilon())
return true;
else
{
ts->printf(cvtest::TS::LOG, "\nNorm: %f\n", ret);
return false;
}
}
void CV_GpuMatOpSetToTest::run( int /* start_from */)
{
bool is_test_good = true;
cv::Mat cpumask(rows, cols, CV_8UC1);
cv::RNG& rng = ts->get_rng();
rng.fill(cpumask, RNG::UNIFORM, cv::Scalar::all(0.0), cv::Scalar(1.5));
cv::gpu::GpuMat gpumask(cpumask);
int lastType = CV_32F;
if (TargetArchs::builtWith(NATIVE_DOUBLE) && DeviceInfo().supports(NATIVE_DOUBLE))
lastType = CV_64F;
for (int i = 0; i <= lastType; i++)
{
for (int cn = 1; cn <= 4; ++cn)
{
int mat_type = CV_MAKETYPE(i, cn);
Mat cpumat(rows, cols, mat_type, Scalar::all(0));
GpuMat gpumat(cpumat);
is_test_good &= testSetTo(cpumat, gpumat, cpumask, gpumask);
}
}
if (is_test_good == true)
ts->set_failed_test_info(cvtest::TS::OK);
else
ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC);
}
TEST(GpuMat_setTo, accuracy) { CV_GpuMatOpSetToTest test; test.safe_run(); }
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_GPU_BASE_HPP__
#define __OPENCV_TEST_GPU_BASE_HPP__
//! return true if device supports specified feature and gpu module was built with support the feature.
bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
//! return all devices compatible with current gpu module build.
const std::vector<cv::gpu::DeviceInfo>& devices();
//! return all devices compatible with current gpu module build which support specified feature.
std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature);
//! return vector with types from specified range.
std::vector<int> types(int depth_start, int depth_end, int cn_start, int cn_end);
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
const std::vector<int>& all_types();
//! read image from testdata folder.
cv::Mat readImage(const std::string& fileName, int flags = CV_LOAD_IMAGE_COLOR);
double checkNorm(const cv::Mat& m1, const cv::Mat& m2);
double checkSimilarity(const cv::Mat& m1, const cv::Mat& m2);
#define OSTR_NAME(suf) ostr_ ## suf
#define PRINT_PARAM(name) \
std::ostringstream OSTR_NAME(name); \
OSTR_NAME(name) << # name << ": " << name; \
SCOPED_TRACE(OSTR_NAME(name).str());
#define PRINT_TYPE(type) \
std::ostringstream OSTR_NAME(type); \
OSTR_NAME(type) << # type << ": " << cvtest::getTypeName(type) << "c" << CV_MAT_CN(type); \
SCOPED_TRACE(OSTR_NAME(type).str());
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNorm(mat1, mat2), eps); \
}
#define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkSimilarity(mat1, mat2), eps); \
}
//! for gtest ASSERT
namespace cv
{
std::ostream& operator << (std::ostream& os, const Size& sz);
std::ostream& operator << (std::ostream& os, const Scalar& s);
namespace gpu
{
std::ostream& operator << (std::ostream& os, const DeviceInfo& info);
}
}
#endif // __OPENCV_TEST_GPU_BASE_HPP__
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment