cosmetic changes in gpu module, decreased matchTemplate test running time
authorAlexey Spizhevoy <no@email>
Wed, 12 Jan 2011 09:30:08 +0000 (09:30 +0000)
committerAlexey Spizhevoy <no@email>
Wed, 12 Jan 2011 09:30:08 +0000 (09:30 +0000)
modules/gpu/include/opencv2/gpu/gpu.hpp
modules/gpu/src/cuda/match_template.cu
modules/gpu/src/hog.cpp
samples/gpu/hog.cpp
tests/gpu/src/match_template.cpp

index 957299b..70a34ee 100644 (file)
@@ -1182,8 +1182,8 @@ namespace cv
             void setSVMDetector(const vector<float>& detector);\r
 \r
             static vector<float> getDefaultPeopleDetector();\r
-            static vector<float> getPeopleDetector_48x96();\r
-            static vector<float> getPeopleDetector_64x128();\r
+            static vector<float> getPeopleDetector48x96();\r
+            static vector<float> getPeopleDetector64x128();\r
 \r
             void detect(const GpuMat& img, vector<Point>& found_locations, \r
                         double hit_threshold=0, Size win_stride=Size(), \r
index 7f47db8..0cdf4d1 100644 (file)
@@ -560,7 +560,7 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8U(
                 (image_sqsum.ptr(y + h)[x + w] - image_sqsum.ptr(y)[x + w]) -\r
                 (image_sqsum.ptr(y + h)[x] - image_sqsum.ptr(y)[x]));\r
         result.ptr(y)[x] = (ccorr - image_sum_ * templ_sum_scale) * \r
-                           rsqrtf(templ_sqsum_scale * max(1.f, image_sqsum_ - weight * image_sum_ * image_sum_));\r
+                           rsqrtf(templ_sqsum_scale * max(1e-3f, image_sqsum_ - weight * image_sum_ * image_sum_));\r
     }\r
 }\r
 \r
@@ -610,8 +610,8 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC2(
                 (image_sqsum_g.ptr(y + h)[x + w] - image_sqsum_g.ptr(y)[x + w]) -\r
                 (image_sqsum_g.ptr(y + h)[x] - image_sqsum_g.ptr(y)[x]));\r
         float ccorr = result.ptr(y)[x];\r
-        float rdenom = rsqrtf(templ_sqsum_scale * max(1.f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_ \r
-                                                           + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_));\r
+        float rdenom = rsqrtf(templ_sqsum_scale * max(1e-3f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_ \r
+                                                             + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_));\r
         result.ptr(y)[x] = (ccorr - image_sum_r_ * templ_sum_scale_r\r
                                   - image_sum_g_ * templ_sum_scale_g) * rdenom;\r
     }\r
@@ -678,9 +678,9 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC3(
                 (image_sqsum_b.ptr(y + h)[x + w] - image_sqsum_b.ptr(y)[x + w]) -\r
                 (image_sqsum_b.ptr(y + h)[x] - image_sqsum_b.ptr(y)[x]));\r
         float ccorr = result.ptr(y)[x];\r
-        float rdenom = rsqrtf(templ_sqsum_scale * max(1.f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_ \r
-                                                           + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_\r
-                                                           + image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_));\r
+        float rdenom = rsqrtf(templ_sqsum_scale * max(1e-3f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_ \r
+                                                             + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_\r
+                                                             + image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_));\r
         result.ptr(y)[x] = (ccorr - image_sum_r_ * templ_sum_scale_r\r
                                   - image_sum_g_ * templ_sum_scale_g\r
                                   - image_sum_b_ * templ_sum_scale_b) * rdenom;\r
@@ -760,10 +760,10 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC4(
                 (image_sqsum_a.ptr(y + h)[x + w] - image_sqsum_a.ptr(y)[x + w]) -\r
                 (image_sqsum_a.ptr(y + h)[x] - image_sqsum_a.ptr(y)[x]));\r
         float ccorr = result.ptr(y)[x];\r
-        float rdenom = rsqrtf(templ_sqsum_scale * max(1.f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_\r
-                                                           + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_\r
-                                                           + image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_\r
-                                                           + image_sqsum_a_ - weight * image_sum_a_ * image_sum_a_));\r
+        float rdenom = rsqrtf(templ_sqsum_scale * max(1e-3f, image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_\r
+                                                             + image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_\r
+                                                             + image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_\r
+                                                             + image_sqsum_a_ - weight * image_sum_a_ * image_sum_a_));\r
         result.ptr(y)[x] = (ccorr - image_sum_r_ * templ_sum_scale_r\r
                                   - image_sum_g_ * templ_sum_scale_g\r
                                   - image_sum_b_ * templ_sum_scale_b\r
index 9a77ad1..56f05d7 100644 (file)
@@ -55,8 +55,8 @@ void cv::gpu::HOGDescriptor::detectMultiScale(const GpuMat&, vector<Rect>&, doub
 void cv::gpu::HOGDescriptor::computeBlockHistograms(const GpuMat&) { throw_nogpu(); }\r
 void cv::gpu::HOGDescriptor::getDescriptors(const GpuMat&, Size, GpuMat&, int) { throw_nogpu(); }\r
 std::vector<float> cv::gpu::HOGDescriptor::getDefaultPeopleDetector() { throw_nogpu(); return std::vector<float>(); }\r
-std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector_48x96() { throw_nogpu(); return std::vector<float>(); }\r
-std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector_64x128() { throw_nogpu(); return std::vector<float>(); }\r
+std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector48x96() { throw_nogpu(); return std::vector<float>(); }\r
+std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector64x128() { throw_nogpu(); return std::vector<float>(); }\r
 \r
 #else\r
 \r
@@ -352,11 +352,11 @@ cv::Size cv::gpu::HOGDescriptor::numPartsWithin(cv::Size size, cv::Size part_siz
 \r
 std::vector<float> cv::gpu::HOGDescriptor::getDefaultPeopleDetector()\r
 {\r
-    return getPeopleDetector_64x128();\r
+    return getPeopleDetector64x128();\r
 }\r
 \r
 \r
-std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector_48x96()\r
+std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector48x96()\r
 {\r
     static const float detector[] = {\r
         0.294350f, -0.098796f, -0.129522f, 0.078753f, 0.387527f, 0.261529f, \r
@@ -696,7 +696,7 @@ std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector_48x96()
 \r
 \r
 \r
-std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector_64x128()\r
+std::vector<float> cv::gpu::HOGDescriptor::getPeopleDetector64x128()\r
 {\r
     static const float detector[] = {\r
        0.05359386f, -0.14721455f, -0.05532170f, 0.05077307f,\r
index d0ff6b3..81d61b0 100644 (file)
@@ -239,9 +239,9 @@ void App::run()
     // Create HOG descriptors and detectors here\r
     vector<float> detector;\r
     if (win_size == Size(64, 128)) \r
-        detector = cv::gpu::HOGDescriptor::getPeopleDetector_64x128();\r
+        detector = cv::gpu::HOGDescriptor::getPeopleDetector64x128();\r
     else\r
-        detector = cv::gpu::HOGDescriptor::getPeopleDetector_48x96();\r
+        detector = cv::gpu::HOGDescriptor::getPeopleDetector48x96();\r
 \r
     cv::gpu::HOGDescriptor gpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9, \r
                                    cv::gpu::HOGDescriptor::DEFAULT_WIN_SIGMA, 0.2, gamma_corr, \r
index 9979a54..2adafdc 100644 (file)
@@ -70,17 +70,17 @@ struct CV_GpuMatchTemplateTest: CvTest
             int n, m, h, w;\r
             F(clock_t t;)\r
 \r
+            RNG rng(*ts->get_rng());\r
+\r
             for (int cn = 1; cn <= 4; ++cn)\r
             {\r
                 F(ts->printf(CvTS::CONSOLE, "cn: %d\n", cn);)\r
                 for (int i = 0; i <= 0; ++i)\r
                 {\r
-                    n = 1 + rand() % 1000;\r
-                    m = 1 + rand() % 1000;\r
-                    do h = 1 + rand() % 100; while (h > n);\r
-                    do w = 1 + rand() % 100; while (w > m);\r
-\r
-                    //cout << "w: " << w << " h: " << h << endl;\r
+                    n = rng.uniform(30, 100);\r
+                    m = rng.uniform(30, 100);\r
+                    h = rng.uniform(5, n - 1);\r
+                    w = rng.uniform(5, m - 1);\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -91,7 +91,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-4f)) return;\r
+                    if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-4f, "SQDIFF 8U")) return;\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -102,7 +102,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF_NORMED);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), h * w * 1e-5f)) return;\r
+                    if (!check(dst_gold, Mat(dst), h * w * 1e-5f, "SQDIFF_NOREMD 8U")) return;\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -113,7 +113,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     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 * cn * cn * 1e-5f)) return;\r
+                    if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f, "CCORR 8U")) return;\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -124,7 +124,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR_NORMED);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), h * w * 1e-6f)) return;\r
+                    if (!check(dst_gold, Mat(dst), h * w * 1e-6f, "CCORR_NORMED 8U")) return;\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -135,7 +135,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f)) return;\r
+                    if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f, "CCOEFF 8U")) return;\r
 \r
                     gen(image, n, m, CV_8U, cn);\r
                     gen(templ, h, w, CV_8U, cn);\r
@@ -146,7 +146,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF_NORMED);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), h * w * 1e-6f)) return;\r
+                    if (!check(dst_gold, Mat(dst), h * w * 1e-6f, "CCOEFF_NORMED 8U")) return;\r
 \r
                     gen(image, n, m, CV_32F, cn);\r
                     gen(templ, h, w, CV_32F, cn);\r
@@ -157,7 +157,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     F(t = clock();)\r
                     gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);\r
                     F(cout << "gpu_block: " << clock() - t << endl;)\r
-                    if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f)) return;\r
+                    if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f, "SQDIFF 32F")) return;\r
 \r
                     gen(image, n, m, CV_32F, cn);\r
                     gen(templ, h, w, CV_32F, cn);\r
@@ -168,7 +168,7 @@ struct CV_GpuMatchTemplateTest: CvTest
                     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), 0.25f * h * w * 1e-5f)) return;\r
+                    if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f, "CCORR 32F")) return;\r
                 }\r
             }\r
         }\r
@@ -190,19 +190,33 @@ struct CV_GpuMatchTemplateTest: CvTest
             rng.fill(a, RNG::UNIFORM, Scalar::all(0.001f), Scalar::all(1.f));\r
     }\r
 \r
-    bool check(const Mat& a, const Mat& b, float max_err)\r
+    bool check(const Mat& a, const Mat& b, float max_err, const string& method="")\r
     {\r
         if (a.size() != b.size())\r
         {\r
-            ts->printf(CvTS::CONSOLE, "bad size");\r
+            ts->printf(CvTS::CONSOLE, "bad size, method=%s\n", method.c_str());\r
             ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
             return false;\r
         }\r
 \r
+        //for (int i = 0; i < a.rows; ++i)\r
+        //{\r
+        //    for (int j = 0; j < a.cols; ++j)\r
+        //    {\r
+        //        float a_ = a.at<float>(i, j);\r
+        //        float b_ = b.at<float>(i, j);\r
+        //        if (fabs(a_ - b_) > max_err)\r
+        //        {\r
+        //            ts->printf(CvTS::CONSOLE, "a=%f, b=%f, i=%d, j=%d\n", a_, b_, i, j);\r
+        //            cin.get();\r
+        //        }\r
+        //    }\r
+        //}\r
+\r
         float err = (float)norm(a, b, NORM_INF);\r
         if (err > max_err)\r
         {\r
-            ts->printf(CvTS::CONSOLE, "bad accuracy: %f\n", err);\r
+            ts->printf(CvTS::CONSOLE, "bad accuracy: %f, method=%s\n", err, method.c_str());\r
             ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
             return false;\r
         }\r