 
 
 void matchTemplateNaive_32F_SQDIFF(const DevMem2D image, const DevMem2D templ,
-                                DevMem2Df result)
+                                   DevMem2Df result)
 {
     dim3 threads(32, 8);
     dim3 grid(divUp(image.cols - templ.cols + 1, threads.x), 
-            divUp(image.rows - templ.rows + 1, threads.y));
+              divUp(image.rows - templ.rows + 1, threads.y));
 
     cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();
-    cudaBindTexture2D(0, imageTex_32F, image.data, desc, image.cols, image.rows, image.step);
-    cudaBindTexture2D(0, templTex_32F, templ.data, desc, templ.cols, templ.rows, templ.step);
-    imageTex_8U.filterMode = cudaFilterModePoint;
-    templTex_8U.filterMode = cudaFilterModePoint;
+    cudaBindTexture2D(0, imageTex_32F_SQDIFF, image.data, desc, image.cols, image.rows, image.step);
+    cudaBindTexture2D(0, templTex_32F_SQDIFF, templ.data, desc, templ.cols, templ.rows, templ.step);
+    imageTex_8U_SQDIFF.filterMode = cudaFilterModePoint;
+    templTex_8U_SQDIFF.filterMode = cudaFilterModePoint;
 
     matchTemplateNaiveKernel_32F_SQDIFF<<<grid, threads>>>(templ.cols, templ.rows, result);
     cudaSafeCall(cudaThreadSynchronize());
-    cudaSafeCall(cudaUnbindTexture(imageTex_32F));
-    cudaSafeCall(cudaUnbindTexture(templTex_32F));
+    cudaSafeCall(cudaUnbindTexture(imageTex_32F_SQDIFF));
+    cudaSafeCall(cudaUnbindTexture(templTex_32F_SQDIFF));
 }
 
 



void matchTemplateNaive_8U_SQDIFF(const DevMem2D image, const DevMem2D templ,
                                DevMem2Df result)
{
    dim3 threads(32, 8);
    dim3 grid(divUp(image.cols - templ.cols + 1, threads.x), 
            divUp(image.rows - templ.rows + 1, threads.y));

    cudaChannelFormatDesc desc = cudaCreateChannelDesc<unsigned char>();
    cudaBindTexture2D(0, imageTex_8U, image.data, desc, image.cols, image.rows, image.step);
    cudaBindTexture2D(0, templTex_8U, templ.data, desc, templ.cols, templ.rows, templ.step);
    imageTex_8U.filterMode = cudaFilterModePoint;
    templTex_8U.filterMode = cudaFilterModePoint;

    matchTemplateNaiveKernel_8U_SQDIFF<<<grid, threads>>>(templ.cols, templ.rows, result);
    cudaSafeCall(cudaThreadSynchronize());
    cudaSafeCall(cudaUnbindTexture(imageTex_8U));
    cudaSafeCall(cudaUnbindTexture(templTex_8U));
}


texture<float, 2> imageTex_32F;
texture<float, 2> templTex_32F;


__global__ void matchTemplateNaiveKernel_32F_SQDIFF(int w, int h, 


    if (x < result.cols && y < result.rows)
    {
        float image_sqsum_ = (float)(
                (image_sqsum.ptr(y + h)[x + w] - image_sqsum.ptr(y)[x + w]) -
                (image_sqsum.ptr(y + h)[x] - image_sqsum.ptr(y)[x]));
        result.ptr(y)[x] *= rsqrtf(image_sqsum_ * templ_sqsum);
    }
}

