add new comparison to tolerate with rounding error
authorTomoaki Teshima <tomoaki.teshima@gmail.com>
Thu, 19 Apr 2018 08:31:42 +0000 (17:31 +0900)
committerTomoaki Teshima <tomoaki.teshima@gmail.com>
Thu, 19 Apr 2018 08:31:42 +0000 (17:31 +0900)
  * restore resize of carotene
  * clean up the source code
  * remove unused member function (Near)
  * add strict test on the border

3rdparty/carotene/hal/tegra_hal.hpp
modules/imgproc/test/ocl/test_warp.cpp
modules/ts/include/opencv2/ts/ocl_test.hpp

index 8d17a4b..e6a3209 100644 (file)
@@ -1433,8 +1433,7 @@ inline int TEGRA_MORPHFREE(cvhalFilter2D *context)
 
 #define TEGRA_RESIZE(src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width, dst_height, inv_scale_x, inv_scale_y, interpolation) \
 ( \
-    /*bilinear interpolation disabled due to rounding accuracy issues*/ \
-    /*interpolation == CV_HAL_INTER_LINEAR ? \
+    interpolation == CV_HAL_INTER_LINEAR ? \
         CV_MAT_DEPTH(src_type) == CV_8U && CAROTENE_NS::isResizeLinearOpenCVSupported(CAROTENE_NS::Size2D(src_width, src_height), CAROTENE_NS::Size2D(dst_width, dst_height), ((src_type >> CV_CN_SHIFT) + 1)) && \
         inv_scale_x > 0 && inv_scale_y > 0 && \
         (dst_width - 0.5)/inv_scale_x - 0.5 < src_width && (dst_height - 0.5)/inv_scale_y - 0.5 < src_height && \
@@ -1442,7 +1441,7 @@ inline int TEGRA_MORPHFREE(cvhalFilter2D *context)
         std::abs(dst_width / inv_scale_x - src_width) < 0.1 && std::abs(dst_height / inv_scale_y - src_height) < 0.1 ? \
             CAROTENE_NS::resizeLinearOpenCV(CAROTENE_NS::Size2D(src_width, src_height), CAROTENE_NS::Size2D(dst_width, dst_height), \
                                             src_data, src_step, dst_data, dst_step, 1.0/inv_scale_x, 1.0/inv_scale_y, ((src_type >> CV_CN_SHIFT) + 1)), \
-            CV_HAL_ERROR_OK : CV_HAL_ERROR_NOT_IMPLEMENTED :*/ \
+            CV_HAL_ERROR_OK : CV_HAL_ERROR_NOT_IMPLEMENTED : \
     interpolation == CV_HAL_INTER_AREA ? \
         CV_MAT_DEPTH(src_type) == CV_8U && CAROTENE_NS::isResizeAreaSupported(1.0/inv_scale_x, 1.0/inv_scale_y, ((src_type >> CV_CN_SHIFT) + 1)) && \
         std::abs(dst_width / inv_scale_x - src_width) < 0.1 && std::abs(dst_height / inv_scale_y - src_height) < 0.1 ? \
index 7b71520..bc82808 100644 (file)
@@ -304,14 +304,9 @@ PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int)
         UMAT_UPLOAD_INPUT_PARAMETER(src);
         UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
     }
-
-    void Near(double threshold = 0.0)
-    {
-        OCL_EXPECT_MATS_NEAR(dst, threshold);
-    }
 };
 
-#if defined(__aarch64__)
+#if defined(__aarch64__) || defined(__arm__)
 const int integerEps = 3;
 #else
 const int integerEps = 1;
@@ -328,7 +323,7 @@ OCL_TEST_P(Resize, Mat)
         OCL_OFF(cv::resize(src_roi, dst_roi, Size(), fx, fy, interpolation));
         OCL_ON(cv::resize(usrc_roi, udst_roi, Size(), fx, fy, interpolation));
 
-        Near(eps);
+        OCL_EXPECT_MAT_N_DIFF(dst, eps);
     }
 }
 
@@ -388,11 +383,6 @@ PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderTy
         if (noType != map2Type)
             UMAT_UPLOAD_INPUT_PARAMETER(map2);
     }
-
-    void Near(double threshold = 0.0)
-    {
-        OCL_EXPECT_MATS_NEAR(dst, threshold);
-    }
 };
 
 typedef Remap Remap_INTER_NEAREST;
@@ -406,7 +396,7 @@ OCL_TEST_P(Remap_INTER_NEAREST, Mat)
         OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_NEAREST, borderType, val));
         OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_NEAREST, borderType, val));
 
-        Near(1.0);
+        OCL_EXPECT_MAT_N_DIFF(dst, 1.0);
     }
 }
 
@@ -423,12 +413,14 @@ OCL_TEST_P(Remap_INTER_LINEAR, Mat)
         // TODO investigate accuracy
         if (cv::ocl::Device::getDefault().isNVidia())
             eps = 8.0;
+#elif defined(__arm__)
+        eps = 8.0;
 #endif
 
         OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
         OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
 
-        Near(eps);
+        OCL_EXPECT_MAT_N_DIFF(dst, eps);
     }
 }
 
index 13e398c..6126883 100644 (file)
@@ -122,6 +122,25 @@ do \
     << "Size: " << mat1.size() << std::endl; \
 } while ((void)0, 0)
 
+#define OCL_EXPECT_MAT_N_DIFF(name, eps) \
+do \
+{ \
+    ASSERT_EQ(name ## _roi.type(), u ## name ## _roi.type()); \
+    ASSERT_EQ(name ## _roi.size(), u ## name ## _roi.size()); \
+    Mat diff, binary, binary_8; \
+    absdiff(name ## _roi, u ## name ## _roi, diff); \
+    Mat mask(diff.size(), CV_8UC(dst.channels()), cv::Scalar::all(255)); \
+    if (mask.cols > 2 && mask.rows > 2) \
+        mask(cv::Rect(1, 1, mask.cols - 2, mask.rows - 2)).setTo(0); \
+    cv::threshold(diff, binary, (double)eps, 255, cv::THRESH_BINARY); \
+    EXPECT_LE(countNonZero(binary.reshape(1)), (int)(binary.cols*binary.rows*5/1000)) \
+        << "Size: " << name ## _roi.size() << std::endl; \
+    binary.convertTo(binary_8, mask.type()); \
+    binary_8 = binary_8 & mask; \
+    EXPECT_LE(countNonZero(binary_8.reshape(1)), (int)((binary_8.cols+binary_8.rows)/100)) \
+        << "Size: " << name ## _roi.size() << std::endl; \
+} while ((void)0, 0)
+
 #define OCL_EXPECT_MATS_NEAR(name, eps) \
 do \
 { \