added new dtypes to cv::Sobel
authorIlya Lavrenov <ilya.lavrenov@itseez.com>
Thu, 6 Mar 2014 13:28:00 +0000 (17:28 +0400)
committerIlya Lavrenov <ilya.lavrenov@itseez.com>
Thu, 6 Mar 2014 13:57:13 +0000 (17:57 +0400)
modules/imgproc/src/filter.cpp
modules/imgproc/src/opencl/filterSepCol.cl

index 8a4c742..ea0baf6 100644 (file)
@@ -3419,7 +3419,7 @@ static bool ocl_sepRowFilter2D( UMat &src, UMat &buf, Mat &kernelX, int anchor,
     return kernelRow.run(2, globalsize, localsize, sync);
 }
 
-static bool ocl_sepColFilter2D(UMat &buf, UMat &dst, Mat &kernelY, int anchor, bool sync)
+static bool ocl_sepColFilter2D(const UMat &buf, UMat &dst, Mat &kernelY, int anchor, bool sync)
 {
 #ifdef ANDROID
     size_t localsize[2] = {16, 10};
@@ -3428,62 +3428,20 @@ static bool ocl_sepColFilter2D(UMat &buf, UMat &dst, Mat &kernelY, int anchor, b
 #endif
     size_t globalsize[2] = {0, 0};
 
-    int type = dst.type();
-    int cn = CV_MAT_CN(type);
-    int ddepth = CV_MAT_DEPTH(type);
+    int dtype = dst.type(), cn = CV_MAT_CN(dtype), ddepth = CV_MAT_DEPTH(dtype);
     Size sz = dst.size();
 
     globalsize[1] = DIVUP(sz.height, localsize[1]) * localsize[1];
 
-    cv::String build_options;
-    if (CV_8U == ddepth)
-    {
-        switch (cn)
-        {
-        case 1:
-            globalsize[0] = DIVUP(sz.width, localsize[0]) * localsize[0];
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float", "uchar", "convert_uchar_sat");
-            break;
-        case 2:
-            globalsize[0] = DIVUP((sz.width + 1) / 2, localsize[0]) * localsize[0];
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float2", "uchar2", "convert_uchar2_sat");
-            break;
-        case 3:
-        case 4:
-            globalsize[0] = DIVUP(sz.width, localsize[0]) * localsize[0];
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float4", "uchar4", "convert_uchar4_sat");
-            break;
-        }
-    }
+    if (dtype == CV_8UC2)
+        globalsize[0] = DIVUP((sz.width + 1) / 2, localsize[0]) * localsize[0];
     else
-    {
         globalsize[0] = DIVUP(sz.width, localsize[0]) * localsize[0];
-        switch (dst.type())
-        {
-        case CV_32SC1:
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float", "int", "convert_int_sat");
-            break;
-        case CV_32SC3:
-        case CV_32SC4:
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float4", "int4", "convert_int4_sat");
-            break;
-        case CV_32FC1:
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float", "float", "");
-            break;
-        case CV_32FC3:
-        case CV_32FC4:
-            build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
-                    anchor, (int)localsize[0], (int)localsize[1], cn, "float4", "float4", "");
-            break;
-        }
-    }
 
+    char cvt[40];
+    cv::String build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s",
+                    anchor, (int)localsize[0], (int)localsize[1], cn, ocl::typeToStr(buf.type()),
+                                          ocl::typeToStr(dtype), ocl::convertTypeStr(CV_32F, ddepth, cn, cvt));
     build_options += ocl::kernelToStr(kernelY, CV_32F);
 
     ocl::Kernel kernelCol;
@@ -3513,8 +3471,8 @@ static bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth,
         return false;
 
     int type = _src.type();
-    if ( !( (CV_8UC1 == type || CV_8UC4 == type || CV_32FC1 == type || CV_32FC4 == type) &&
-            (ddepth == CV_32F || ddepth == CV_8U || ddepth < 0) ) )
+    if ( !( (type == CV_8UC1 || type == CV_8UC4 || type == CV_32FC1 || type == CV_32FC4) &&
+            (ddepth == CV_32F || ddepth == CV_16S || ddepth == CV_8U || ddepth < 0) ) )
         return false;
 
     int cn = CV_MAT_CN(type);
index 2657ae9..30a2221 100644 (file)
@@ -47,6 +47,8 @@
 #define READ_TIMES_ROW ((2*(RADIUS+LSIZE0)-1)/LSIZE0)
 #endif
 
+#define noconvert
+
 /**********************************************************************************
 These kernels are written for separable filters such as Sobel, Scharr, GaussianBlur.
 Now(6/29/2011) the kernels only support 8U data type and the anchor of the convovle