most of the performance tests was rewritten in google-test manner

pull/1326/head
ilya-lavrenov 12 years ago
parent 6c4ad9b597
commit 4c28a6f0f6
  1. 32
      modules/ocl/perf/main.cpp
  2. 1580
      modules/ocl/perf/perf_arithm.cpp
  3. 96
      modules/ocl/perf/perf_blend.cpp
  4. 289
      modules/ocl/perf/perf_brute_force_matcher.cpp
  5. 67
      modules/ocl/perf/perf_calib3d.cpp
  6. 55
      modules/ocl/perf/perf_canny.cpp
  7. 58
      modules/ocl/perf/perf_color.cpp
  8. 58
      modules/ocl/perf/perf_fft.cpp
  9. 455
      modules/ocl/perf/perf_filters.cpp
  10. 64
      modules/ocl/perf/perf_gemm.cpp
  11. 76
      modules/ocl/perf/perf_gftt.cpp
  12. 72
      modules/ocl/perf/perf_haar.cpp
  13. 56
      modules/ocl/perf/perf_hog.cpp
  14. 1002
      modules/ocl/perf/perf_imgproc.cpp
  15. 150
      modules/ocl/perf/perf_match_template.cpp
  16. 201
      modules/ocl/perf/perf_matrix_operation.cpp
  17. 71
      modules/ocl/perf/perf_moments.cpp
  18. 63
      modules/ocl/perf/perf_norm.cpp
  19. 197
      modules/ocl/perf/perf_opticalflow.cpp
  20. 35
      modules/ocl/perf/perf_precomp.hpp
  21. 133
      modules/ocl/perf/perf_pyramid.cpp
  22. 174
      modules/ocl/perf/perf_split_merge.cpp

@ -42,7 +42,7 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
int main(int argc, const char *argv[]) static int old_main(int argc, const char *argv[])
{ {
const char *keys = const char *keys =
"{ h | help | false | print help message }" "{ h | help | false | print help message }"
@ -162,3 +162,33 @@ END_DEV:
return 0; return 0;
} }
const char * impls[] =
{
"ocl",
"plain",
#ifdef HAVE_OPENCV_GPU
"gpu"
#endif
};
int main(int argc, char **argv)
{
// temp solution: if no '--gtest_' and '--perf_' args switch to old behavior
bool useGTest = false;
for(int i=1; i<argc; i++)
{
std::string arg( argv[i] );
if( arg.find("--gtest_")==0 || arg.find("--perf_")==0 )
useGTest = true;
// if (arg == "--perf_verify_sanity")
// argv[i] = (char*)"--perf_no_verify_sanity";
}
if( !useGTest )
return old_main(argc, (const char**)argv);
CV_PERF_TEST_MAIN_INTERNALS(ocl, impls)
}

File diff suppressed because it is too large Load Diff

@ -45,9 +45,15 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// blend //////////////////////// ///////////// blend ////////////////////////
template <typename T> template <typename T>
void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &weights1, const cv::Mat &weights2, cv::Mat &result_gold) static void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2,
const cv::Mat &weights1, const cv::Mat &weights2,
cv::Mat &result_gold)
{ {
result_gold.create(img1.size(), img1.type()); result_gold.create(img1.size(), img1.type());
@ -63,60 +69,54 @@ void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &we
for (int x = 0; x < img1.cols * cn; ++x) for (int x = 0; x < img1.cols * cn; ++x)
{ {
float w1 = weights1_row[x / cn]; int x1 = x * cn;
float w2 = weights2_row[x / cn]; float w1 = weights1_row[x];
result_gold_row[x] = static_cast<T>((img1_row[x] * w1 + img2_row[x] * w2) / (w1 + w2 + 1e-5f)); float w2 = weights2_row[x];
result_gold_row[x] = static_cast<T>((img1_row[x1] * w1
+ img2_row[x1] * w2) / (w1 + w2 + 1e-5f));
} }
} }
} }
PERFTEST(blend)
{
Mat src1, src2, weights1, weights2, dst, ocl_dst;
ocl::oclMat d_src1, d_src2, d_weights1, d_weights2, d_dst;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef TestBaseWithParam<Size> blendLinearFixture;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(blendLinearFixture, blendLinear, OCL_TYPICAL_MAT_SIZES)
{ {
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) // getting params
const Size srcSize = GetParam();
const int type = CV_8UC1;
const std::string impl = getSelectedImpl();
// creating src data
Mat src1(srcSize, type), src2(srcSize, CV_8UC1), dst;
Mat weights1(srcSize, CV_32FC1), weights2(srcSize, CV_32FC1);
declare.in(src1, src2, WARMUP_RNG);
randu(weights1, 0.0f, 1.0f);
randu(weights2, 0.0f, 1.0f);
// select implementation
if (impl == "ocl")
{ {
SUBTEST << size << 'x' << size << "; " << type_name[j] << " and CV_32FC1"; ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst;
ocl::oclMat oclWeights1(weights1), oclWeights2(weights2);
gen(src1, size, size, all_type[j], 0, 256);
gen(src2, size, size, all_type[j], 0, 256); TEST_CYCLE() cv::ocl::blendLinear(oclSrc1, oclSrc2, oclWeights1, oclWeights2, oclDst);
gen(weights1, size, size, CV_32FC1, 0, 1);
gen(weights2, size, size, CV_32FC1, 0, 1); oclDst.download(dst);
blendLinearGold<uchar>(src1, src2, weights1, weights2, dst); SANITY_CHECK(dst);
CPU_ON;
blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
CPU_OFF;
d_src1.upload(src1);
d_src2.upload(src2);
d_weights1.upload(weights1);
d_weights2.upload(weights2);
WARMUP_ON;
ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
WARMUP_OFF;
GPU_ON;
ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
GPU_OFF;
GPU_FULL_ON;
d_src1.upload(src1);
d_src2.upload(src2);
d_weights1.upload(weights1);
d_weights2.upload(weights2);
ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.f);
} }
else if (impl == "plain")
{
TEST_CYCLE() blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,123 +45,242 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
#define OCL_BFMATCHER_TYPICAL_MAT_SIZES ::testing::Values(cv::Size(128, 500), cv::Size(128, 1000), cv::Size(128, 2000))
//////////////////// BruteForceMatch ///////////////// //////////////////// BruteForceMatch /////////////////
PERFTEST(BruteForceMatcher)
{
Mat trainIdx_cpu;
Mat distance_cpu;
Mat allDist_cpu;
Mat nMatches_cpu;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef TestBaseWithParam<Size> BruteForceMatcherFixture;
PERF_TEST_P(BruteForceMatcherFixture, match,
OCL_BFMATCHER_TYPICAL_MAT_SIZES)
{ {
// Init CPU matcher const Size srcSize = GetParam();
int desc_len = 64; const string impl = getSelectedImpl();
BFMatcher matcher(NORM_L2); vector<DMatch> matches;
Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
declare.in(query, train).time(srcSize.height == 2000 ? 8 : 4 );
randu(query, 0.0f, 1.0f);
randu(train, 0.0f, 1.0f);
Mat query; if (impl == "plain")
gen(query, size, desc_len, CV_32F, 0, 1); {
BFMatcher matcher(NORM_L2);
TEST_CYCLE() matcher.match(query, train, matches);
Mat train; SANITY_CHECK_MATCHES(matches);
gen(train, size, desc_len, CV_32F, 0, 1); }
// Output else if (impl == "ocl")
vector< vector<DMatch> > matches(2); {
vector< vector<DMatch> > d_matches(2);
// Init GPU matcher // Init GPU matcher
ocl::BruteForceMatcher_OCL_base d_matcher(ocl::BruteForceMatcher_OCL_base::L2Dist); ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
ocl::oclMat oclQuery(query), oclTrain(train);
ocl::oclMat d_query(query); TEST_CYCLE() oclMatcher.match(oclQuery, oclTrain, matches);
ocl::oclMat d_train(train);
ocl::oclMat d_trainIdx, d_distance, d_allDist, d_nMatches; SANITY_CHECK_MATCHES(matches);
}
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
}
SUBTEST << size << "; match"; //PERF_TEST_P(BruteForceMatcherFixture, matchSingle,
// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
//{
// const Size srcSize = GetParam();
// const string impl = getSelectedImpl();
matcher.match(query, train, matches[0]); // Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
// Mat trainIdx, distance;
CPU_ON; // randu(query, 0.0f, 1.0f);
matcher.match(query, train, matches[0]); // randu(train, 0.0f, 1.0f);
CPU_OFF;
WARMUP_ON; // if (impl == "plain")
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); // CV_TEST_FAIL_NO_IMPL();
WARMUP_OFF; // else if (impl == "ocl")
// {
// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance;
GPU_ON; // TEST_CYCLE() oclMatcher->matchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance);
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
GPU_OFF;
GPU_FULL_ON; // oclTrainIdx.download(trainIdx);
d_query.upload(query); // oclDistance.download(distance);
d_train.upload(train);
d_matcher.match(d_query, d_train, d_matches[0]);
GPU_FULL_OFF;
int diff = abs((int)d_matches[0].size() - (int)matches[0].size()); // SANITY_CHECK(trainIdx);
if(diff == 0) // SANITY_CHECK(distance);
TestSystem::instance().setAccurate(1, 0); // }
else //#ifdef HAVE_OPENCV_GPU
TestSystem::instance().setAccurate(0, diff); // else if (impl == "gpu")
// CV_TEST_FAIL_NO_IMPL();
//#endif
// else
// CV_TEST_FAIL_NO_IMPL();
//}
SUBTEST << size << "; knnMatch"; PERF_TEST_P(BruteForceMatcherFixture, knnMatch,
OCL_BFMATCHER_TYPICAL_MAT_SIZES)
{
const Size srcSize = GetParam();
const string impl = getSelectedImpl();
matcher.knnMatch(query, train, matches, 2); vector<vector<DMatch> > matches(2);
Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
randu(query, 0.0f, 1.0f);
randu(train, 0.0f, 1.0f);
CPU_ON; declare.in(query, train);
matcher.knnMatch(query, train, matches, 2); if (srcSize.height == 2000)
CPU_OFF; declare.time(8);
WARMUP_ON; if (impl == "plain")
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2); {
WARMUP_OFF; BFMatcher matcher (NORM_L2);
TEST_CYCLE() matcher.knnMatch(query, train, matches, 2);
GPU_ON; std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2); SANITY_CHECK_MATCHES(matches0);
GPU_OFF; SANITY_CHECK_MATCHES(matches1);
}
else if (impl == "ocl")
{
ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
ocl::oclMat oclQuery(query), oclTrain(train);
GPU_FULL_ON; TEST_CYCLE() oclMatcher.knnMatch(oclQuery, oclTrain, matches, 2);
d_query.upload(query);
d_train.upload(train);
d_matcher.knnMatch(d_query, d_train, d_matches, 2);
GPU_FULL_OFF;
diff = abs((int)d_matches[0].size() - (int)matches[0].size()); std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
if(diff == 0) SANITY_CHECK_MATCHES(matches0);
TestSystem::instance().setAccurate(1, 0); SANITY_CHECK_MATCHES(matches1);
}
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else else
TestSystem::instance().setAccurate(0, diff); CV_TEST_FAIL_NO_IMPL();
}
SUBTEST << size << "; radiusMatch"; //PERF_TEST_P(BruteForceMatcherFixture, knnMatchSingle,
// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
//{
// const Size srcSize = GetParam();
// const string impl = getSelectedImpl();
float max_distance = 2.0f; // Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
// Mat trainIdx, distance, allDist;
matcher.radiusMatch(query, train, matches, max_distance); // randu(query, 0.0f, 1.0f);
// randu(train, 0.0f, 1.0f);
CPU_ON; // if (impl == "plain")
matcher.radiusMatch(query, train, matches, max_distance); // CV_TEST_FAIL_NO_IMPL();
CPU_OFF; // else if (impl == "ocl")
// {
// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance, oclAllDist;
d_trainIdx.release(); // TEST_CYCLE() oclMatcher->knnMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclAllDist, 2);
WARMUP_ON; // oclTrainIdx.download(trainIdx);
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance); // oclDistance.download(distance);
WARMUP_OFF; // oclAllDist.download(allDist);
GPU_ON; // SANITY_CHECK(trainIdx);
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance); // SANITY_CHECK(distance);
GPU_OFF; // SANITY_CHECK(allDist);
// }
//#ifdef HAVE_OPENCV_GPU
// else if (impl == "gpu")
// CV_TEST_FAIL_NO_IMPL();
//#endif
// else
// CV_TEST_FAIL_NO_IMPL();
//}
GPU_FULL_ON; PERF_TEST_P(BruteForceMatcherFixture, DISABLED_radiusMatch,
d_query.upload(query); OCL_BFMATCHER_TYPICAL_MAT_SIZES)
d_train.upload(train); {
d_matcher.radiusMatch(d_query, d_train, d_matches, max_distance); const Size srcSize = GetParam();
GPU_FULL_OFF; const string impl = getSelectedImpl();
diff = abs((int)d_matches[0].size() - (int)matches[0].size()); const float max_distance = 2.0f;
if(diff == 0) vector<vector<DMatch> > matches(2);
TestSystem::instance().setAccurate(1, 0); Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
else declare.in(query, train);
TestSystem::instance().setAccurate(0, diff); Mat trainIdx, distance, allDist;
randu(query, 0.0f, 1.0f);
randu(train, 0.0f, 1.0f);
if (impl == "plain")
{
BFMatcher matcher (NORM_L2);
TEST_CYCLE() matcher.radiusMatch(query, matches, max_distance);
std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
SANITY_CHECK_MATCHES(matches0);
SANITY_CHECK_MATCHES(matches1);
} }
else if (impl == "ocl")
{
ocl::oclMat oclQuery(query), oclTrain(train);
ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
TEST_CYCLE() oclMatcher.radiusMatch(oclQuery, oclTrain, matches, max_distance);
std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
SANITY_CHECK_MATCHES(matches0);
SANITY_CHECK_MATCHES(matches1);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
}
//PERF_TEST_P(BruteForceMatcherFixture, radiusMatchSingle,
// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
//{
// const Size srcSize = GetParam();
// const string impl = getSelectedImpl();
// const float max_distance = 2.0f;
// Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
// Mat trainIdx, distance, nMatches;
// randu(query, 0.0f, 1.0f);
// randu(train, 0.0f, 1.0f);
// if (impl == "plain")
// CV_TEST_FAIL_NO_IMPL();
// else if (impl == "ocl")
// {
// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance, oclNMatches;
// TEST_CYCLE() oclMatcher->radiusMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclNMatches, max_distance);
// oclTrainIdx.download(trainIdx);
// oclDistance.download(distance);
// oclNMatches.download(nMatches);
// SANITY_CHECK(trainIdx);
// SANITY_CHECK(distance);
// SANITY_CHECK(nMatches);
// }
//#ifdef HAVE_OPENCV_GPU
// else if (impl == "gpu")
// CV_TEST_FAIL_NO_IMPL();
//#endif
// else
// CV_TEST_FAIL_NO_IMPL();
//}
#undef OCL_BFMATCHER_TYPICAL_MAT_SIZES

@ -45,48 +45,49 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// StereoMatchBM //////////////////////// ///////////// StereoMatchBM ////////////////////////
PERFTEST(StereoMatchBM)
PERF_TEST(StereoMatchBMFixture, DISABLED_StereoMatchBM)
{ {
Mat left_image = imread(abspath("aloeL.jpg"), cv::IMREAD_GRAYSCALE); Mat left_image = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
Mat right_image = imread(abspath("aloeR.jpg"), cv::IMREAD_GRAYSCALE); Mat right_image = imread(getDataPath("gpu/stereobm/aloe-R.png"), cv::IMREAD_GRAYSCALE);
Mat disp,dst;
ocl::oclMat d_left, d_right,d_disp;
int n_disp= 128;
int winSize =19;
SUBTEST << left_image.cols << 'x' << left_image.rows << "; aloeL.jpg ;"<< right_image.cols << 'x' << right_image.rows << "; aloeR.jpg "; ASSERT_TRUE(!left_image.empty()) << "no input image";
ASSERT_TRUE(!right_image.empty()) << "no input image";
ASSERT_TRUE(right_image.size() == left_image.size());
ASSERT_TRUE(right_image.size() == left_image.size());
StereoBM bm(0, n_disp, winSize); const std::string impl = getSelectedImpl();
bm(left_image, right_image, dst); const int n_disp = 128, winSize = 19;
Mat disp(left_image.size(), CV_16SC1);
CPU_ON; declare.in(left_image, right_image).out(disp);
bm(left_image, right_image, dst);
CPU_OFF;
d_left.upload(left_image); if (impl == "ocl")
d_right.upload(right_image); {
ocl::oclMat oclLeft(left_image), oclRight(right_image),
ocl::StereoBM_OCL d_bm(0, n_disp, winSize); oclDisp(left_image.size(), CV_16SC1);
ocl::StereoBM_OCL oclBM(0, n_disp, winSize);
WARMUP_ON; TEST_CYCLE() oclBM(oclLeft, oclRight, oclDisp);
d_bm(d_left, d_right, d_disp);
WARMUP_OFF;
cv::Mat ocl_mat; oclDisp.download(disp);
d_disp.download(ocl_mat);
ocl_mat.convertTo(ocl_mat, dst.type());
GPU_ON; SANITY_CHECK(disp);
d_bm(d_left, d_right, d_disp); }
GPU_OFF; else if (impl == "plain")
{
StereoBM bm(0, n_disp, winSize);
GPU_FULL_ON; TEST_CYCLE() bm(left_image, right_image, disp);
d_left.upload(left_image);
d_right.upload(right_image);
d_bm(d_left, d_right, d_disp);
d_disp.download(disp);
GPU_FULL_OFF;
TestSystem::instance().setAccurate(-1, 0.); SANITY_CHECK(disp);
}
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,41 +45,38 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// Canny //////////////////////// ///////////// Canny ////////////////////////
PERFTEST(Canny)
{
Mat img = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
if (img.empty()) PERF_TEST(CannyFixture, Canny)
{ {
throw runtime_error("can't open aloeL.jpg"); Mat img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE),
} edges(img.size(), CV_8UC1);
ASSERT_TRUE(!img.empty()) << "can't open aloeL.jpg";
SUBTEST << img.cols << 'x' << img.rows << "; aloeL.jpg" << "; edges" << "; CV_8UC1";
Mat edges(img.size(), CV_8UC1), ocl_edges;
CPU_ON; const std::string impl = getSelectedImpl();
Canny(img, edges, 50.0, 100.0); declare.in(img).out(edges);
CPU_OFF;
ocl::oclMat d_img(img); if (impl == "ocl")
ocl::oclMat d_edges; {
ocl::CannyBuf d_buf; ocl::oclMat oclImg(img), oclEdges(img.size(), CV_8UC1);
WARMUP_ON;
ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
WARMUP_OFF;
GPU_ON; TEST_CYCLE() Canny(oclImg, oclEdges, 50.0, 100.0);
ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0); oclEdges.download(edges);
GPU_OFF;
GPU_FULL_ON; SANITY_CHECK(edges);
d_img.upload(img); }
ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0); else if (impl == "plain")
d_edges.download(ocl_edges); {
GPU_FULL_OFF; TEST_CYCLE() Canny(img, edges, 50.0, 100.0);
TestSystem::instance().ExceptedMatSimilar(edges, ocl_edges, 2e-2); SANITY_CHECK(edges);
}
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,49 +45,39 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// cvtColor//////////////////////// ///////////// cvtColor////////////////////////
PERFTEST(cvtColor)
{
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_8UC4}; typedef TestBaseWithParam<Size> cvtColorFixture;
std::string type_name[] = {"CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(cvtColorFixture, cvtColor, OCL_TYPICAL_MAT_SIZES)
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{ {
gen(src, size, size, all_type[j], 0, 256); const Size srcSize = GetParam();
SUBTEST << size << "x" << size << "; " << type_name[j] << " ; CV_RGBA2GRAY"; const std::string impl = getSelectedImpl();
cvtColor(src, dst, CV_RGBA2GRAY, 4);
CPU_ON;
cvtColor(src, dst, CV_RGBA2GRAY, 4);
CPU_OFF;
d_src.upload(src);
WARMUP_ON; Mat src(srcSize, CV_8UC4), dst(srcSize, CV_8UC4);
ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4); declare.in(src).out(dst);
WARMUP_OFF;
GPU_ON; if (impl == "ocl")
ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4); {
GPU_OFF; ocl::oclMat oclSrc(src), oclDst(src.size(), CV_8UC4);
GPU_FULL_ON; TEST_CYCLE() ocl::cvtColor(oclSrc, oclDst, CV_RGBA2GRAY, 4);
d_src.upload(src); oclDst.download(dst);
ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExceptedMatSimilar(dst, ocl_dst, 1e-5); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::cvtColor(src, dst, CV_RGBA2GRAY, 4);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,47 +45,43 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// dft //////////////////////// ///////////// dft ////////////////////////
PERFTEST(dft)
{
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_32FC2}; typedef TestBaseWithParam<Size> dftFixture;
std::string type_name[] = {"CV_32FC2"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(dftFixture, DISABLED_dft, OCL_TYPICAL_MAT_SIZES)
{ {
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) const std::string impl = getSelectedImpl();
{ Size srcSize = GetParam();
SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; complex-to-complex";
gen(src, size, size, all_type[j], Scalar::all(0), Scalar::all(1));
dft(src, dst); Mat src(srcSize, CV_32FC2), dst;
randu(src, 0.0f, 1.0f);
declare.in(src);
CPU_ON; if (impl == "ocl")
dft(src, dst); {
CPU_OFF; ocl::oclMat oclSrc(src), oclDst;
d_src.upload(src);
WARMUP_ON;
ocl::dft(d_src, d_dst, Size(size, size));
WARMUP_OFF;
GPU_ON; EXPECT_NO_THROW({
ocl::dft(d_src, d_dst, Size(size, size)); TEST_CYCLE() cv::ocl::dft(oclSrc, oclDst);
GPU_OFF; });
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::dft(d_src, d_dst, Size(size, size));
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, src.size().area() * 1e-4); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::dft(src, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,333 +45,344 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
using std::tr1::get;
using std::tr1::tuple;
///////////// Blur//////////////////////// ///////////// Blur////////////////////////
PERFTEST(Blur)
{
Mat src1, dst, ocl_dst;
ocl::oclMat d_src1, d_dst;
Size ksize = Size(3, 3); CV_ENUM(BlurMatType, CV_8UC1, CV_8UC4)
int bordertype = BORDER_CONSTANT;
int all_type[] = {CV_8UC1, CV_8UC4};
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef tuple<Size, BlurMatType> BlurParams;
{ typedef TestBaseWithParam<BlurParams> BlurFixture;
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src1, size, size, all_type[j], 0, 256); PERF_TEST_P(BlurFixture, Blur,
gen(dst, size, size, all_type[j], 0, 256); ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
BlurMatType::all()))
{
// getting params
BlurParams params = GetParam();
const Size srcSize = get<0>(params), ksize(3, 3);
const int type = get<1>(params), bordertype = BORDER_CONSTANT;
blur(src1, dst, ksize, Point(-1, -1), bordertype); const std::string impl = getSelectedImpl();
CPU_ON; Mat src(srcSize, type), dst(srcSize, type);
blur(src1, dst, ksize, Point(-1, -1), bordertype); declare.in(src, WARMUP_RNG).out(dst);
CPU_OFF;
d_src1.upload(src1); if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
declare.time(5);
WARMUP_ON; if (impl == "ocl")
ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype); {
WARMUP_OFF; ocl::oclMat oclSrc(src), oclDst(srcSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::blur(oclSrc, oclDst, ksize, Point(-1, -1), bordertype);
ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src1.upload(src1);
ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0); SANITY_CHECK(dst, 1 + DBL_EPSILON);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::blur(src, dst, ksize, Point(-1, -1), bordertype);
SANITY_CHECK(dst, 1 + DBL_EPSILON);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// Laplacian//////////////////////// ///////////// Laplacian////////////////////////
PERFTEST(Laplacian)
{
Mat src1, dst, ocl_dst;
ocl::oclMat d_src1, d_dst;
int ksize = 3; typedef BlurMatType LaplacianMatType;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef tuple<Size, LaplacianMatType> LaplacianParams;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"}; typedef TestBaseWithParam<LaplacianParams> LaplacianFixture;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(LaplacianFixture, Laplacian,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
LaplacianMatType::all()))
{ {
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) // getting params
{ LaplacianParams params = GetParam();
SUBTEST << size << 'x' << size << "; " << type_name[j] ; const Size srcSize = get<0>(params);
const int type = get<1>(params), ksize = 3;
gen(src1, size, size, all_type[j], 0, 256);
gen(dst, size, size, all_type[j], 0, 256);
Laplacian(src1, dst, -1, ksize, 1); const std::string impl = getSelectedImpl();
CPU_ON; Mat src(srcSize, type), dst(srcSize, type);
Laplacian(src1, dst, -1, ksize, 1); declare.in(src, WARMUP_RNG).out(dst);
CPU_OFF;
d_src1.upload(src1); if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
declare.time(6);
WARMUP_ON; if (impl == "ocl")
ocl::Laplacian(d_src1, d_dst, -1, ksize, 1); {
WARMUP_OFF; ocl::oclMat oclSrc(src), oclDst(srcSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::Laplacian(oclSrc, oclDst, -1, ksize, 1);
ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src1.upload(src1);
ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize, 1);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// Erode //////////////////// ///////////// Erode ////////////////////
PERFTEST(Erode)
{
Mat src, dst, ker, ocl_dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4}; CV_ENUM(ErodeMatType, CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4)
std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef tuple<Size, ErodeMatType> ErodeParams;
{ typedef TestBaseWithParam<ErodeParams> ErodeFixture;
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src, size, size, all_type[j], Scalar::all(0), Scalar::all(256)); PERF_TEST_P(ErodeFixture, Erode,
ker = getStructuringElement(MORPH_RECT, Size(3, 3)); ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
ErodeMatType::all()))
{
// getting params
ErodeParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params), ksize = 3;
const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize));
erode(src, dst, ker); const std::string impl = getSelectedImpl();
CPU_ON; Mat src(srcSize, type), dst(srcSize, type);
erode(src, dst, ker); declare.in(src, WARMUP_RNG).out(dst).in(ker);
CPU_OFF;
d_src.upload(src); if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
declare.time(5);
WARMUP_ON; if (impl == "ocl")
ocl::erode(d_src, d_dst, ker); {
WARMUP_OFF; ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKer(ker);
GPU_ON; TEST_CYCLE() cv::ocl::erode(oclSrc, oclDst, oclKer);
ocl::erode(d_src, d_dst, ker);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::erode(d_src, d_dst, ker);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::erode(src, dst, ker);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// Sobel //////////////////////// ///////////// Sobel ////////////////////////
PERFTEST(Sobel)
{
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int dx = 1; typedef BlurMatType SobelMatType;
int dy = 1; typedef tuple<Size, SobelMatType> SobelMatParams;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef TestBaseWithParam<SobelMatParams> SobelFixture;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(SobelFixture, Sobel,
{ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) SobelMatType::all()))
{ {
SUBTEST << size << 'x' << size << "; " << type_name[j] ; // getting params
SobelMatParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params), dx = 1, dy = 1;
gen(src, size, size, all_type[j], 0, 256); const std::string impl = getSelectedImpl();
Sobel(src, dst, -1, dx, dy); Mat src(srcSize, type), dst(srcSize, type);
declare.in(src, WARMUP_RNG).out(dst);
CPU_ON; if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) ||
Sobel(src, dst, -1, dx, dy); (srcSize == OCL_SIZE_4000 && type == CV_8UC1))
CPU_OFF; declare.time(5.5);
else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
declare.time(20);
d_src.upload(src); if (impl == "ocl")
{
WARMUP_ON; ocl::oclMat oclSrc(src), oclDst(srcSize, type);
ocl::Sobel(d_src, d_dst, -1, dx, dy);
WARMUP_OFF;
GPU_ON; TEST_CYCLE() cv::ocl::Sobel(oclSrc, oclDst, -1, dx, dy);
ocl::Sobel(d_src, d_dst, -1, dx, dy);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::Sobel(d_src, d_dst, -1, dx, dy);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::Sobel(src, dst, -1, dx, dy);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// Scharr //////////////////////// ///////////// Scharr ////////////////////////
PERFTEST(Scharr)
{
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int dx = 1; typedef BlurMatType ScharrMatType;
int dy = 0; typedef tuple<Size, ScharrMatType> ScharrParams;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef TestBaseWithParam<ScharrParams> ScharrFixture;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(ScharrFixture, Scharr,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
ScharrMatType::all()))
{ {
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) // getting params
{ ScharrParams params = GetParam();
SUBTEST << size << 'x' << size << "; " << type_name[j] ; const Size srcSize = get<0>(params);
const int type = get<1>(params), dx = 1, dy = 0;
gen(src, size, size, all_type[j], 0, 256);
Scharr(src, dst, -1, dx, dy); const std::string impl = getSelectedImpl();
CPU_ON; Mat src(srcSize, type), dst(srcSize, type);
Scharr(src, dst, -1, dx, dy); declare.in(src, WARMUP_RNG).out(dst);
CPU_OFF;
d_src.upload(src); if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) ||
(srcSize == OCL_SIZE_4000 && type == CV_8UC1))
declare.time(5.5);
else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
declare.time(21);
WARMUP_ON; if (impl == "ocl")
ocl::Scharr(d_src, d_dst, -1, dx, dy); {
WARMUP_OFF; ocl::oclMat oclSrc(src), oclDst(srcSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::Scharr(oclSrc, oclDst, -1, dx, dy);
ocl::Scharr(d_src, d_dst, -1, dx, dy);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::Scharr(d_src, d_dst, -1, dx, dy);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::Scharr(src, dst, -1, dx, dy);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// GaussianBlur //////////////////////// ///////////// GaussianBlur ////////////////////////
PERFTEST(GaussianBlur)
{
Mat src, dst, ocl_dst;
int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
const int ksize = 7;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef ErodeMatType GaussianBlurMatType;
{ typedef tuple<Size, GaussianBlurMatType> GaussianBlurParams;
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) typedef TestBaseWithParam<GaussianBlurParams> GaussianBlurFixture;
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src, size, size, all_type[j], 0, 256); PERF_TEST_P(GaussianBlurFixture, GaussianBlur,
::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
GaussianBlurMatType::all()))
{
// getting params
GaussianBlurParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params), ksize = 7;
GaussianBlur(src, dst, Size(ksize, ksize), 0); const std::string impl = getSelectedImpl();
CPU_ON; Mat src(srcSize, type), dst(srcSize, type);
GaussianBlur(src, dst, Size(ksize, ksize), 0); declare.in(src, WARMUP_RNG).out(dst);
CPU_OFF;
ocl::oclMat d_src(src); const double eps = src.depth() == CV_8U ? 1 + DBL_EPSILON : 3e-4;
ocl::oclMat d_dst;
WARMUP_ON; if (impl == "ocl")
ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0); {
WARMUP_OFF; ocl::oclMat oclSrc(src), oclDst(srcSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::GaussianBlur(oclSrc, oclDst, Size(ksize, ksize), 0);
ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0); SANITY_CHECK(dst, eps);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::GaussianBlur(src, dst, Size(ksize, ksize), 0);
SANITY_CHECK(dst, eps);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// filter2D//////////////////////// ///////////// filter2D////////////////////////
PERFTEST(filter2D)
{
Mat src;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef BlurMatType filter2DMatType;
{ typedef tuple<Size, filter2DMatType> filter2DParams;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef TestBaseWithParam<filter2DParams> filter2DFixture;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) PERF_TEST_P(filter2DFixture, filter2D,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
filter2DMatType::all()))
{ {
gen(src, size, size, all_type[j], 0, 256); // getting params
filter2DParams params = GetParam();
const int ksize = 3; const Size srcSize = get<0>(params);
const int type = get<1>(params), ksize = 3;
SUBTEST << "ksize = " << ksize << "; " << size << 'x' << size << "; " << type_name[j] ;
Mat kernel;
gen(kernel, ksize, ksize, CV_32SC1, -3.0, 3.0);
Mat dst, ocl_dst; const std::string impl = getSelectedImpl();
cv::filter2D(src, dst, -1, kernel); Mat src(srcSize, type), dst(srcSize, type), kernel(ksize, ksize, CV_32SC1);
declare.in(src, WARMUP_RNG).in(kernel).out(dst);
randu(kernel, -3.0, 3.0);
CPU_ON; if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
cv::filter2D(src, dst, -1, kernel); declare.time(8);
CPU_OFF;
ocl::oclMat d_src(src), d_dst; if (impl == "ocl")
{
WARMUP_ON; ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKernel(kernel);
ocl::filter2D(d_src, d_dst, -1, kernel);
WARMUP_OFF;
GPU_ON;
ocl::filter2D(d_src, d_dst, -1, kernel);
GPU_OFF;
GPU_FULL_ON; TEST_CYCLE() cv::ocl::filter2D(oclSrc, oclDst, -1, oclKernel);
d_src.upload(src);
ocl::filter2D(d_src, d_dst, -1, kernel);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5); oclDst.download(dst);
SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::filter2D(src, dst, -1, kernel);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,46 +45,46 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// gemm //////////////////////// using namespace perf;
PERFTEST(gemm)
{
Mat src1, src2, src3, dst, ocl_dst;
ocl::oclMat d_src1, d_src2, d_src3, d_dst;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) ///////////// gemm ////////////////////////
{
SUBTEST << size << 'x' << size;
gen(src1, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10)); typedef TestBaseWithParam<Size> gemmFixture;
gen(src2, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
gen(src3, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
gemm(src1, src2, 1.0, src3, 1.0, dst); PERF_TEST_P(gemmFixture, DISABLED_gemm, OCL_TYPICAL_MAT_SIZES)
{
// getting params
const Size srcSize = GetParam();
const std::string impl = getSelectedImpl();
CPU_ON; Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
gemm(src1, src2, 1.0, src3, 1.0, dst); src3(srcSize, CV_32FC1), dst(srcSize, CV_32FC1);
CPU_OFF; declare.in(src1, src2, src3).out(dst);
randu(src1, -10.0f, 10.0f);
randu(src2, -10.0f, 10.0f);
randu(src3, -10.0f, 10.0f);
d_src1.upload(src1); if (impl == "ocl")
d_src2.upload(src2); {
d_src3.upload(src3); ocl::oclMat oclSrc1(src1), oclSrc2(src2),
oclSrc3(src3), oclDst(srcSize, CV_32FC1);
WARMUP_ON; TEST_CYCLE() cv::ocl::gemm(oclSrc1, oclSrc2, 1.0, oclSrc3, 1.0, oclDst);
ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
WARMUP_OFF;
GPU_ON; oclDst.download(dst);
ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
GPU_OFF;
GPU_FULL_ON; SANITY_CHECK(dst);
d_src1.upload(src1); }
d_src2.upload(src2); else if (impl == "plain")
d_src3.upload(src3); {
ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst); TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(ocl_dst, dst, src1.cols * src1.rows * 1e-4); SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -46,56 +46,54 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// GoodFeaturesToTrack //////////////////////// using namespace perf;
PERFTEST(GoodFeaturesToTrack) using std::tr1::tuple;
{ using std::tr1::get;
using namespace cv;
int maxCorners = 2000;
double qualityLevel = 0.01;
std::string images[] = { "rubberwhale1.png", "aloeL.jpg" }; ///////////// GoodFeaturesToTrack ////////////////////////
std::vector<cv::Point2f> pts_gold, pts_ocl;
for(size_t imgIdx = 0; imgIdx < (sizeof(images)/sizeof(std::string)); ++imgIdx) typedef tuple<string, double> GoodFeaturesToTrackParams;
{ typedef TestBaseWithParam<GoodFeaturesToTrackParams> GoodFeaturesToTrackFixture;
Mat frame = imread(abspath(images[imgIdx]), IMREAD_GRAYSCALE);
CV_Assert(!frame.empty());
for(float minDistance = 0; minDistance < 4; minDistance += 3.0) PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack,
::testing::Combine(::testing::Values(string("gpu/opticalflow/rubberwhale1.png"),
string("gpu/stereobm/aloe-L.png")),
::testing::Range(0.0, 4.0, 3.0)))
{ {
SUBTEST << "image = " << images[imgIdx] << "; "; std::vector<cv::Point2f> pts_gold;
SUBTEST << "minDistance = " << minDistance << "; ";
cv::goodFeaturesToTrack(frame, pts_gold, maxCorners, qualityLevel, minDistance); // getting params
GoodFeaturesToTrackParams param = GetParam();
const string fileName = getDataPath(get<0>(param)), impl = getSelectedImpl();
const int maxCorners = 2000;
const double qualityLevel = 0.01, minDistance = get<1>(param);
CPU_ON; Mat frame = imread(fileName, IMREAD_GRAYSCALE);
cv::goodFeaturesToTrack(frame, pts_gold, maxCorners, qualityLevel, minDistance); declare.in(frame);
CPU_OFF; ASSERT_TRUE(!frame.empty()) << "no input image";
if (impl == "ocl")
{
ocl::oclMat oclFrame(frame), pts_oclmat;
cv::ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance); cv::ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance);
ocl::oclMat frame_ocl(frame), pts_oclmat; TEST_CYCLE() detector(oclFrame, pts_oclmat);
WARMUP_ON;
detector(frame_ocl, pts_oclmat);
WARMUP_OFF;
detector.downloadPoints(pts_oclmat, pts_ocl);
double diff = abs(static_cast<float>(pts_gold.size() - pts_ocl.size())); detector.downloadPoints(pts_oclmat, pts_gold);
TestSystem::instance().setAccurate(diff == 0.0, diff);
GPU_ON; SANITY_CHECK(pts_gold);
detector(frame_ocl, pts_oclmat);
GPU_OFF;
GPU_FULL_ON;
frame_ocl.upload(frame);
detector(frame_ocl, pts_oclmat);
detector.downloadPoints(pts_oclmat, pts_ocl);
GPU_FULL_OFF;
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::goodFeaturesToTrack(frame, pts_gold,
maxCorners, qualityLevel, minDistance);
SANITY_CHECK(pts_gold);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,6 +45,8 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// Haar //////////////////////// ///////////// Haar ////////////////////////
namespace cv namespace cv
{ {
@ -83,61 +85,45 @@ public:
} }
} }
PERFTEST(Haar)
{
Mat img = imread(abspath("basketball1.png"), CV_LOAD_IMAGE_GRAYSCALE);
if (img.empty()) PERF_TEST(HaarFixture, Haar)
{ {
throw runtime_error("can't open basketball1.png"); const std::string impl = getSelectedImpl();
} vector<Rect> faces;
CascadeClassifier faceCascadeCPU; Mat img = imread(getDataPath("gpu/haarcascade/basketball1.png"), CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_TRUE(!img.empty()) << "can't open basketball1.png";
declare.in(img);
if (!faceCascadeCPU.load(abspath("haarcascade_frontalface_alt.xml"))) if (impl == "plain")
{ {
throw runtime_error("can't load haarcascade_frontalface_alt.xml"); CascadeClassifier faceCascade;
} ASSERT_TRUE(faceCascade.load(getDataPath("gpu/haarcascade/haarcascade_frontalface_alt.xml")))
<< "can't load haarcascade_frontalface_alt.xml";
vector<Rect> faces; TEST_CYCLE() faceCascade.detectMultiScale(img, faces,
SUBTEST << img.cols << "x" << img.rows << "; scale image";
CPU_ON;
faceCascadeCPU.detectMultiScale(img, faces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
CPU_OFF;
vector<Rect> oclfaces;
ocl::CascadeClassifier_GPU faceCascade;
if (!faceCascade.load(abspath("haarcascade_frontalface_alt.xml"))) SANITY_CHECK(faces, 4 + 1e-4);
{
throw runtime_error("can't load haarcascade_frontalface_alt.xml");
} }
else if (impl == "ocl")
{
ocl::CascadeClassifier_GPU faceCascade;
ocl::oclMat oclImg(img);
ocl::oclMat d_img(img); ASSERT_TRUE(faceCascade.load(getDataPath("gpu/haarcascade/haarcascade_frontalface_alt.xml")))
<< "can't load haarcascade_frontalface_alt.xml";
WARMUP_ON; TEST_CYCLE() faceCascade.detectMultiScale(oclImg, faces,
faceCascade.detectMultiScale(d_img, oclfaces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
WARMUP_OFF;
if(faces.size() == oclfaces.size())
TestSystem::instance().setAccurate(1, 0);
else
TestSystem::instance().setAccurate(0, abs((int)faces.size() - (int)oclfaces.size()));
faces.clear(); SANITY_CHECK(faces, 4 + 1e-4);
}
GPU_ON;
faceCascade.detectMultiScale(d_img, oclfaces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
GPU_OFF;
GPU_FULL_ON; #ifdef HAVE_OPENCV_GPU
d_img.upload(img); else if (impl == "gpu")
faceCascade.detectMultiScale(d_img, oclfaces, CV_TEST_FAIL_NO_IMPL();
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); #endif
GPU_FULL_OFF; else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,50 +45,42 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
///////////// HOG//////////////////////// ///////////// HOG////////////////////////
PERFTEST(HOG) PERF_TEST(HOGFixture, HOG)
{ {
Mat src = imread(abspath("road.png"), cv::IMREAD_GRAYSCALE); Mat src = imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE);
ASSERT_TRUE(!src.empty()) << "can't open input image road.png";
if (src.empty()) const std::string impl = getSelectedImpl();
{ std::vector<cv::Rect> found_locations;
throw runtime_error("can't open road.png"); declare.in(src).time(5);
}
if (impl == "plain")
{
cv::HOGDescriptor hog; cv::HOGDescriptor hog;
hog.setSVMDetector(hog.getDefaultPeopleDetector()); hog.setSVMDetector(hog.getDefaultPeopleDetector());
std::vector<cv::Rect> found_locations;
std::vector<cv::Rect> d_found_locations;
SUBTEST << src.cols << 'x' << src.rows << "; road.png";
hog.detectMultiScale(src, found_locations); TEST_CYCLE() hog.detectMultiScale(src, found_locations);
CPU_ON;
hog.detectMultiScale(src, found_locations);
CPU_OFF;
SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
}
else if (impl == "ocl")
{
cv::ocl::HOGDescriptor ocl_hog; cv::ocl::HOGDescriptor ocl_hog;
ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector()); ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector());
ocl::oclMat d_src; ocl::oclMat oclSrc(src);
d_src.upload(src);
WARMUP_ON; TEST_CYCLE() ocl_hog.detectMultiScale(oclSrc, found_locations);
ocl_hog.detectMultiScale(d_src, d_found_locations);
WARMUP_OFF;
if(d_found_locations.size() == found_locations.size()) SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
TestSystem::instance().setAccurate(1, 0); }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else else
TestSystem::instance().setAccurate(0, abs((int)found_locations.size() - (int)d_found_locations.size())); CV_TEST_FAIL_NO_IMPL();
GPU_ON;
ocl_hog.detectMultiScale(d_src, found_locations);
GPU_OFF;
GPU_FULL_ON;
d_src.upload(src);
ocl_hog.detectMultiScale(d_src, found_locations);
GPU_FULL_OFF;
} }

File diff suppressed because it is too large Load Diff

@ -45,101 +45,97 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
using std::tr1::tuple;
using std::tr1::get;
/////////// matchTemplate //////////////////////// /////////// matchTemplate ////////////////////////
//void InitMatchTemplate()
//{
// Mat src; gen(src, 500, 500, CV_32F, 0, 1);
// Mat templ; gen(templ, 500, 500, CV_32F, 0, 1);
// ocl::oclMat d_src(src), d_templ(templ), d_dst;
// ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
//}
PERFTEST(matchTemplate)
{
//InitMatchTemplate();
Mat src, templ, dst, ocl_dst;
int templ_size = 5;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) CV_ENUM(CV_TM_CCORRMatType, CV_32FC1, CV_32FC4)
{
int all_type[] = {CV_32FC1, CV_32FC4};
std::string type_name[] = {"CV_32FC1", "CV_32FC4"};
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) typedef tuple<Size, CV_TM_CCORRMatType> CV_TM_CCORRParams;
typedef TestBaseWithParam<CV_TM_CCORRParams> CV_TM_CCORRFixture;
PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate,
::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
CV_TM_CCORRMatType::all()))
{ {
for(templ_size = 5; templ_size <= 5; templ_size *= 5) // getting params
CV_TM_CCORRParams params = GetParam();
const Size srcSize = get<0>(params), templSize(5, 5);
const int type = get<1>(params);
std::string impl = getSelectedImpl();
// creating src data
Mat src(srcSize, type), templ(templSize, type);
const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
Mat dst(dstSize, CV_32F);
randu(src, 0.0f, 1.0f);
randu(templ, 0.0f, 1.0f);
declare.time(srcSize == OCL_SIZE_2000 ? 20 : 6).in(src, templ).out(dst);
// select implementation
if (impl == "ocl")
{ {
gen(src, size, size, all_type[j], 0, 1); ocl::oclMat oclSrc(src), oclTempl(templ), oclDst(dstSize, CV_32F);
SUBTEST << src.cols << 'x' << src.rows << "; " << type_name[j] << "; templ " << templ_size << 'x' << templ_size << "; CCORR";
gen(templ, templ_size, templ_size, all_type[j], 0, 1); TEST_CYCLE() cv::ocl::matchTemplate(oclSrc, oclTempl, oclDst, CV_TM_CCORR);
matchTemplate(src, templ, dst, CV_TM_CCORR); oclDst.download(dst);
CPU_ON; SANITY_CHECK(dst, 1e-4);
matchTemplate(src, templ, dst, CV_TM_CCORR); }
CPU_OFF; else if (impl == "plain")
{
ocl::oclMat d_src(src), d_templ(templ), d_dst; TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR);
WARMUP_ON;
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
WARMUP_OFF;
GPU_ON;
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
GPU_OFF;
GPU_FULL_ON;
d_src.upload(src);
d_templ.upload(templ);
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, templ.rows * templ.cols * 1e-1); SANITY_CHECK(dst, 1e-4);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
int all_type_8U[] = {CV_8UC1}; typedef TestBaseWithParam<Size> CV_TM_CCORR_NORMEDFixture;
std::string type_name_8U[] = {"CV_8UC1"};
for (size_t j = 0; j < sizeof(all_type_8U) / sizeof(int); j++) PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate, OCL_TYPICAL_MAT_SIZES)
{ {
for(templ_size = 5; templ_size <= 5; templ_size *= 5) // getting params
const Size srcSize = GetParam(), templSize(5, 5);
const std::string impl = getSelectedImpl();
// creating src data
Mat src(srcSize, CV_8UC1), templ(templSize, CV_8UC1), dst;
const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
dst.create(dstSize, CV_8UC1);
declare.in(src, templ, WARMUP_RNG).out(dst)
.time(srcSize == OCL_SIZE_2000 ? 10 : srcSize == OCL_SIZE_4000 ? 23 : 2);
// select implementation
if (impl == "ocl")
{ {
SUBTEST << src.cols << 'x' << src.rows << "; " << type_name_8U[j] << "; templ " << templ_size << 'x' << templ_size << "; CCORR_NORMED"; ocl::oclMat oclSrc(src), oclTempl(templ), oclDst(dstSize, CV_8UC1);
gen(src, size, size, all_type_8U[j], 0, 255);
gen(templ, templ_size, templ_size, all_type_8U[j], 0, 255);
matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
CPU_ON;
matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
CPU_OFF;
ocl::oclMat d_src(src); TEST_CYCLE() cv::ocl::matchTemplate(oclSrc, oclTempl, oclDst, CV_TM_CCORR_NORMED);
ocl::oclMat d_templ(templ), d_dst;
WARMUP_ON; oclDst.download(dst);
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
WARMUP_OFF;
GPU_ON; SANITY_CHECK(dst, 2e-2);
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
GPU_OFF;
GPU_FULL_ON;
d_src.upload(src);
d_templ.upload(templ);
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, templ.rows * templ.cols * 1e-1);
}
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
SANITY_CHECK(dst, 2e-2);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,142 +45,147 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// ConvertTo//////////////////////// using namespace perf;
PERFTEST(ConvertTo) using std::tr1::tuple;
{ using std::tr1::get;
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_8UC1, CV_8UC4}; ///////////// ConvertTo////////////////////////
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple)
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] << " to 32FC1";
gen(src, size, size, all_type[j], 0, 256); CV_ENUM(ConvertToMatType, CV_8UC1, CV_8UC4)
//gen(dst, size, size, all_type[j], 0, 256);
//d_dst.upload(dst); typedef tuple<Size, ConvertToMatType> ConvertToParams;
typedef TestBaseWithParam<ConvertToParams> ConvertToFixture;
src.convertTo(dst, CV_32FC1); PERF_TEST_P(ConvertToFixture, ConvertTo,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
ConvertToMatType::all()))
{
// getting params
ConvertToParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params);
CPU_ON; std::string impl = getSelectedImpl();
src.convertTo(dst, CV_32FC1);
CPU_OFF;
d_src.upload(src); // creating src data
Mat src(srcSize, type), dst;
const int dstType = CV_MAKE_TYPE(CV_32F, src.channels());
dst.create(srcSize, dstType);
declare.in(src, WARMUP_RNG).out(dst);
WARMUP_ON; // select implementation
d_src.convertTo(d_dst, CV_32FC1); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclSrc(src), oclDst(srcSize, dstType);
GPU_ON; TEST_CYCLE() oclSrc.convertTo(oclDst, dstType);
d_src.convertTo(d_dst, CV_32FC1);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
d_src.convertTo(d_dst, CV_32FC1);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() src.convertTo(dst, dstType);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// copyTo//////////////////////// ///////////// copyTo////////////////////////
PERFTEST(copyTo)
{
Mat src, dst, ocl_dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef ConvertToMatType copyToMatType;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"}; typedef tuple<Size, copyToMatType> copyToParams;
typedef TestBaseWithParam<copyToParams> copyToFixture;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(copyToFixture, copyTo,
{ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) copyToMatType::all()))
{ {
SUBTEST << size << 'x' << size << "; " << type_name[j] ; // getting params
copyToParams params = GetParam();
gen(src, size, size, all_type[j], 0, 256); const Size srcSize = get<0>(params);
//gen(dst, size, size, all_type[j], 0, 256); const int type = get<1>(params);
//d_dst.upload(dst); std::string impl = getSelectedImpl();
src.copyTo(dst); // creating src data
Mat src(srcSize, type), dst(srcSize, type);
declare.in(src, WARMUP_RNG).out(dst);
CPU_ON; // select implementation
src.copyTo(dst); if (impl == "ocl")
CPU_OFF; {
ocl::oclMat oclSrc(src), oclDst(srcSize, type);
d_src.upload(src);
WARMUP_ON;
d_src.copyTo(d_dst);
WARMUP_OFF;
GPU_ON; TEST_CYCLE() oclSrc.copyTo(oclDst);
d_src.copyTo(d_dst);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
d_src.copyTo(d_dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() src.copyTo(dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// setTo//////////////////////// ///////////// setTo////////////////////////
PERFTEST(setTo)
{
Mat src, ocl_src;
Scalar val(1, 2, 3, 4);
ocl::oclMat d_src;
int all_type[] = {CV_8UC1, CV_8UC4}; typedef ConvertToMatType setToMatType;
std::string type_name[] = {"CV_8UC1", "CV_8UC4"}; typedef tuple<Size, setToMatType> setToParams;
typedef TestBaseWithParam<setToParams> setToFixture;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) PERF_TEST_P(setToFixture, setTo,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
setToMatType::all()))
{ {
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++) // getting params
{ setToParams params = GetParam();
SUBTEST << size << 'x' << size << "; " << type_name[j] ; const Size srcSize = get<0>(params);
const int type = get<1>(params);
gen(src, size, size, all_type[j], 0, 256); const Scalar val(1, 2, 3, 4);
src.setTo(val);
CPU_ON; std::string impl = getSelectedImpl();
src.setTo(val);
CPU_OFF;
d_src.upload(src); // creating src data
Mat src(srcSize, type);
declare.in(src);
WARMUP_ON; // select implementation
d_src.setTo(val); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclSrc(srcSize, type);
d_src.download(ocl_src);
TestSystem::instance().ExpectedMatNear(src, ocl_src, 1.0);
GPU_ON;; TEST_CYCLE() oclSrc.setTo(val);
d_src.setTo(val); oclSrc.download(src);
GPU_OFF;
GPU_FULL_ON; SANITY_CHECK(src);
d_src.upload(src);
d_src.setTo(val);
GPU_FULL_OFF;
} }
else if (impl == "plain")
{
TEST_CYCLE() src.setTo(val);
SANITY_CHECK(src);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -43,50 +43,59 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// Moments ////////////////////////
PERFTEST(Moments)
{
Mat src;
bool binaryImage = 0;
int all_type[] = {CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1}; using namespace perf;
std::string type_name[] = {"CV_8UC1", "CV_16SC1", "CV_32FC1", "CV_64FC1"}; using std::tr1::tuple;
using std::tr1::get;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) ///////////// Moments ////////////////////////
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j];
gen(src, size, size, all_type[j], 0, 256); CV_ENUM(MomentsMatType, CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1)
cv::Moments CvMom = moments(src, binaryImage); typedef tuple<Size, MomentsMatType> MomentsParams;
typedef TestBaseWithParam<MomentsParams> MomentsFixture;
CPU_ON; PERF_TEST_P(MomentsFixture, DISABLED_Moments,
moments(src, binaryImage); ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
CPU_OFF; MomentsMatType::all()))
{
// getting params
MomentsParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params);
cv::Moments oclMom; std::string impl = getSelectedImpl();
WARMUP_ON;
oclMom = ocl::ocl_moments(src, binaryImage);
WARMUP_OFF;
Mat gpu_dst, cpu_dst; // creating src data
HuMoments(CvMom, cpu_dst); Mat src(srcSize, type), dst(7, 1, CV_64F);
HuMoments(oclMom, gpu_dst); const bool binaryImage = false;
cv::Moments mom;
GPU_ON; declare.in(src, WARMUP_RNG).out(dst);
ocl::ocl_moments(src, binaryImage);
GPU_OFF;
GPU_FULL_ON; // select implementation
ocl::ocl_moments(src, binaryImage); if (impl == "ocl")
GPU_FULL_OFF; {
ocl::oclMat oclSrc(src);
TestSystem::instance().ExpectedMatNear(gpu_dst, cpu_dst, .5); TEST_CYCLE() mom = cv::ocl::ocl_moments(oclSrc, binaryImage);
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() mom = cv::moments(src, binaryImage);
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,43 +45,46 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// norm//////////////////////// using namespace perf;
PERFTEST(norm) using std::tr1::tuple;
{ using std::tr1::get;
Mat src1, src2, ocl_src1;
ocl::oclMat d_src1, d_src2;
for (int size = Min_Size; size <= Max_Size; size *= Multiple) ///////////// norm////////////////////////
{
SUBTEST << size << 'x' << size << "; CV_8UC1; NORM_INF";
gen(src1, size, size, CV_8UC1, Scalar::all(0), Scalar::all(1));
gen(src2, size, size, CV_8UC1, Scalar::all(0), Scalar::all(1));
norm(src1, src2, NORM_INF); typedef TestBaseWithParam<Size> normFixture;
CPU_ON; PERF_TEST_P(normFixture, DISABLED_norm, OCL_TYPICAL_MAT_SIZES)
norm(src1, src2, NORM_INF); {
CPU_OFF; // getting params
const Size srcSize = GetParam();
const std::string impl = getSelectedImpl();
double value = 0.0;
d_src1.upload(src1); // creating src data
d_src2.upload(src2); Mat src1(srcSize, CV_8UC1), src2(srcSize, CV_8UC1);
declare.in(src1, src2);
randu(src1, 0, 1);
randu(src2, 0, 1);
WARMUP_ON; // select implementation
ocl::norm(d_src1, d_src2, NORM_INF); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclSrc1(src1), oclSrc2(src2);
d_src1.download(ocl_src1); TEST_CYCLE() value = cv::ocl::norm(oclSrc1, oclSrc2, NORM_INF);
TestSystem::instance().ExpectedMatNear(src1, ocl_src1, .5);
GPU_ON; SANITY_CHECK(value);
ocl::norm(d_src1, d_src2, NORM_INF); }
GPU_OFF; else if (impl == "plain")
{
TEST_CYCLE() value = cv::norm(src1, src2, NORM_INF);
GPU_FULL_ON; SANITY_CHECK(value);
d_src1.upload(src1);
d_src2.upload(src2);
ocl::norm(d_src1, d_src2, NORM_INF);
GPU_FULL_OFF;
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -46,117 +46,130 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
///////////// PyrLKOpticalFlow //////////////////////// ///////////// PyrLKOpticalFlow ////////////////////////
PERFTEST(PyrLKOpticalFlow)
{
std::string images1[] = {"rubberwhale1.png", "aloeL.jpg"};
std::string images2[] = {"rubberwhale2.png", "aloeR.jpg"};
for (size_t i = 0; i < sizeof(images1) / sizeof(std::string); i++)
{
Mat frame0 = imread(abspath(images1[i]), i == 0 ? IMREAD_COLOR : IMREAD_GRAYSCALE);
if (frame0.empty())
{
std::string errstr = "can't open " + images1[i];
throw runtime_error(errstr);
}
Mat frame1 = imread(abspath(images2[i]), i == 0 ? IMREAD_COLOR : IMREAD_GRAYSCALE); using namespace perf;
using std::tr1::get;
using std::tr1::tuple;
using std::tr1::make_tuple;
if (frame1.empty()) template <typename T>
static vector<T> & MatToVector(const ocl::oclMat & oclSrc, vector<T> & instance)
{ {
std::string errstr = "can't open " + images2[i]; Mat src;
throw runtime_error(errstr); oclSrc.download(src);
}
Mat gray_frame; for (int i = 0; i < src.cols; ++i)
instance.push_back(src.at<T>(0, i));
if (i == 0) return instance;
{
cvtColor(frame0, gray_frame, COLOR_BGR2GRAY);
} }
for (int points = Min_Size; points <= Max_Size; points *= Multiple) CV_ENUM(LoadMode, IMREAD_GRAYSCALE, IMREAD_COLOR)
typedef tuple<int, tuple<string, string, LoadMode> > PyrLKOpticalFlowParamType;
typedef TestBaseWithParam<PyrLKOpticalFlowParamType> PyrLKOpticalFlowFixture;
PERF_TEST_P(PyrLKOpticalFlowFixture,
PyrLKOpticalFlow,
::testing::Combine(
::testing::Values(1000, 2000, 4000),
::testing::Values(
make_tuple<string, string, LoadMode>
(
string("gpu/opticalflow/rubberwhale1.png"),
string("gpu/opticalflow/rubberwhale1.png"),
LoadMode(IMREAD_COLOR)
)
// , make_tuple<string, string, LoadMode>
// (
// string("gpu/stereobm/aloe-L.png"),
// string("gpu/stereobm/aloe-R.png"),
// LoadMode(IMREAD_GRAYSCALE)
// )
)
)
)
{ {
if (i == 0) PyrLKOpticalFlowParamType params = GetParam();
SUBTEST << frame0.cols << "x" << frame0.rows << "; color; " << points << " points"; tuple<string, string, LoadMode> fileParam = get<1>(params);
const int pointsCount = get<0>(params);
const int openMode = static_cast<int>(get<2>(fileParam));
const string fileName0 = get<0>(fileParam), fileName1 = get<1>(fileParam);
Mat frame0 = imread(getDataPath(fileName0), openMode);
Mat frame1 = imread(getDataPath(fileName1), openMode);
const string impl = getSelectedImpl();
ASSERT_FALSE(frame0.empty()) << "can't load " << fileName0;
ASSERT_FALSE(frame1.empty()) << "can't load " << fileName1;
Mat grayFrame;
if (openMode == IMREAD_COLOR)
cvtColor(frame0, grayFrame, COLOR_BGR2GRAY);
else else
SUBTEST << frame0.cols << "x" << frame0.rows << "; gray; " << points << " points"; grayFrame = frame0;
Mat ocl_nextPts;
Mat ocl_status;
vector<Point2f> pts; // initialization
goodFeaturesToTrack(i == 0 ? gray_frame : frame0, pts, points, 0.01, 0.0); vector<Point2f> pts, nextPts;
vector<Point2f> nextPts;
vector<unsigned char> status; vector<unsigned char> status;
vector<float> err; vector<float> err;
goodFeaturesToTrack(grayFrame, pts, pointsCount, 0.01, 0.0);
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err); // selecting implementation
if (impl == "plain")
CPU_ON; {
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err); TEST_CYCLE()
CPU_OFF; cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
ocl::PyrLKOpticalFlow d_pyrLK;
ocl::oclMat d_frame0(frame0);
ocl::oclMat d_frame1(frame1);
ocl::oclMat d_pts;
Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void *)&pts[0]);
d_pts.upload(pts_mat);
ocl::oclMat d_nextPts;
ocl::oclMat d_status;
ocl::oclMat d_err;
WARMUP_ON;
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
WARMUP_OFF;
GPU_ON;
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
GPU_OFF;
GPU_FULL_ON; SANITY_CHECK(nextPts);
d_frame0.upload(frame0); SANITY_CHECK(status);
d_frame1.upload(frame1); SANITY_CHECK(err);
d_pts.upload(pts_mat); }
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err); else if (impl == "ocl")
{
ocl::PyrLKOpticalFlow oclPyrLK;
ocl::oclMat oclFrame0(frame0), oclFrame1(frame1);
ocl::oclMat oclPts(1, static_cast<int>(pts.size()), CV_32FC2, (void *)&pts[0]);
ocl::oclMat oclNextPts, oclStatus, oclErr;
if (!d_nextPts.empty()) TEST_CYCLE()
d_nextPts.download(ocl_nextPts); oclPyrLK.sparse(oclFrame0, oclFrame1, oclPts, oclNextPts, oclStatus, &oclErr);
if (!d_status.empty()) MatToVector(oclNextPts, nextPts);
d_status.download(ocl_status); MatToVector(oclStatus, status);
GPU_FULL_OFF; MatToVector(oclErr, err);
size_t mismatch = 0; SANITY_CHECK(nextPts);
for (int i = 0; i < (int)nextPts.size(); ++i) SANITY_CHECK(status);
{ SANITY_CHECK(err);
if(status[i] != ocl_status.at<unsigned char>(0, i))
{
mismatch++;
continue;
}
if(status[i])
{
Point2f gpu_rst = ocl_nextPts.at<Point2f>(0, i);
Point2f cpu_rst = nextPts[i];
if(fabs(gpu_rst.x - cpu_rst.x) >= 1. || fabs(gpu_rst.y - cpu_rst.y) >= 1.)
mismatch++;
} }
} #ifdef HAVE_OPENCV_GPU
double ratio = (double)mismatch / (double)nextPts.size(); else if (impl == "gpu")
if(ratio < .02) CV_TEST_FAIL_NO_IMPL();
TestSystem::instance().setAccurate(1, ratio); #endif
else else
TestSystem::instance().setAccurate(0, ratio); CV_TEST_FAIL_NO_IMPL();
}
// size_t mismatch = 0;
} // for (int i = 0; i < (int)nextPts.size(); ++i)
// {
// if(status[i] != ocl_status.at<unsigned char>(0, i))
// {
// mismatch++;
// continue;
// }
// if(status[i])
// {
// Point2f gpu_rst = ocl_nextPts.at<Point2f>(0, i);
// Point2f cpu_rst = nextPts[i];
// if(fabs(gpu_rst.x - cpu_rst.x) >= 1. || fabs(gpu_rst.y - cpu_rst.y) >= 1.)
// mismatch++;
// }
// }
// double ratio = (double)mismatch / (double)nextPts.size();
// if(ratio < .02)
// TestSystem::instance().setAccurate(1, ratio);
// else
// TestSystem::instance().setAccurate(0, ratio);
} }

@ -40,6 +40,15 @@
// //
//M*/ //M*/
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# pragma GCC diagnostic ignored "-Wunused-function"
# if defined __clang__ || defined __APPLE__
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wextra"
# endif
#endif
#ifndef __OPENCV_PERF_PRECOMP_HPP__ #ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__ #define __OPENCV_PERF_PRECOMP_HPP__
@ -50,6 +59,7 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
#include <numeric> #include <numeric>
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
@ -59,9 +69,12 @@
#include "opencv2/features2d/features2d.hpp" #include "opencv2/features2d/features2d.hpp"
#include "opencv2/ocl/ocl.hpp" #include "opencv2/ocl/ocl.hpp"
#include "opencv2/ts/ts.hpp" #include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/ts/ts_gtest.h"
#define OCL_SIZE_1000 cv::Size(1000, 1000)
#define OCL_SIZE_2000 cv::Size(2000, 2000)
#define OCL_SIZE_4000 cv::Size(4000, 4000)
#define OCL_TYPICAL_MAT_SIZES ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000, OCL_SIZE_4000)
#define Min_Size 1000 #define Min_Size 1000
#define Max_Size 4000 #define Max_Size 4000
@ -76,15 +89,15 @@ void gen(Mat &mat, int rows, int cols, int type, int low, int high, int n);
string abspath(const string &relpath); string abspath(const string &relpath);
int CV_CDECL cvErrorCallback(int, const char *, const char *, const char *, int, void *); int CV_CDECL cvErrorCallback(int, const char *, const char *, const char *, int, void *);
typedef struct //typedef struct
{ //{
short x; // short x;
short y; // short y;
} COOR; //} COOR;
COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, //COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep,
cv::Size size, int sp, int sr, int maxIter, float eps, int *tab); // cv::Size size, int sp, int sr, int maxIter, float eps, int *tab);
void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, //void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi,
int sp, int sr, cv::TermCriteria crit); // int sp, int sr, cv::TermCriteria crit);
template<class T1, class T2> template<class T1, class T2>

@ -45,88 +45,103 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
using std::tr1::tuple;
using std::tr1::get;
///////////// pyrDown ////////////////////// ///////////// pyrDown //////////////////////
PERFTEST(pyrDown)
{
Mat src, dst, ocl_dst;
int all_type[] = {CV_8UC1, CV_8UC4};
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) CV_ENUM(pyrDownMatType, CV_8UC1, CV_8UC4)
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src, size, size, all_type[j], 0, 256); typedef tuple<Size, pyrDownMatType> pyrDownParams;
typedef TestBaseWithParam<pyrDownParams> pyrDownFixture;
pyrDown(src, dst); PERF_TEST_P(pyrDownFixture, pyrDown,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
pyrDownMatType::all()))
{
// getting params
pyrDownParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params);
CPU_ON; std::string impl = getSelectedImpl();
pyrDown(src, dst);
CPU_OFF;
ocl::oclMat d_src(src); // creating src data
ocl::oclMat d_dst; Mat src(srcSize, type), dst;
Size dstSize((srcSize.height + 1) >> 1, (srcSize.width + 1) >> 1);
dst.create(dstSize, type);
declare.in(src).out(dst);
WARMUP_ON; // select implementation
ocl::pyrDown(d_src, d_dst); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclSrc(src), oclDst(dstSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::pyrDown(oclSrc, oclDst);
ocl::pyrDown(d_src, d_dst);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::pyrDown(d_src, d_dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, dst.depth() == CV_32F ? 1e-4f : 1.0f); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::pyrDown(src, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// pyrUp //////////////////////// ///////////// pyrUp ////////////////////////
PERFTEST(pyrUp)
{
Mat src, dst, ocl_dst;
int all_type[] = {CV_8UC1, CV_8UC4};
std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
for (int size = 500; size <= 2000; size *= 2)
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src, size, size, all_type[j], 0, 256); typedef pyrDownMatType pyrUpMatType;
typedef tuple<Size, pyrUpMatType> pyrUpParams;
typedef TestBaseWithParam<pyrUpParams> pyrUpFixture;
pyrUp(src, dst); PERF_TEST_P(pyrUpFixture, pyrUp,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
pyrUpMatType::all()))
{
// getting params
pyrUpParams params = GetParam();
const Size srcSize = get<0>(params);
const int type = get<1>(params);
CPU_ON; std::string impl = getSelectedImpl();
pyrUp(src, dst);
CPU_OFF;
ocl::oclMat d_src(src); // creating src data
ocl::oclMat d_dst; Mat src(srcSize, type), dst;
Size dstSize(srcSize.height << 1, srcSize.width << 1);
dst.create(dstSize, type);
declare.in(src).out(dst);
WARMUP_ON; // select implementation
ocl::pyrUp(d_src, d_dst); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclSrc(src), oclDst(dstSize, type);
GPU_ON; TEST_CYCLE() cv::ocl::pyrDown(oclSrc, oclDst);
ocl::pyrUp(d_src, d_dst);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
d_src.upload(src);
ocl::pyrUp(d_src, d_dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, (src.depth() == CV_32F ? 1e-4f : 1.0)); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::pyrDown(src, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

@ -45,110 +45,120 @@
//M*/ //M*/
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
using namespace perf;
using std::tr1::tuple;
using std::tr1::get;
///////////// Merge//////////////////////// ///////////// Merge////////////////////////
PERFTEST(Merge)
{
Mat dst, ocl_dst;
ocl::oclMat d_dst;
int channels = 4; CV_ENUM(MergeMatType, CV_8U, CV_32F)
int all_type[] = {CV_8UC1, CV_32FC1};
std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple) typedef tuple<Size, MergeMatType> MergeParams;
{ typedef TestBaseWithParam<MergeParams> MergeFixture;
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
Size size1 = Size(size, size);
std::vector<Mat> src(channels);
for (int i = 0; i < channels; ++i) PERF_TEST_P(MergeFixture, Merge,
::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
MergeMatType::all()))
{ {
src[i] = Mat(size1, all_type[j], cv::Scalar::all(i)); // getting params
} MergeParams params = GetParam();
const Size srcSize = get<0>(params);
merge(src, dst); const int depth = get<1>(params), channels = 3;
CPU_ON; std::string impl = getSelectedImpl();
merge(src, dst);
CPU_OFF; // creating src data
const int dstType = CV_MAKE_TYPE(depth, channels);
std::vector<ocl::oclMat> d_src(channels); Mat dst(srcSize, dstType);
vector<Mat> src(channels);
for (int i = 0; i < channels; ++i) for (vector<Mat>::iterator i = src.begin(), end = src.end(); i != end; ++i)
{ {
d_src[i] = ocl::oclMat(size1, all_type[j], cv::Scalar::all(i)); i->create(srcSize, CV_MAKE_TYPE(depth, 1));
declare.in(*i, WARMUP_RNG);
} }
declare.out(dst);
WARMUP_ON; // select implementation
ocl::merge(d_src, d_dst); if (impl == "ocl")
WARMUP_OFF; {
ocl::oclMat oclDst(srcSize, dstType);
vector<ocl::oclMat> oclSrc(src.size());
for (vector<ocl::oclMat>::size_type i = 0, end = src.size(); i < end; ++i)
oclSrc[i] = src[i];
GPU_ON; TEST_CYCLE() cv::ocl::merge(oclSrc, oclDst);
ocl::merge(d_src, d_dst);
GPU_OFF;
GPU_FULL_ON; oclDst.download(dst);
for (int i = 0; i < channels; ++i)
{
d_src[i] = ocl::oclMat(size1, all_type[j], cv::Scalar::all(i));
}
ocl::merge(d_src, d_dst);
d_dst.download(ocl_dst);
GPU_FULL_OFF;
TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0); SANITY_CHECK(dst);
} }
else if (impl == "plain")
{
TEST_CYCLE() cv::merge(src, dst);
SANITY_CHECK(dst);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }
///////////// Split//////////////////////// ///////////// Split////////////////////////
PERFTEST(Split)
{
//int channels = 4;
int all_type[] = {CV_8UC1, CV_32FC1};
std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple)
{
for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
{
SUBTEST << size << 'x' << size << "; " << type_name[j];
Size size1 = Size(size, size);
Mat src(size1, CV_MAKE_TYPE(all_type[j], 4), cv::Scalar(1, 2, 3, 4));
std::vector<cv::Mat> dst, ocl_dst(4);
split(src, dst); typedef MergeMatType SplitMatType;
typedef tuple<Size, SplitMatType> SplitParams;
typedef TestBaseWithParam<SplitParams> SplitFixture;
CPU_ON; PERF_TEST_P(SplitFixture, Split,
split(src, dst); ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
CPU_OFF; SplitMatType::all()))
{
ocl::oclMat d_src(size1, CV_MAKE_TYPE(all_type[j], 4), cv::Scalar(1, 2, 3, 4)); // getting params
std::vector<cv::ocl::oclMat> d_dst; MergeParams params = GetParam();
const Size srcSize = get<0>(params);
WARMUP_ON; const int depth = get<1>(params), channels = 3;
ocl::split(d_src, d_dst);
WARMUP_OFF;
GPU_ON; std::string impl = getSelectedImpl();
ocl::split(d_src, d_dst);
GPU_OFF;
GPU_FULL_ON; // creating src data
d_src.upload(src); Mat src(srcSize, CV_MAKE_TYPE(depth, channels));
ocl::split(d_src, d_dst); declare.in(src, WARMUP_RNG);
for(size_t i = 0; i < dst.size(); i++)
d_dst[i].download(ocl_dst[i]);
GPU_FULL_OFF;
vector<double> eps(4, 0.); // select implementation
TestSystem::instance().ExpectMatsNear(dst, ocl_dst, eps); if (impl == "ocl")
{
ocl::oclMat oclSrc(src);
vector<ocl::oclMat> oclDst(channels, ocl::oclMat(srcSize, CV_MAKE_TYPE(depth, 1)));
TEST_CYCLE() cv::ocl::split(oclSrc, oclDst);
AssertEQ(channels, 3);
Mat dst0, dst1, dst2;
oclDst[0].download(dst0);
oclDst[1].download(dst1);
oclDst[2].download(dst2);
SANITY_CHECK(dst0);
SANITY_CHECK(dst1);
SANITY_CHECK(dst2);
} }
else if (impl == "plain")
{
vector<Mat> dst(channels, Mat(srcSize, CV_MAKE_TYPE(depth, 1)));
TEST_CYCLE() cv::split(src, dst);
AssertEQ(channels, 3);
Mat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2];
SANITY_CHECK(dst0);
SANITY_CHECK(dst1);
SANITY_CHECK(dst2);
} }
#ifdef HAVE_OPENCV_GPU
else if (impl == "gpu")
CV_TEST_FAIL_NO_IMPL();
#endif
else
CV_TEST_FAIL_NO_IMPL();
} }

Loading…
Cancel
Save