imgproc(ocl): don't use doubles to process float data
authorAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 7 Sep 2017 09:42:20 +0000 (12:42 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 7 Sep 2017 09:42:20 +0000 (12:42 +0300)
modules/imgproc/src/imgwarp.cpp
modules/imgproc/src/opencl/warp_affine.cl
modules/imgproc/src/opencl/warp_perspective.cl

index 8c854a4..5b7e4b3 100644 (file)
@@ -2547,6 +2547,8 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
          (!doubleSupport && depth == CV_64F) || cn > 4)
         return false;
 
+    bool useDouble = depth == CV_64F;
+
     const char * const interpolationMap[3] = { "NEAREST", "LINEAR", "CUBIC" };
     ocl::ProgramSource program = op_type == OCL_OP_AFFINE ?
                 ocl::imgproc::warp_affine_oclsrc : ocl::imgproc::warp_perspective_oclsrc;
@@ -2561,8 +2563,10 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
     String opts;
     if (interpolation == INTER_NEAREST)
     {
-        opts = format("-D INTER_NEAREST -D T=%s%s -D T1=%s -D ST=%s -D cn=%d -D rowsPerWI=%d",
-                      ocl::typeToStr(type), doubleSupport ? " -D DOUBLE_SUPPORT" : "",
+        opts = format("-D INTER_NEAREST -D T=%s%s -D CT=%s -D T1=%s -D ST=%s -D cn=%d -D rowsPerWI=%d",
+                      ocl::typeToStr(type),
+                      doubleSupport ? " -D DOUBLE_SUPPORT" : "",
+                      useDouble ? "double" : "float",
                       ocl::typeToStr(CV_MAT_DEPTH(type)),
                       ocl::typeToStr(sctype), cn, rowsPerWI);
     }
@@ -2570,14 +2574,16 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
     {
         char cvt[2][50];
         opts = format("-D INTER_%s -D T=%s -D T1=%s -D ST=%s -D WT=%s -D depth=%d"
-                      " -D convertToWT=%s -D convertToT=%s%s -D cn=%d -D rowsPerWI=%d",
+                      " -D convertToWT=%s -D convertToT=%s%s -D CT=%s -D cn=%d -D rowsPerWI=%d",
                       interpolationMap[interpolation], ocl::typeToStr(type),
                       ocl::typeToStr(CV_MAT_DEPTH(type)),
                       ocl::typeToStr(sctype),
                       ocl::typeToStr(CV_MAKE_TYPE(wdepth, cn)), depth,
                       ocl::convertTypeStr(depth, wdepth, cn, cvt[0]),
                       ocl::convertTypeStr(wdepth, depth, cn, cvt[1]),
-                      doubleSupport ? " -D DOUBLE_SUPPORT" : "", cn, rowsPerWI);
+                      doubleSupport ? " -D DOUBLE_SUPPORT" : "",
+                      useDouble ? "double" : "float",
+                      cn, rowsPerWI);
     }
 
     k.create(kernelName, program, opts);
@@ -2614,7 +2620,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
             M[2] = b1; M[5] = b2;
         }
     }
-    matM.convertTo(M0, doubleSupport ? CV_64F : CV_32F);
+    matM.convertTo(M0, useDouble ? CV_64F : CV_32F);
 
     k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::PtrReadOnly(M0),
            ocl::KernelArg(ocl::KernelArg::CONSTANT, 0, 0, 0, borderBuf, CV_ELEM_SIZE(sctype)));
index 8c6c5f9..bfbd0a6 100644 (file)
@@ -49,9 +49,6 @@
 #elif defined (cl_khr_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64:enable
 #endif
-#define CT double
-#else
-#define CT float
 #endif
 
 #define INTER_BITS 5
index 211f45b..20e3a27 100644 (file)
@@ -49,9 +49,6 @@
 #elif defined (cl_khr_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64:enable
 #endif
-#define CT double
-#else
-#define CT float
 #endif
 
 #define INTER_BITS 5