sad.hpp
Go to the documentation of this file.
00001 #ifndef __fovis_sad_hpp__
00002 #define __fovis_sad_hpp__
00003 
00004 #ifdef FOVIS_USE_SSE
00005 #include <emmintrin.h>
00006 #endif
00007 
00008 namespace fovis
00009 {
00010 
00017 class SAD {
00018 public:
00019   SAD(int descriptor_len) :
00020       _descriptor_len(descriptor_len),
00021       _nsad_ops(descriptor_len / 16 + ((descriptor_len % 16) ? 1 : 0))
00022       { }
00023 
00029   int32_t score(const uint8_t *ref_desc, const uint8_t *target_desc) {
00030 #ifdef FOVIS_USE_SSE
00031     // compute sum of absolute differences (fast)
00032     const uint8_t * pp = ref_desc;
00033     const uint8_t * cp = target_desc;
00034     __m128i d = _mm_setzero_si128();
00035     for (int i = 0; i < _nsad_ops; i++) {
00036       __m128i c = _mm_sad_epu8(*(__m128i *) pp, *(__m128i *) cp);
00037       d = _mm_add_epi16(c, d);
00038       pp += 16;
00039       cp += 16;
00040     }
00041 
00042     __m128i e = _mm_srli_si128(d, 8);
00043     __m128i f = _mm_add_epi32(d, e);
00044 
00045     int32_t score = _mm_cvtsi128_si32(f);
00046 #else
00047     int32_t score = 0;
00048     for(int i=0; i<_descriptor_len; i++) {
00049       score += abs(ref_desc[i] - target_desc[i]);
00050     }
00051 #endif
00052     return score;
00053   }
00054 
00055   int getWorstScore() const {
00056     return _descriptor_len * 255;
00057   }
00058 
00059 private:
00060   int _descriptor_len;
00061   int _nsad_ops;
00062 };
00063 
00064 }
00065 
00066 #endif


libfovis
Author(s): Albert Huang, Maurice Fallon
autogenerated on Thu Jun 6 2019 20:16:12