GpuSurfFeatures.hppGo to the documentation of this file.00001 00011 /* 00012 Copyright (c) 2010, Paul Furgale and Chi Hay Tong 00013 All rights reserved. 00014 00015 Redistribution and use in source and binary forms, with or without 00016 modification, are permitted provided that the following conditions are 00017 met: 00018 00019 * Redistributions of source code must retain the above copyright notice, 00020 this list of conditions and the following disclaimer. 00021 * Redistributions in binary form must reproduce the above copyright 00022 notice, this list of conditions and the following disclaimer in the 00023 documentation and/or other materials provided with the distribution. 00024 * The names of its contributors may not be used to endorse or promote 00025 products derived from this software without specific prior written 00026 permission. 00027 00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00030 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00031 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 00032 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00033 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00034 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00035 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00036 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00037 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00038 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 */ 00040 00041 #ifndef ASRL_GPU_SURF_FEATURES 00042 #define ASRL_GPU_SURF_FEATURES 00043 00044 //#include <builtin_types.h> 00045 #include "CudaSynchronizedMemory.hpp" 00046 #include "gpu_globals.h" 00047 00048 00049 namespace asrl { 00050 00055 class GpuSurfFeatures 00056 { 00057 public: 00058 00067 GpuSurfFeatures(); 00068 00073 ~GpuSurfFeatures(); 00074 00081 Keypoint * deviceFeatures(){return m_features.d_get();} 00082 00089 Keypoint * hostFeatures(){return m_features.h_get();} 00090 00097 float * deviceDescriptors(){return m_descriptors.d_get();} 00098 00105 float * hostDescriptors(){ return m_descriptors.h_get();} 00106 00113 unsigned int * deviceFtCount(){return m_feature_counter.d_get(); } 00114 00121 unsigned int * hostFtCount(){return m_feature_counter.h_get(); } 00122 00128 Keypoint * downloadFeatures(); 00129 00138 unsigned int ftCount(); 00139 00148 unsigned int rawFeatureCount(); 00149 00154 void clearFeatureCounts(); 00155 00162 float * downloadDescriptors(); 00163 00169 void setDirty(); 00170 00174 CudaSynchronizedMemory<Keypoint> & featuresMem(){return m_features;} 00175 00179 CudaSynchronizedMemory<float> & descriptorsMem(){ return m_descriptors;} 00180 00184 CudaSynchronizedMemory<unsigned int> & featureCounterMem(){ return m_feature_counter;} 00188 CudaSynchronizedMemory<int4> & rawFeatureMem(){ return m_rawFeatures; } 00189 00197 template<typename CV_KEYPOINT_VECTOR> 00198 void getKeypoints(CV_KEYPOINT_VECTOR & outKeypoints); 00199 00206 template<typename CV_KEYPOINT_VECTOR> 00207 void getRawKeypoints(CV_KEYPOINT_VECTOR & outKeypoints); 00208 00216 template<typename CV_KEYPOINT_VECTOR> 00217 void setKeypoints(CV_KEYPOINT_VECTOR const & inKeypoints); 00218 private: 00219 00221 CudaSynchronizedMemory<Keypoint> m_features; 00222 00224 CudaSynchronizedMemory<float> m_descriptors; 00225 00227 CudaSynchronizedMemory<unsigned int> m_feature_counter; 00228 00230 CudaSynchronizedMemory<int4> m_rawFeatures; 00231 00233 bool m_descriptorsDirty; 00234 00236 bool m_featuresDirty; 00237 00239 bool m_countDirty; 00240 }; 00241 00242 // This is overly clever. Using a template here avoids including 00243 // the OpenCV header which CUDA has terrible problems with. 00244 template<typename CV_KEYPOINT_VECTOR> 00245 void GpuSurfFeatures::getKeypoints(CV_KEYPOINT_VECTOR & outKeypoints) 00246 { 00247 // This has an implicit "Thread synchronize" 00248 int ftcount = ftCount(); 00249 00250 featuresMem().pullFromDevice(); 00251 //m_features->descriptorsMem().pullFromDevice(); 00252 00253 outKeypoints.resize(ftcount); 00254 if(ftcount > 0) 00255 { 00256 00257 for(int i = 0; i < ftcount; i++) 00258 { 00259 typename CV_KEYPOINT_VECTOR::value_type & k = outKeypoints[i]; 00260 Keypoint * ft = hostFeatures() + i; 00261 00262 k.pt.x = ft->x; 00263 k.pt.y = ft->y; 00264 00265 k.size = ft->size; 00266 00267 k.octave= ft->octave; 00268 k.angle = ft->angle; 00269 k.response = ft->response; 00270 00271 } 00272 } 00273 00274 } 00275 00276 template<typename CV_KEYPOINT_VECTOR> 00277 void GpuSurfFeatures::getRawKeypoints(CV_KEYPOINT_VECTOR & outKeypoints) 00278 { 00279 // This has an implicit "Thread synchronize" 00280 m_feature_counter.pullFromDevice(); 00281 m_rawFeatures.pullFromDevice(); 00282 int ftcount = m_feature_counter[1]; 00283 00284 00285 outKeypoints.resize(ftcount); 00286 00287 00288 for(int i = 0; i < ftcount; i++) { 00289 // {hidx_x, hidx_y, threadIdx.z, octave}; 00290 typename CV_KEYPOINT_VECTOR::value_type & k = outKeypoints[i]; 00291 00292 k.pt.x = (float)m_rawFeatures[i].x; 00293 k.pt.y = (float)m_rawFeatures[i].y; 00294 00295 k.response = (float)m_rawFeatures[i].z; 00296 00297 k.octave= m_rawFeatures[i].w; 00298 k.angle = 0; 00299 00300 } 00301 00302 00303 } 00304 00305 template<typename CV_KEYPOINT_VECTOR> 00306 void GpuSurfFeatures::setKeypoints(CV_KEYPOINT_VECTOR const & inKeypoints){ 00307 00308 ASRL_ASSERT_LT(inKeypoints.size(), ASRL_SURF_MAX_FEATURES, "The device is unable to hold " << inKeypoints.size() << " features. Max: " << ASRL_SURF_MAX_FEATURES); 00309 00310 m_feature_counter[0] = inKeypoints.size(); 00311 m_feature_counter.pushToDevice(); 00312 00313 for(unsigned i = 0; i < inKeypoints.size(); i++) 00314 { 00315 typename CV_KEYPOINT_VECTOR::value_type const & k = inKeypoints[i]; 00316 Keypoint & ft = m_features[i]; 00317 ft.x = k.pt.x; 00318 ft.y = k.pt.y; 00319 ft.size = k.size; 00320 ft.angle = k.angle; 00321 ft.response = k.response; 00322 ft.octave = k.octave; 00323 } 00324 00325 m_features.pushToDevice(inKeypoints.size()); 00326 } 00327 } // namespace asrl 00328 00329 #endif Generated on Fri Apr 30 20:06:19 2010 for gpusurf by 1.6.2 |