Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLFilter/src/ICLFilter/MotionSensitiveTemporalSmoothi ** 00010 ** ng.h ** 00011 ** Module : ICLFilter ** 00012 ** Authors: Andre Ueckermann ** 00013 ** ** 00014 ** ** 00015 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00016 ** This file may be used under the terms of the GNU Lesser General ** 00017 ** Public License version 3.0 as published by the ** 00018 ** ** 00019 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00020 ** included in the packaging of this file. Please review the ** 00021 ** following information to ensure the license requirements will ** 00022 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00023 ** ** 00024 ** The development of this software was supported by the ** 00025 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00026 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00027 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00028 ** Excellence Initiative. ** 00029 ** ** 00030 ********************************************************************/ 00031 00032 #pragma once 00033 00034 #include <ICLFilter/UnaryOp.h> 00035 #include <ICLCore/Img.h> 00036 #include <ICLUtils/Uncopyable.h> 00037 00038 #ifdef HAVE_OPENCL 00039 #include <CL/cl.hpp> 00040 #endif 00041 00042 namespace icl{ 00043 namespace filter{ 00044 00045 class TemporalSmoothingCL{ 00046 public: 00047 00049 00052 TemporalSmoothingCL(utils::Size size, core::depth depth, int iMaxFilterSize, int iNullValue); 00053 00055 ~TemporalSmoothingCL(); 00056 00058 00060 core::Img32f temporalSmoothingF(core::Img32f &inputImage); 00061 00063 00065 core::Img8u temporalSmoothingC(core::Img8u &inputImage); 00066 00068 00069 void setUseCL(bool use); 00070 00072 00073 void setFilterSize(int iFilterSize); 00074 00076 00077 void setDifference(int iDifference); 00078 00080 00081 core::Img32f getMotionImage(); 00082 00084 00085 bool isCLReady(); 00086 00088 00089 bool isCLActive(); 00090 00091 private: 00092 00093 int w,h; 00094 core::depth d; 00095 bool clReady; 00096 bool useCL; 00097 00098 int imgCount; 00099 00100 int filterSize; 00101 int currentFilterSize; 00102 int maxFilterSize; 00103 00104 int currentDifference; 00105 int nullValue; 00106 00107 std::vector<core::Img32f> inputImagesF; 00108 core::Img32f outputImageF; 00109 std::vector<core::Img8u> inputImagesC; 00110 core::Img8u outputImageC; 00111 core::Img32f motionImage; 00112 00113 #ifdef HAVE_OPENCL 00114 //OpenCL 00115 float* inputImage1ArrayF; 00116 float* inputImagesArrayF; 00117 float* outputImageArrayF; 00118 00119 cl_uchar* inputImage1ArrayC; 00120 cl_uchar* inputImagesArrayC; 00121 cl_uchar* outputImageArrayC; 00122 00123 float* motionImageArray; 00124 00125 cl::Context context; 00126 std::vector<cl::Device> devices; 00127 cl::Program program; 00128 cl::CommandQueue queue; 00129 00130 cl::Kernel kernelTemporalSmoothingFloat; 00131 cl::Kernel kernelTemporalSmoothingChar; 00132 00133 cl::Buffer inputImageBufferF; 00134 cl::Buffer outputImageBufferF; 00135 cl::Buffer inputImageBufferC; 00136 cl::Buffer outputImageBufferC; 00137 cl::Buffer motionImageBuffer; 00138 00139 #endif 00140 00141 }; 00142 00143 class MotionSensitiveTemporalSmoothing : public UnaryOp, public utils::Uncopyable{ 00144 public: 00145 00147 00149 MotionSensitiveTemporalSmoothing(int iNullValue, int iMaxFilterSize); 00150 00152 ~MotionSensitiveTemporalSmoothing(); 00153 00155 00159 virtual void apply(const core::ImgBase *src, core::ImgBase **dst); 00160 00162 using UnaryOp::apply; 00163 00165 00166 void setUseCL(bool use); 00167 00169 00170 void setFilterSize(int filterSize); 00171 00173 00174 void setDifference(int difference); 00175 00177 00178 core::Img32f getMotionImage(); 00179 00181 00182 bool isCLActive(); 00183 00184 private: 00185 00186 void init(int iChannels, core::depth iDepth, utils::Size iSize); 00187 00188 bool useCL; 00189 00190 int currentFilterSize; 00191 int currentDifference; 00192 00193 int nullValue; 00194 int maxFilterSize; 00195 00196 int numChannels; 00197 utils::Size size; 00198 core::depth depth; 00199 00200 std::vector<TemporalSmoothingCL*> clPointer; 00201 }; 00202 00203 } // namespace filter 00204 }