moving CannyVX test from ocl to cpp file
authorapavlenko <andrey.e.pavlenko@gmail.com>
Fri, 9 Dec 2016 12:07:53 +0000 (15:07 +0300)
committerapavlenko <andrey.e.pavlenko@gmail.com>
Fri, 9 Dec 2016 12:07:53 +0000 (15:07 +0300)
modules/imgproc/test/ocl/test_canny.cpp
modules/imgproc/test/test_canny.cpp

index 6798e26..c5e0485 100644 (file)
@@ -133,90 +133,6 @@ OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine(
                                 testing::Values(L2gradient(false), L2gradient(true)),
                                 testing::Values(UseRoi(false), UseRoi(true))));
 
-
-IMPLEMENT_PARAM_CLASS(ImagePath, string)
-//IMPLEMENT_PARAM_CLASS(ApertureSize, int)
-//IMPLEMENT_PARAM_CLASS(L2gradient, bool)
-
-PARAM_TEST_CASE(CannyVX, ImagePath, ApertureSize, L2gradient)
-{
-    string imgPath;
-    int kSize;
-    bool useL2;
-
-    TEST_DECLARE_INPUT_PARAMETER(src);
-    TEST_DECLARE_OUTPUT_PARAMETER(dst);
-
-    virtual void SetUp()
-    {
-        imgPath = GET_PARAM(0);
-        kSize = GET_PARAM(1);
-        useL2 = GET_PARAM(2);
-    }
-
-    void loadImage()
-    {
-        src = readImage(imgPath, IMREAD_GRAYSCALE);
-        ASSERT_FALSE(src.empty()) << "cann't load image: " << imgPath;
-    }
-};
-
-TEST_P(CannyVX, Accuracy)
-{
-    if(haveOpenVX())
-    {
-        loadImage();
-
-        setUseOpenVX(false);
-        Mat canny;
-        cv::Canny(src, canny, 100, 150, 3);
-
-        setUseOpenVX(true);
-        Mat cannyVX;
-        cv::Canny(src, cannyVX, 100, 150, 3);
-
-        setUseOpenVX(false);
-        Mat diff, diff1;
-        absdiff(canny, cannyVX, diff);
-        boxFilter(diff, diff1, -1, Size(3,3));
-        diff1 = diff1 > 255/9*3;
-        erode(diff1, diff1, Mat());
-        double error = cv::norm(diff1, NORM_L1) / 255;
-        const int maxError = 10;
-        if(error > maxError)
-        {
-            string outPath =
-                    string("CannyVX-diff-") +
-                    imgPath + '-' +
-                    'k' + char(kSize+'0') + '-' +
-                    (useL2 ? "l2" : "l1");
-            std::replace(outPath.begin(), outPath.end(), '/', '_');
-            std::replace(outPath.begin(), outPath.end(), '\\', '_');
-            std::replace(outPath.begin(), outPath.end(), '.', '_');
-            imwrite(outPath+".png", diff);
-        }
-        ASSERT_LE(error, maxError);
-
-    }
-}
-
-    INSTANTIATE_TEST_CASE_P(
-                ImgProc, CannyVX,
-                testing::Combine(
-                    testing::Values(
-                        string("shared/baboon.png"),
-                        string("shared/fruits.png"),
-                        string("shared/lena.png"),
-                        string("shared/pic1.png"),
-                        string("shared/pic3.png"),
-                        string("shared/pic5.png"),
-                        string("shared/pic6.png")
-                    ),
-                    testing::Values(ApertureSize(3), ApertureSize(5)),
-                    testing::Values(L2gradient(false), L2gradient(true))
-                )
-    );
-
 } // namespace ocl
 
 } // namespace cvtest
index 4031839..ea7f563 100644 (file)
@@ -306,4 +306,107 @@ int CV_CannyTest::validate_test_results( int test_case_idx )
 TEST(DISABLED_Imgproc_Canny, accuracy) { CV_CannyTest test; test.safe_run(); }
 TEST(DISABLED_Imgproc_Canny, accuracy_deriv) { CV_CannyTest test(true); test.safe_run(); }
 
+
+/*
+ * Comparing OpenVX based implementation with the main one
+*/
+
+#ifndef IMPLEMENT_PARAM_CLASS
+#define IMPLEMENT_PARAM_CLASS(name, type) \
+    class name \
+    { \
+    public: \
+        name ( type arg = type ()) : val_(arg) {} \
+        operator type () const {return val_;} \
+    private: \
+        type val_; \
+    }; \
+    inline void PrintTo( name param, std::ostream* os) \
+    { \
+        *os << #name <<  "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
+    }
+#endif // IMPLEMENT_PARAM_CLASS
+
+IMPLEMENT_PARAM_CLASS(ImagePath, string)
+IMPLEMENT_PARAM_CLASS(ApertureSize, int)
+IMPLEMENT_PARAM_CLASS(L2gradient, bool)
+
+PARAM_TEST_CASE(CannyVX, ImagePath, ApertureSize, L2gradient)
+{
+    string imgPath;
+    int kSize;
+    bool useL2;
+    Mat src, dst;
+
+    virtual void SetUp()
+    {
+        imgPath = GET_PARAM(0);
+        kSize = GET_PARAM(1);
+        useL2 = GET_PARAM(2);
+    }
+
+    void loadImage()
+    {
+        src = cv::imread(cvtest::TS::ptr()->get_data_path() + imgPath, IMREAD_GRAYSCALE);
+        ASSERT_FALSE(src.empty()) << "cann't load image: " << imgPath;
+    }
+};
+
+TEST_P(CannyVX, Accuracy)
+{
+    if(haveOpenVX())
+    {
+        loadImage();
+
+        setUseOpenVX(false);
+        Mat canny;
+        cv::Canny(src, canny, 100, 150, 3);
+
+        setUseOpenVX(true);
+        Mat cannyVX;
+        cv::Canny(src, cannyVX, 100, 150, 3);
+
+        setUseOpenVX(false);
+        Mat diff, diff1;
+        absdiff(canny, cannyVX, diff);
+        boxFilter(diff, diff1, -1, Size(3,3));
+        const int minPixelsAroud = 3; // empirical number
+        diff1 = diff1 > 255/9 * minPixelsAroud;
+        erode(diff1, diff1, Mat());
+        double error = cv::norm(diff1, NORM_L1) / 255;
+        const int maxError = 10; // empirical number
+        if(error > maxError)
+        {
+            string outPath =
+                    string("CannyVX-diff-") +
+                    imgPath + '-' +
+                    'k' + char(kSize+'0') + '-' +
+                    (useL2 ? "l2" : "l1");
+            std::replace(outPath.begin(), outPath.end(), '/', '_');
+            std::replace(outPath.begin(), outPath.end(), '\\', '_');
+            std::replace(outPath.begin(), outPath.end(), '.', '_');
+            imwrite(outPath+".png", diff);
+        }
+        ASSERT_LE(error, maxError);
+
+    }
+}
+
+    INSTANTIATE_TEST_CASE_P(
+                ImgProc, CannyVX,
+                testing::Combine(
+                    testing::Values(
+                        string("shared/baboon.png"),
+                        string("shared/fruits.png"),
+                        string("shared/lena.png"),
+                        string("shared/pic1.png"),
+                        string("shared/pic3.png"),
+                        string("shared/pic5.png"),
+                        string("shared/pic6.png")
+                    ),
+                    testing::Values(ApertureSize(3), ApertureSize(5)),
+                    testing::Values(L2gradient(false), L2gradient(true))
+                )
+    );
+
 /* End of file. */