Commit 6891a601 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

added host code for gpu::matchTemplate (as NPP_staging was integrated)

parent e62bf3a2
This diff is collapsed.
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#ifdef SHOW_TIME #ifdef SHOW_TIME
#include <ctime> #include <ctime>
#define F(x) #define F(x) x
#else #else
#define F(x) #define F(x)
#endif #endif
...@@ -70,54 +70,106 @@ struct CV_GpuMatchTemplateTest: CvTest ...@@ -70,54 +70,106 @@ struct CV_GpuMatchTemplateTest: CvTest
int n, m, h, w; int n, m, h, w;
F(clock_t t;) F(clock_t t;)
for (int i = 0; i < 3; ++i) for (int cn = 1; cn <= 4; ++cn)
{ {
n = 1 + rand() % 2000; F(ts->printf(CvTS::CONSOLE, "cn: %d\n", cn);)
m = 1 + rand() % 1000; for (int i = 0; i <= 0; ++i)
do h = 1 + rand() % 30; while (h > n); {
do w = 1 + rand() % 30; while (w > m); n = 1 + rand() % 1000;
m = 1 + rand() % 1000;
//cout << "w: " << w << " h: " << h << endl; do h = 1 + rand() % 100; while (h > n);
do w = 1 + rand() % 100; while (w > m);
gen(image, n, m, CV_8U);
gen(templ, h, w, CV_8U); //cout << "w: " << w << " h: " << h << endl;
F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF); gen(image, n, m, CV_8U, cn);
F(cout << "cpu:" << clock() - t << endl;) gen(templ, h, w, CV_8U, cn);
F(t = clock();) F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF); matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF);
F(cout << "gpu_block: " << clock() - t << endl;) F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-5f)) return; F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gen(image, n, m, CV_8U); gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);
gen(templ, h, w, CV_8U); F(cout << "gpu_block: " << clock() - t << endl;)
F(t = clock();) if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-4f)) return;
matchTemplate(image, templ, dst_gold, CV_TM_CCORR);
F(cout << "cpu:" << clock() - t << endl;) gen(image, n, m, CV_8U, cn);
F(t = clock();) gen(templ, h, w, CV_8U, cn);
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR); F(t = clock();)
F(cout << "gpu_block: " << clock() - t << endl;) matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF_NORMED);
if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-5f)) return; F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
gen(image, n, m, CV_32F); F(t = clock();)
gen(templ, h, w, CV_32F); gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF_NORMED);
F(t = clock();) F(cout << "gpu_block: " << clock() - t << endl;)
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF); if (!check(dst_gold, Mat(dst), h * w * 1e-5f)) return;
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();) gen(image, n, m, CV_8U, cn);
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF); gen(templ, h, w, CV_8U, cn);
F(cout << "gpu_block: " << clock() - t << endl;) F(t = clock();)
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f)) return; matchTemplate(image, templ, dst_gold, CV_TM_CCORR);
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
gen(image, n, m, CV_32F); F(cout << "cpu:" << clock() - t << endl;)
gen(templ, h, w, CV_32F); F(t = clock();)
F(t = clock();) gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR);
matchTemplate(image, templ, dst_gold, CV_TM_CCORR); F(cout << "gpu_block: " << clock() - t << endl;)
F(cout << "cpu:" << clock() - t << endl;) if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f)) return;
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR); gen(image, n, m, CV_8U, cn);
F(cout << "gpu_block: " << clock() - t << endl;) gen(templ, h, w, CV_8U, cn);
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f)) return; F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_CCORR_NORMED);
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR_NORMED);
F(cout << "gpu_block: " << clock() - t << endl;)
if (!check(dst_gold, Mat(dst), h * w * 1e-5f)) return;
gen(image, n, m, CV_8U, cn);
gen(templ, h, w, CV_8U, cn);
F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_CCOEFF);
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF);
F(cout << "gpu_block: " << clock() - t << endl;)
if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f)) return;
gen(image, n, m, CV_8U, cn);
gen(templ, h, w, CV_8U, cn);
F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_CCOEFF_NORMED);
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF_NORMED);
F(cout << "gpu_block: " << clock() - t << endl;)
if (!check(dst_gold, Mat(dst), h * w * 1e-6f)) return;
gen(image, n, m, CV_32F, cn);
gen(templ, h, w, CV_32F, cn);
F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF);
F(cout << "depth: 32F cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);
F(cout << "gpu_block: " << clock() - t << endl;)
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f)) return;
gen(image, n, m, CV_32F, cn);
gen(templ, h, w, CV_32F, cn);
F(t = clock();)
matchTemplate(image, templ, dst_gold, CV_TM_CCORR);
F(cout << "depth: 32F cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
F(cout << "cpu:" << clock() - t << endl;)
F(t = clock();)
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR);
F(cout << "gpu_block: " << clock() - t << endl;)
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f)) return;
}
} }
} }
catch (const Exception& e) catch (const Exception& e)
...@@ -128,14 +180,14 @@ struct CV_GpuMatchTemplateTest: CvTest ...@@ -128,14 +180,14 @@ struct CV_GpuMatchTemplateTest: CvTest
} }
} }
void gen(Mat& a, int rows, int cols, int type) void gen(Mat& a, int rows, int cols, int depth, int cn)
{ {
RNG rng; RNG rng;
a.create(rows, cols, type); a.create(rows, cols, CV_MAKETYPE(depth, cn));
if (type == CV_8U) if (depth == CV_8U)
rng.fill(a, RNG::UNIFORM, Scalar(0), Scalar(10)); rng.fill(a, RNG::UNIFORM, Scalar::all(1), Scalar::all(10));
else if (type == CV_32F) else if (depth == CV_32F)
rng.fill(a, RNG::UNIFORM, Scalar(0.f), Scalar(1.f)); rng.fill(a, RNG::UNIFORM, Scalar::all(0.001f), Scalar::all(1.f));
} }
bool check(const Mat& a, const Mat& b, float max_err) bool check(const Mat& a, const Mat& b, float max_err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment