提交 8274ed22 编写于 作者: V Vladislav Vinogradov

fixed gpu tests (BruteForceMatcher_GPU, divide, phase, cartToPolar, async)

minor code refactoring
上级 7a29d96c
......@@ -671,10 +671,12 @@ namespace cv
//! output will have CV_32FC1 type
CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect);
//! applies Canny edge detector and produces the edge map
//! supprots only CV_8UC1 source type
//! disabled until fix crash
CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);
// applies Canny edge detector and produces the edge map
// disabled until fix crash
//CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);
//CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, GpuMat& buffer, double threshold1, double threshold2, int apertureSize = 3);
//CV_EXPORTS void Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);
//CV_EXPORTS void Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, GpuMat& buffer, double threshold1, double threshold2, int apertureSize = 3);
//! computes Harris cornerness criteria at each image pixel
CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101);
......
......@@ -104,6 +104,18 @@ namespace cv { namespace gpu { namespace bfmatcher
const DevMem2D& mask, const DevMem2Di& trainIdx, unsigned int* nMatches, const DevMem2Df& distance);
}}}
namespace
{
class ImgIdxSetter
{
public:
ImgIdxSetter(int imgIdx_) : imgIdx(imgIdx_) {}
void operator()(DMatch& m) const {m.imgIdx = imgIdx;}
private:
int imgIdx;
};
}
cv::gpu::BruteForceMatcher_GPU_base::BruteForceMatcher_GPU_base(DistType distType_) : distType(distType_)
{
}
......@@ -185,7 +197,7 @@ void cv::gpu::BruteForceMatcher_GPU_base::matchDownload(const GpuMat& trainIdx,
return;
CV_Assert(trainIdx.type() == CV_32SC1 && trainIdx.isContinuous());
CV_Assert(distance.type() == CV_32FC1 && distance.isContinuous() && distance.size().area() == trainIdx.size().area());
CV_Assert(distance.type() == CV_32FC1 && distance.isContinuous() && distance.cols == trainIdx.cols);
const int nQuery = trainIdx.cols;
......@@ -309,8 +321,8 @@ void cv::gpu::BruteForceMatcher_GPU_base::matchDownload(const GpuMat& trainIdx,
return;
CV_Assert(trainIdx.type() == CV_32SC1 && trainIdx.isContinuous());
CV_Assert(imgIdx.type() == CV_32SC1 && imgIdx.isContinuous());
CV_Assert(distance.type() == CV_32FC1 && distance.isContinuous());
CV_Assert(imgIdx.type() == CV_32SC1 && imgIdx.isContinuous() && imgIdx.cols == trainIdx.cols);
CV_Assert(distance.type() == CV_32FC1 && distance.isContinuous() && imgIdx.cols == trainIdx.cols);
const int nQuery = trainIdx.cols;
......@@ -390,7 +402,7 @@ void cv::gpu::BruteForceMatcher_GPU_base::knnMatch(const GpuMat& queryDescs, con
trainIdx.setTo(Scalar::all(-1));
distance.create(nQuery, k, CV_32F);
allDist.create(nQuery, nTrain, CV_32F);
ensureSizeIsEnough(nQuery, nTrain, CV_32FC1, allDist);
match_caller_t func = match_callers[distType][queryDescs.depth()];
CV_Assert(func != 0);
......@@ -451,18 +463,6 @@ void cv::gpu::BruteForceMatcher_GPU_base::knnMatch(const GpuMat& queryDescs, con
knnMatchDownload(trainIdx, distance, matches, compactResult);
}
namespace
{
class ImgIdxSetter
{
public:
ImgIdxSetter(int imgIdx_) : imgIdx(imgIdx_) {}
void operator()(DMatch& m) const {m.imgIdx = imgIdx;}
private:
int imgIdx;
};
}
void cv::gpu::BruteForceMatcher_GPU_base::knnMatch(const GpuMat& queryDescs,
vector< vector<DMatch> >& matches, int knn, const vector<GpuMat>& masks, bool compactResult)
{
......@@ -538,9 +538,9 @@ void cv::gpu::BruteForceMatcher_GPU_base::radiusMatch(const GpuMat& queryDescs,
CV_Assert(queryDescs.channels() == 1 && queryDescs.depth() < CV_64F);
CV_Assert(trainDescs.type() == queryDescs.type() && trainDescs.cols == queryDescs.cols);
CV_Assert(trainIdx.empty() || trainIdx.rows == nQuery);
CV_Assert(trainIdx.empty() || (trainIdx.rows == nQuery && trainIdx.size() == distance.size()));
nMatches.create(1, nQuery, CV_32SC1);
ensureSizeIsEnough(1, nQuery, CV_32SC1, nMatches);
nMatches.setTo(Scalar::all(0));
if (trainIdx.empty())
{
......@@ -561,7 +561,7 @@ void cv::gpu::BruteForceMatcher_GPU_base::radiusMatchDownload(const GpuMat& trai
return;
CV_Assert(trainIdx.type() == CV_32SC1);
CV_Assert(nMatches.type() == CV_32SC1 && nMatches.isContinuous() && nMatches.size().area() == trainIdx.rows);
CV_Assert(nMatches.type() == CV_32SC1 && nMatches.isContinuous() && nMatches.cols >= trainIdx.rows);
CV_Assert(distance.type() == CV_32FC1 && distance.size() == trainIdx.size());
const int nQuery = trainIdx.rows;
......
......@@ -66,7 +66,10 @@ void cv::gpu::integral(const GpuMat&, GpuMat&, GpuMat&) { throw_nogpu(); }
void cv::gpu::sqrIntegral(const GpuMat&, GpuMat&) { throw_nogpu(); }
void cv::gpu::columnSum(const GpuMat&, GpuMat&) { throw_nogpu(); }
void cv::gpu::rectStdDev(const GpuMat&, const GpuMat&, GpuMat&, const Rect&) { throw_nogpu(); }
void cv::gpu::Canny(const GpuMat&, GpuMat&, double, double, int) { throw_nogpu(); }
//void cv::gpu::Canny(const GpuMat&, GpuMat&, double, double, int) { throw_nogpu(); }
//void cv::gpu::Canny(const GpuMat&, GpuMat&, GpuMat&, double, double, int) { throw_nogpu(); }
//void cv::gpu::Canny(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, double, double, int) { throw_nogpu(); }
//void cv::gpu::Canny(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, GpuMat&, double, double, int) { throw_nogpu(); }
void cv::gpu::evenLevels(GpuMat&, int, int, int) { throw_nogpu(); }
void cv::gpu::histEven(const GpuMat&, GpuMat&, int, int, int) { throw_nogpu(); }
void cv::gpu::histEven(const GpuMat&, GpuMat*, int*, int*, int*) { throw_nogpu(); }
......@@ -655,34 +658,60 @@ void cv::gpu::rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, cons
////////////////////////////////////////////////////////////////////////
// Canny
void cv::gpu::Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize)
{
CV_Assert(!"disabled until fix crash");
CV_Assert(image.type() == CV_8UC1);
GpuMat srcDx, srcDy;
Sobel(image, srcDx, -1, 1, 0, apertureSize);
Sobel(image, srcDy, -1, 0, 1, apertureSize);
srcDx.convertTo(srcDx, CV_32F);
srcDy.convertTo(srcDy, CV_32F);
edges.create(image.size(), CV_8UC1);
NppiSize sz;
sz.height = image.rows;
sz.width = image.cols;
int bufsz;
nppSafeCall( nppiCannyGetBufferSize(sz, &bufsz) );
GpuMat buf(1, bufsz, CV_8UC1);
nppSafeCall( nppiCanny_32f8u_C1R(srcDx.ptr<Npp32f>(), srcDx.step, srcDy.ptr<Npp32f>(), srcDy.step,
edges.ptr<Npp8u>(), edges.step, sz, (Npp32f)threshold1, (Npp32f)threshold2, buf.ptr<Npp8u>()) );
cudaSafeCall( cudaThreadSynchronize() );
}
//void cv::gpu::Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize)
//{
// CV_Assert(!"disabled until fix crash");
//
// GpuMat srcDx, srcDy;
//
// Sobel(image, srcDx, CV_32F, 1, 0, apertureSize);
// Sobel(image, srcDy, CV_32F, 0, 1, apertureSize);
//
// GpuMat buf;
//
// Canny(srcDx, srcDy, edges, buf, threshold1, threshold2, apertureSize);
//}
//
//void cv::gpu::Canny(const GpuMat& image, GpuMat& edges, GpuMat& buf, double threshold1, double threshold2, int apertureSize)
//{
// CV_Assert(!"disabled until fix crash");
//
// GpuMat srcDx, srcDy;
//
// Sobel(image, srcDx, CV_32F, 1, 0, apertureSize);
// Sobel(image, srcDy, CV_32F, 0, 1, apertureSize);
//
// Canny(srcDx, srcDy, edges, buf, threshold1, threshold2, apertureSize);
//}
//
//void cv::gpu::Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, double threshold1, double threshold2, int apertureSize)
//{
// CV_Assert(!"disabled until fix crash");
//
// GpuMat buf;
// Canny(srcDx, srcDy, edges, buf, threshold1, threshold2, apertureSize);
//}
//
//void cv::gpu::Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, GpuMat& buf, double threshold1, double threshold2, int apertureSize)
//{
// CV_Assert(!"disabled until fix crash");
// CV_Assert(srcDx.type() == CV_32FC1 && srcDy.type() == CV_32FC1 && srcDx.size() == srcDy.size());
//
// edges.create(srcDx.size(), CV_8UC1);
//
// NppiSize sz;
// sz.height = srcDx.rows;
// sz.width = srcDx.cols;
//
// int bufsz;
// nppSafeCall( nppiCannyGetBufferSize(sz, &bufsz) );
// ensureSizeIsEnough(1, bufsz, CV_8UC1, buf);
//
// nppSafeCall( nppiCanny_32f8u_C1R(srcDx.ptr<Npp32f>(), srcDx.step, srcDy.ptr<Npp32f>(), srcDy.step,
// edges.ptr<Npp8u>(), edges.step, sz, (Npp32f)threshold1, (Npp32f)threshold2, buf.ptr<Npp8u>()) );
//
// cudaSafeCall( cudaThreadSynchronize() );
//}
////////////////////////////////////////////////////////////////////////
// Histogram
......
......@@ -66,45 +66,58 @@ protected:
virtual int test(const Mat& mat1, const Mat& mat2) = 0;
int CheckNorm(const Mat& m1, const Mat& m2);
int CheckNorm(const Scalar& s1, const Scalar& s2);
int CheckNorm(double d1, double d2);
int CheckNorm(const Mat& m1, const Mat& m2, double eps = 1e-5);
int CheckNorm(const Scalar& s1, const Scalar& s2, double eps = 1e-5);
int CheckNorm(double d1, double d2, double eps = 1e-5);
};
int CV_GpuArithmTest::test(int type)
{
cv::Size sz(200, 200);
cv::Mat mat1(sz, type), mat2(sz, type);
cv::RNG rng(*ts->get_rng());
rng.fill(mat1, cv::RNG::UNIFORM, cv::Scalar::all(1), cv::Scalar::all(20));
rng.fill(mat2, cv::RNG::UNIFORM, cv::Scalar::all(1), cv::Scalar::all(20));
if (type != CV_32FC1)
{
rng.fill(mat1, cv::RNG::UNIFORM, cv::Scalar::all(1), cv::Scalar::all(20));
rng.fill(mat2, cv::RNG::UNIFORM, cv::Scalar::all(1), cv::Scalar::all(20));
}
else
{
rng.fill(mat1, cv::RNG::UNIFORM, cv::Scalar::all(0.1), cv::Scalar::all(1.0));
rng.fill(mat2, cv::RNG::UNIFORM, cv::Scalar::all(0.1), cv::Scalar::all(1.0));
}
return test(mat1, mat2);
}
int CV_GpuArithmTest::CheckNorm(const Mat& m1, const Mat& m2)
int CV_GpuArithmTest::CheckNorm(const Mat& m1, const Mat& m2, double eps)
{
double ret = norm(m1, m2, NORM_INF);
if (ret < 1e-5)
if (ret < eps)
return CvTS::OK;
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
return CvTS::FAIL_GENERIC;
}
int CV_GpuArithmTest::CheckNorm(const Scalar& s1, const Scalar& s2)
int CV_GpuArithmTest::CheckNorm(const Scalar& s1, const Scalar& s2, double eps)
{
double ret0 = CheckNorm(s1[0], s2[0]), ret1 = CheckNorm(s1[1], s2[1]), ret2 = CheckNorm(s1[2], s2[2]), ret3 = CheckNorm(s1[3], s2[3]);
int ret0 = CheckNorm(s1[0], s2[0], eps),
ret1 = CheckNorm(s1[1], s2[1], eps),
ret2 = CheckNorm(s1[2], s2[2], eps),
ret3 = CheckNorm(s1[3], s2[3], eps);
return (ret0 == CvTS::OK && ret1 == CvTS::OK && ret2 == CvTS::OK && ret3 == CvTS::OK) ? CvTS::OK : CvTS::FAIL_GENERIC;
}
int CV_GpuArithmTest::CheckNorm(double d1, double d2)
int CV_GpuArithmTest::CheckNorm(double d1, double d2, double eps)
{
double ret = ::fabs(d1 - d2);
if (ret < 1e-5)
if (ret < eps)
return CvTS::OK;
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
......@@ -245,7 +258,7 @@ struct CV_GpuNppImageDivideTest : public CV_GpuArithmTest
GpuMat gpuRes;
cv::gpu::divide(gpu1, gpu2, gpuRes);
return CheckNorm(cpuRes, gpuRes);
return CheckNorm(cpuRes, gpuRes, 1.01f);
}
};
......@@ -584,7 +597,7 @@ struct CV_GpuNppImagePhaseTest : public CV_GpuArithmTest
GpuMat gpuRes;
cv::gpu::phase(gpu1, gpu2, gpuRes, true);
return CheckNorm(cpuRes, gpuRes);
return CheckNorm(cpuRes, gpuRes, 0.3f);
}
};
......@@ -611,7 +624,7 @@ struct CV_GpuNppImageCartToPolarTest : public CV_GpuArithmTest
cv::gpu::cartToPolar(gpu1, gpu2, gpuMag, gpuAngle);
int magRes = CheckNorm(cpuMag, gpuMag);
int angleRes = CheckNorm(cpuAngle, gpuAngle);
int angleRes = CheckNorm(cpuAngle, gpuAngle, 0.005f);
return magRes == CvTS::OK && angleRes == CvTS::OK ? CvTS::OK : CvTS::FAIL_GENERIC;
}
......
......@@ -51,24 +51,27 @@ class CV_GpuBruteForceMatcherTest : public CvTest
{
public:
CV_GpuBruteForceMatcherTest() :
CvTest( "GPU-BruteForceMatcher", "BruteForceMatcher" ), badPart(0.01f)
CvTest( "GPU-BruteForceMatcher", "BruteForceMatcher" )
{
}
protected:
static const int dim = 500;
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
static const int countFactor = 4; // do not change it
const float badPart;
protected:
virtual void run(int);
void generateData(GpuMat& query, GpuMat& train);
void emptyDataTest();
void dataTest(int dim);
void generateData(GpuMat& query, GpuMat& train, int dim);
void matchTest(const GpuMat& query, const GpuMat& train);
void knnMatchTest(const GpuMat& query, const GpuMat& train);
void radiusMatchTest(const GpuMat& query, const GpuMat& train);
private:
BruteForceMatcher_GPU< L2<float> > dmatcher;
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
static const int countFactor = 4; // do not change it
};
void CV_GpuBruteForceMatcherTest::emptyDataTest()
......@@ -150,7 +153,7 @@ void CV_GpuBruteForceMatcherTest::emptyDataTest()
}
void CV_GpuBruteForceMatcherTest::generateData( GpuMat& queryGPU, GpuMat& trainGPU )
void CV_GpuBruteForceMatcherTest::generateData( GpuMat& queryGPU, GpuMat& trainGPU, int dim )
{
Mat query, train;
RNG rng(*ts->get_rng());
......@@ -209,7 +212,7 @@ void CV_GpuBruteForceMatcherTest::matchTest( const GpuMat& query, const GpuMat&
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0) )
badCount++;
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
ts->printf( CvTS::LOG, "%f - too large bad matches part while test match() function (1).\n",
(float)badCount/(float)queryDescCount );
......@@ -260,7 +263,7 @@ void CV_GpuBruteForceMatcherTest::matchTest( const GpuMat& query, const GpuMat&
}
}
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
ts->printf( CvTS::LOG, "%f - too large bad matches part while test match() function (2).\n",
(float)badCount/(float)queryDescCount );
......@@ -305,7 +308,7 @@ void CV_GpuBruteForceMatcherTest::knnMatchTest( const GpuMat& query, const GpuMa
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
ts->printf( CvTS::LOG, "%f - too large bad matches part while test knnMatch() function (1).\n",
(float)badCount/(float)queryDescCount );
......@@ -369,7 +372,7 @@ void CV_GpuBruteForceMatcherTest::knnMatchTest( const GpuMat& query, const GpuMa
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
ts->printf( CvTS::LOG, "%f - too large bad matches part while test knnMatch() function (2).\n",
(float)badCount/(float)queryDescCount );
......@@ -407,7 +410,7 @@ void CV_GpuBruteForceMatcherTest::radiusMatchTest( const GpuMat& query, const Gp
badCount++;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
ts->printf( CvTS::LOG, "%f - too large bad matches part while test radiusMatch() function (1).\n",
(float)badCount/(float)queryDescCount );
......@@ -473,7 +476,8 @@ void CV_GpuBruteForceMatcherTest::radiusMatchTest( const GpuMat& query, const Gp
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
if (badCount > 0)
{
curRes = CvTS::FAIL_INVALID_OUTPUT;
ts->printf( CvTS::LOG, "%f - too large bad matches part while test radiusMatch() function (2).\n",
......@@ -483,20 +487,29 @@ void CV_GpuBruteForceMatcherTest::radiusMatchTest( const GpuMat& query, const Gp
}
}
void CV_GpuBruteForceMatcherTest::run( int )
void CV_GpuBruteForceMatcherTest::dataTest(int dim)
{
emptyDataTest();
GpuMat query, train;
generateData( query, train );
generateData(query, train, dim);
matchTest( query, train );
matchTest(query, train);
knnMatchTest(query, train);
radiusMatchTest(query, train);
knnMatchTest( query, train );
dmatcher.clear();
}
radiusMatchTest( query, train );
void CV_GpuBruteForceMatcherTest::run(int)
{
emptyDataTest();
dmatcher.clear();
dataTest(50);
dataTest(64);
dataTest(100);
dataTest(128);
dataTest(200);
dataTest(256);
dataTest(300);
}
CV_GpuBruteForceMatcherTest CV_GpuBruteForceMatcher_test;
......@@ -45,7 +45,6 @@ CvTS test_system("gpu");
const char* blacklist[] =
{
"GPU-AsyncGpuMatOperator", // crash
"GPU-NppImageCanny", // NPP_TEXTURE_BIND_ERROR
0
};
......
......@@ -408,30 +408,30 @@ struct CV_GpuNppImageIntegralTest : public CV_GpuImageProcTest
////////////////////////////////////////////////////////////////////////////////
// Canny
struct CV_GpuNppImageCannyTest : public CV_GpuImageProcTest
{
CV_GpuNppImageCannyTest() : CV_GpuImageProcTest( "GPU-NppImageCanny", "Canny" ) {}
int test(const Mat& img)
{
if (img.type() != CV_8UC1)
{
ts->printf(CvTS::LOG, "\nUnsupported type\n");
return CvTS::OK;
}
const double threshold1 = 1.0, threshold2 = 10.0;
Mat cpudst;
cv::Canny(img, cpudst, threshold1, threshold2);
GpuMat gpu1(img);
GpuMat gpudst;
cv::gpu::Canny(gpu1, gpudst, threshold1, threshold2);
return CheckNorm(cpudst, gpudst);
}
};
//struct CV_GpuNppImageCannyTest : public CV_GpuImageProcTest
//{
// CV_GpuNppImageCannyTest() : CV_GpuImageProcTest( "GPU-NppImageCanny", "Canny" ) {}
//
// int test(const Mat& img)
// {
// if (img.type() != CV_8UC1)
// {
// ts->printf(CvTS::LOG, "\nUnsupported type\n");
// return CvTS::OK;
// }
//
// const double threshold1 = 1.0, threshold2 = 10.0;
//
// Mat cpudst;
// cv::Canny(img, cpudst, threshold1, threshold2);
//
// GpuMat gpu1(img);
// GpuMat gpudst;
// cv::gpu::Canny(gpu1, gpudst, threshold1, threshold2);
//
// return CheckNorm(cpudst, gpudst);
// }
//};
////////////////////////////////////////////////////////////////////////////////
// cvtColor
......@@ -839,7 +839,7 @@ CV_GpuNppImageCopyMakeBorderTest CV_GpuNppImageCopyMakeBorder_test;
CV_GpuNppImageWarpAffineTest CV_GpuNppImageWarpAffine_test;
CV_GpuNppImageWarpPerspectiveTest CV_GpuNppImageWarpPerspective_test;
CV_GpuNppImageIntegralTest CV_GpuNppImageIntegral_test;
CV_GpuNppImageCannyTest CV_GpuNppImageCanny_test;
//CV_GpuNppImageCannyTest CV_GpuNppImageCanny_test;
CV_GpuCvtColorTest CV_GpuCvtColor_test;
CV_GpuHistogramsTest CV_GpuHistograms_test;
CV_GpuCornerHarrisTest CV_GpuCornerHarris_test;
......
......@@ -40,119 +40,54 @@
//M*/
#include "gputest.hpp"
#include <string>
#include <iostream>
#include <fstream>
#include <iterator>
#include <limits>
#include <numeric>
#include <iomanip> // for cout << setw()
using namespace cv;
using namespace std;
using namespace gpu;
class CV_AsyncGpuMatTest : public CvTest
{
public:
CV_AsyncGpuMatTest() : CvTest( "GPU-AsyncGpuMatOperator", "async" )
{
rows = 234;
cols = 123;
}
~CV_AsyncGpuMatTest() {}
protected:
void run(int);
template <typename T>
void print_mat(const T & mat, const std::string & name) const;
bool compare_matrix(cv::Mat & cpumat);
private:
int rows;
int cols;
};
template<typename T>
void CV_AsyncGpuMatTest::print_mat(const T & mat, const std::string & name) const { cv::imshow(name, mat); }
using namespace cv;
using namespace cv::gpu;
bool CV_AsyncGpuMatTest::compare_matrix(cv::Mat & cpumat)
struct CV_AsyncGpuMatTest : public CvTest
{
Mat cmat(cpumat.size(), cpumat.type(), Scalar::all(0));
GpuMat gmat0(cmat);
GpuMat gmat1;
GpuMat gmat2;
GpuMat gmat3;
//int64 time = getTickCount();
Stream stream;
stream.enqueueMemSet(gmat0, cv::Scalar::all(1), gmat1);
stream.enqueueMemSet(gmat0, cv::Scalar::all(1), gmat2);
stream.enqueueMemSet(gmat0, cv::Scalar::all(1), gmat3);
stream.waitForCompletion();
//int64 time1 = getTickCount();
gmat1.copyTo(gmat0);
gmat2.copyTo(gmat0);
gmat3.copyTo(gmat0);
//int64 time2 = getTickCount();
//std::cout << "\ntime async: " << std::fixed << std::setprecision(12) << double((time1 - time) / (double)getTickFrequency());
//std::cout << "\ntime sync: " << std::fixed << std::setprecision(12) << double((time2 - time1) / (double)getTickFrequency());
//std::cout << "\n";
#ifdef PRINT_MATRIX
print_mat(cmat, "cpu mat");
print_mat(gmat0, "gpu mat 0");
print_mat(gmat1, "gpu mat 1");
print_mat(gmat2, "gpu mat 2");
print_mat(gmat3, "gpu mat 3");
cv::waitKey(0);
#endif
double ret = norm(cmat, gmat0) + norm(cmat, gmat1) + norm(cmat, gmat2) + norm(cmat, gmat3);
if (ret < 1.0)
return true;
else
CV_AsyncGpuMatTest() : CvTest( "GPU-AsyncGpuMatOperator", "async" )
{
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
return false;
}
}
void CV_AsyncGpuMatTest::run( int /* start_from */)
{
bool is_test_good = true;
void run(int)
{
try
{
CudaMem src(Mat::zeros(100, 100, CV_8UC1));
Mat cpumat(rows, cols, CV_8U);
cpumat.setTo(Scalar::all(127));
GpuMat gpusrc;
GpuMat gpudst0, gpudst1(100, 100, CV_8UC1);
try
{
is_test_good &= compare_matrix(cpumat);
}
catch(cv::Exception& e)
{
if (!check_and_treat_gpu_exception(e, ts))
throw;
return;
}
CudaMem cpudst0;
CudaMem cpudst1;
if (is_test_good == true)
ts->set_failed_test_info(CvTS::OK);
else
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
}
Stream stream0, stream1;
stream0.enqueueUpload(src, gpusrc);
bitwise_not(gpusrc, gpudst0, GpuMat(), stream0);
stream0.enqueueDownload(gpudst0, cpudst0);
/////////////////////////////////////////////////////////////////////////////
/////////////////// tests registration /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
stream1.enqueueMemSet(gpudst1, Scalar::all(128));
stream1.enqueueDownload(gpudst1, cpudst1);
stream0.waitForCompletion();
stream1.waitForCompletion();
Mat cpu_gold0(100, 100, CV_8UC1, Scalar::all(255));
Mat cpu_gold1(100, 100, CV_8UC1, Scalar::all(128));
CV_AsyncGpuMatTest CV_AsyncGpuMatTest_test;
if (norm(cpudst0, cpu_gold0, NORM_INF) > 0 || norm(cpudst1, cpu_gold1, NORM_INF) > 0)
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
else
ts->set_failed_test_info(CvTS::OK);
}
catch(cv::Exception& e)
{
if (!check_and_treat_gpu_exception(e, ts))
throw;
return;
}
}
} CV_AsyncGpuMatTest_test;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册