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 #include "precomp.hpp" 44 45 using namespace cv; 46 using namespace cv::cuda; 47 48 #if !defined HAVE_CUDA || defined(CUDA_DISABLER) 49 50 void cv::cuda::reprojectImageTo3D(InputArray, OutputArray, InputArray, int, Stream&) { throw_no_cuda(); } 51 void cv::cuda::drawColorDisp(InputArray, OutputArray, int, Stream&) { throw_no_cuda(); } 52 53 #else 54 55 //////////////////////////////////////////////////////////////////////// 56 // reprojectImageTo3D 57 58 namespace cv { namespace cuda { namespace device 59 { 60 template <typename T, typename D> 61 void reprojectImageTo3D_gpu(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream); 62 }}} 63 64 void cv::cuda::reprojectImageTo3D(InputArray _disp, OutputArray _xyz, InputArray _Q, int dst_cn, Stream& stream) 65 { 66 using namespace cv::cuda::device; 67 68 typedef void (*func_t)(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream); 69 static const func_t funcs[2][4] = 70 { 71 {reprojectImageTo3D_gpu<uchar, float3>, 0, 0, reprojectImageTo3D_gpu<short, float3>}, 72 {reprojectImageTo3D_gpu<uchar, float4>, 0, 0, reprojectImageTo3D_gpu<short, float4>} 73 }; 74 75 GpuMat disp = _disp.getGpuMat(); 76 Mat Q = _Q.getMat(); 77 78 CV_Assert( disp.type() == CV_8U || disp.type() == CV_16S ); 79 CV_Assert( Q.type() == CV_32F && Q.rows == 4 && Q.cols == 4 && Q.isContinuous() ); 80 CV_Assert( dst_cn == 3 || dst_cn == 4 ); 81 82 _xyz.create(disp.size(), CV_MAKE_TYPE(CV_32F, dst_cn)); 83 GpuMat xyz = _xyz.getGpuMat(); 84 85 funcs[dst_cn == 4][disp.type()](disp, xyz, Q.ptr<float>(), StreamAccessor::getStream(stream)); 86 } 87 88 //////////////////////////////////////////////////////////////////////// 89 // drawColorDisp 90 91 namespace cv { namespace cuda { namespace device 92 { 93 void drawColorDisp_gpu(const PtrStepSzb& src, const PtrStepSzb& dst, int ndisp, const cudaStream_t& stream); 94 void drawColorDisp_gpu(const PtrStepSz<short>& src, const PtrStepSzb& dst, int ndisp, const cudaStream_t& stream); 95 }}} 96 97 namespace 98 { 99 template <typename T> 100 void drawColorDisp_caller(const GpuMat& src, OutputArray _dst, int ndisp, const cudaStream_t& stream) 101 { 102 using namespace ::cv::cuda::device; 103 104 _dst.create(src.size(), CV_8UC4); 105 GpuMat dst = _dst.getGpuMat(); 106 107 drawColorDisp_gpu((PtrStepSz<T>)src, dst, ndisp, stream); 108 } 109 } 110 111 void cv::cuda::drawColorDisp(InputArray _src, OutputArray dst, int ndisp, Stream& stream) 112 { 113 typedef void (*drawColorDisp_caller_t)(const GpuMat& src, OutputArray dst, int ndisp, const cudaStream_t& stream); 114 const drawColorDisp_caller_t drawColorDisp_callers[] = {drawColorDisp_caller<unsigned char>, 0, 0, drawColorDisp_caller<short>, 0, 0, 0, 0}; 115 116 GpuMat src = _src.getGpuMat(); 117 118 CV_Assert( src.type() == CV_8U || src.type() == CV_16S ); 119 120 drawColorDisp_callers[src.type()](src, dst, ndisp, StreamAccessor::getStream(stream)); 121 } 122 123 #endif 124