1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Third party copyrights are property of their respective owners. 16 // 17 // Redistribution and use in source and binary forms, with or without modification, 18 // are permitted provided that the following conditions are met: 19 // 20 // * Redistribution's of source code must retain the above copyright notice, 21 // this list of conditions and the following disclaimer. 22 // 23 // * Redistribution's in binary form must reproduce the above copyright notice, 24 // this list of conditions and the following disclaimer in the documentation 25 // and/or other materials provided with the distribution. 26 // 27 // * The name of the copyright holders may not be used to endorse or promote products 28 // derived from this software without specific prior written permission. 29 // 30 // This software is provided by the copyright holders and contributors "as is" and 31 // any express or implied warranties, including, but not limited to, the implied 32 // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 // In no event shall the Intel Corporation or contributors be liable for any direct, 34 // indirect, incidental, special, exemplary, or consequential damages 35 // (including, but not limited to, procurement of substitute goods or services; 36 // loss of use, data, or profits; or business interruption) however caused 37 // and on any theory of liability, whether in contract, strict liability, 38 // or tort (including negligence or otherwise) arising in any way out of 39 // the use of this software, even if advised of the possibility of such damage. 40 // 41 //M*/ 42 43 #if !defined CUDA_DISABLER 44 45 #include <thrust/device_ptr.h> 46 #include <thrust/remove.h> 47 #include <thrust/functional.h> 48 #include "opencv2/core/cuda/common.hpp" 49 50 namespace cv { namespace cuda { namespace device { namespace globmotion { 51 52 __constant__ float cml[9]; 53 __constant__ float cmr[9]; 54 55 int compactPoints(int N, float *points0, float *points1, const uchar *mask) 56 { 57 thrust::device_ptr<float2> dpoints0((float2*)points0); 58 thrust::device_ptr<float2> dpoints1((float2*)points1); 59 thrust::device_ptr<const uchar> dmask(mask); 60 61 return (int)(thrust::remove_if(thrust::make_zip_iterator(thrust::make_tuple(dpoints0, dpoints1)), 62 thrust::make_zip_iterator(thrust::make_tuple(dpoints0 + N, dpoints1 + N)), 63 dmask, thrust::not1(thrust::identity<uchar>())) 64 - thrust::make_zip_iterator(make_tuple(dpoints0, dpoints1))); 65 } 66 67 68 __global__ void calcWobbleSuppressionMapsKernel( 69 const int left, const int idx, const int right, const int width, const int height, 70 PtrStepf mapx, PtrStepf mapy) 71 { 72 const int x = blockDim.x * blockIdx.x + threadIdx.x; 73 const int y = blockDim.y * blockIdx.y + threadIdx.y; 74 75 if (x < width && y < height) 76 { 77 float xl = cml[0]*x + cml[1]*y + cml[2]; 78 float yl = cml[3]*x + cml[4]*y + cml[5]; 79 float izl = 1.f / (cml[6]*x + cml[7]*y + cml[8]); 80 xl *= izl; 81 yl *= izl; 82 83 float xr = cmr[0]*x + cmr[1]*y + cmr[2]; 84 float yr = cmr[3]*x + cmr[4]*y + cmr[5]; 85 float izr = 1.f / (cmr[6]*x + cmr[7]*y + cmr[8]); 86 xr *= izr; 87 yr *= izr; 88 89 float wl = idx - left; 90 float wr = right - idx; 91 mapx(y,x) = (wr * xl + wl * xr) / (wl + wr); 92 mapy(y,x) = (wr * yl + wl * yr) / (wl + wr); 93 } 94 } 95 96 97 void calcWobbleSuppressionMaps( 98 int left, int idx, int right, int width, int height, 99 const float *ml, const float *mr, PtrStepSzf mapx, PtrStepSzf mapy) 100 { 101 cudaSafeCall(cudaMemcpyToSymbol(cml, ml, 9*sizeof(float))); 102 cudaSafeCall(cudaMemcpyToSymbol(cmr, mr, 9*sizeof(float))); 103 104 dim3 threads(32, 8); 105 dim3 grid(divUp(width, threads.x), divUp(height, threads.y)); 106 107 calcWobbleSuppressionMapsKernel<<<grid, threads>>>( 108 left, idx, right, width, height, mapx, mapy); 109 110 cudaSafeCall(cudaGetLastError()); 111 cudaSafeCall(cudaDeviceSynchronize()); 112 } 113 114 }}}} 115 116 117 #endif /* CUDA_DISABLER */ 118