added support of CV_8U & CV_TM_CCORR into gpu::matchTemplate
authorAlexey Spizhevoy <no@email>
Fri, 10 Dec 2010 08:06:54 +0000 (08:06 +0000)
committerAlexey Spizhevoy <no@email>
Fri, 10 Dec 2010 08:06:54 +0000 (08:06 +0000)
modules/gpu/src/match_template.cpp
tests/gpu/src/match_template.cpp

index b5090f6..b06d6bc 100644 (file)
@@ -85,15 +85,6 @@ namespace
         bh = std::min(bh, h);\r
     }\r
 #endif\r
-\r
-\r
-    template <>\r
-    void matchTemplate<CV_8U, CV_TM_SQDIFF>(const GpuMat& image, const GpuMat& templ, GpuMat& result)\r
-    {\r
-        result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F);\r
-        imgproc::matchTemplateNaive_8U_SQDIFF(image, templ, result);\r
-    }\r
-\r
     \r
     template <>\r
     void matchTemplate<CV_32F, CV_TM_SQDIFF>(const GpuMat& image, const GpuMat& templ, GpuMat& result)\r
@@ -242,6 +233,24 @@ namespace
     }\r
 #endif\r
 \r
+\r
+    template <>\r
+    void matchTemplate<CV_8U, CV_TM_SQDIFF>(const GpuMat& image, const GpuMat& templ, GpuMat& result)\r
+    {\r
+        result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F);\r
+        imgproc::matchTemplateNaive_8U_SQDIFF(image, templ, result);\r
+    }\r
+\r
+       \r
+    template <>\r
+    void matchTemplate<CV_8U, CV_TM_CCORR>(const GpuMat& image, const GpuMat& templ, GpuMat& result)\r
+       {\r
+               GpuMat imagef, templf;\r
+               image.convertTo(imagef, CV_32F);\r
+               templ.convertTo(templf, CV_32F);\r
+               matchTemplate<CV_32F, CV_TM_SQDIFF>(imagef, templf, result);\r
+       }\r
+\r
 }\r
 \r
 \r
@@ -252,7 +261,8 @@ void cv::gpu::matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& re
 \r
     typedef void (*Caller)(const GpuMat&, const GpuMat&, GpuMat&);\r
 \r
-    static const Caller callers8U[] = { ::matchTemplate<CV_8U, CV_TM_SQDIFF>, 0, 0, 0, 0, 0 };\r
+       static const Caller callers8U[] = { ::matchTemplate<CV_8U, CV_TM_SQDIFF>, 0, \r
+                                                                               ::matchTemplate<CV_8U, CV_TM_CCORR>, 0, 0, 0 };\r
     static const Caller callers32F[] = { ::matchTemplate<CV_32F, CV_TM_SQDIFF>, 0, \r
                                          ::matchTemplate<CV_32F, CV_TM_CCORR>, 0, 0, 0 };\r
 \r
index 1805678..8aa8315 100644 (file)
@@ -87,6 +87,16 @@ struct CV_GpuMatchTemplateTest: CvTest
                 F(cout << "gpu_block: " << clock() - t << endl;)\r
                 if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-5f)) return;\r
 \r
+                gen(image, n, m, CV_8U);\r
+                gen(templ, h, w, CV_8U);\r
+                F(t = clock();)\r
+                matchTemplate(image, templ, dst_gold, CV_TM_CCORR);\r
+                F(cout << "cpu:" << clock() - t << endl;)\r
+                F(t = clock();)\r
+                gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR);\r
+                F(cout << "gpu_block: " << clock() - t << endl;)\r
+                if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-5f)) return;\r
+\r
                 gen(image, n, m, CV_32F);\r
                 gen(templ, h, w, CV_32F);\r
                 F(t = clock();)\r