cv::boxFilter
authorIlya Lavrenov <ilya.lavrenov@itseez.com>
Fri, 4 Apr 2014 19:46:50 +0000 (23:46 +0400)
committerIlya Lavrenov <ilya.lavrenov@itseez.com>
Tue, 8 Apr 2014 20:11:28 +0000 (00:11 +0400)
modules/imgproc/src/smooth.cpp
modules/imgproc/test/ocl/test_boxfilter.cpp

index 67b3793ad421043c37bfd08f446be5ad9878df0f..7138a84b84be00a1702c1d67af317551c7a2ea6f 100644 (file)
@@ -841,7 +841,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
     CV_OCL_RUN(_dst.isUMat(), ocl_boxFilter(_src, _dst, ddepth, ksize, anchor, borderType, normalize))
 
     Mat src = _src.getMat();
-    int sdepth = src.depth(), cn = src.channels();
+    int stype = src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype);
     if( ddepth < 0 )
         ddepth = sdepth;
     _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );
@@ -858,6 +858,64 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
         return;
 #endif
 
+    /*
+#ifdef HAVE_IPP
+    bool isolated = (borderType & BORDER_ISOLATED) != 0;
+    if (!normalize && !isolated && (borderType & ~BORDER_ISOLATED) == BORDER_REPLICATE && ddepth == sdepth &&
+        (anchor == Point(-1, -1) || anchor == Point(ksize.width >> 1, ksize.height >> 1)) && ksize.width == ksize.width)
+    {
+        Ipp32s bufSize;
+        IppiSize roiSize = ippiSize(dst.cols, dst.rows), maskSize = ippiSize(ksize.width, ksize.height);
+
+#define IPP_FILTER_BOX_BORDER(ippType, ippDataType, flavor) \
+        do \
+        { \
+            if (ippiFilterBoxBorderGetBufferSize(roiSize, maskSize, ippDataType, cn, &bufSize) >= 0) \
+            { \
+                Ipp8u * buffer = ippsMalloc_8u(bufSize); \
+                ippType borderValue[4] = { 0, 0, 0, 0 }; \
+                IppStatus status = ippiFilterBoxBorder_##flavor((ippType *)src.data, (int)src.step, (ippType *)dst.data, (int)dst.step, roiSize, maskSize, \
+                                                              ippBorderRepl, borderValue, buffer); \
+                ippFree(buffer); \
+                printf("%d\n", status); \
+                IPPI_CALL(status); \
+                if (status >= 0) \
+                    return; \
+            } \
+        } while ((void)0, 0)
+
+        if (stype == CV_8UC1)
+            IPP_FILTER_BOX_BORDER(Ipp8u, ipp8u, 8u_C1R);
+        else if (stype == CV_8UC3)
+            IPP_FILTER_BOX_BORDER(Ipp8u, ipp8u, 8u_C3R);
+        else if (stype == CV_8UC4)
+            IPP_FILTER_BOX_BORDER(Ipp8u, ipp8u, 8u_C4R);
+
+        else if (stype == CV_16UC1)
+            IPP_FILTER_BOX_BORDER(Ipp16u, ipp16u, 16u_C1R);
+        else if (stype == CV_16UC3)
+            IPP_FILTER_BOX_BORDER(Ipp16u, ipp16u, 16u_C3R);
+        else if (stype == CV_16UC4)
+            IPP_FILTER_BOX_BORDER(Ipp16u, ipp16u, 16u_C4R);
+
+        else if (stype == CV_16SC1)
+            IPP_FILTER_BOX_BORDER(Ipp16s, ipp16s, 16s_C1R);
+        else if (stype == CV_16SC3)
+            IPP_FILTER_BOX_BORDER(Ipp16s, ipp16s, 16s_C3R);
+        else if (stype == CV_16SC4)
+            IPP_FILTER_BOX_BORDER(Ipp16s, ipp16s, 16s_C4R);
+
+        else if (stype == CV_32FC1)
+            IPP_FILTER_BOX_BORDER(Ipp32f, ipp32f, 32f_C1R);
+        else if (stype == CV_32FC3)
+            IPP_FILTER_BOX_BORDER(Ipp32f, ipp32f, 32f_C3R);
+        else if (stype == CV_32FC4)
+            IPP_FILTER_BOX_BORDER(Ipp32f, ipp32f, 32f_C4R);
+    }
+#undef IPP_FILTER_BOX_BORDER
+#endif
+    */
+
     Ptr<FilterEngine> f = createBoxFilter( src.type(), dst.type(),
                         ksize, anchor, normalize, borderType );
     f->apply( src, dst );
@@ -1962,7 +2020,7 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize )
         if (ippiFilterMedianBorderGetBufferSize(dstRoiSize, maskSize, \
             ippDataType, CV_MAT_CN(type), &bufSize) >= 0) \
         { \
-            Ipp8u * buffer = (Ipp8u *)ippMalloc(bufSize); \
+            Ipp8u * buffer = ippsMalloc_8u(bufSize); \
             IppStatus status = ippiFilterMedianBorder_##flavor((const ippType *)src0.data, (int)src0.step, \
                 (ippType *)dst.data, (int)dst.step, dstRoiSize, maskSize, \
                 ippBorderRepl, (ippType)0, buffer); \
index 63f4ebff207b434d335debd5e5fad6c1d4c76f29..aa8b3d2f9ddc143931d27192181c27cdf739f57a 100644 (file)
@@ -102,7 +102,7 @@ typedef BoxFilterBase BoxFilter;
 
 OCL_TEST_P(BoxFilter, Mat)
 {
-    for (int j = 0; j < test_loop_times; j++)
+    for (int j = 0; j < 100; j++)
     {
         random_roi();