1 #ifndef __fovis_sad_hpp__
2 #define __fovis_sad_hpp__
19 SAD(
int descriptor_len) :
20 _descriptor_len(descriptor_len),
21 _nsad_ops(descriptor_len / 16 + ((descriptor_len % 16) ? 1 : 0))
29 int32_t
score(
const uint8_t *ref_desc,
const uint8_t *target_desc) {
32 const uint8_t * pp = ref_desc;
33 const uint8_t * cp = target_desc;
34 __m128i d = _mm_setzero_si128();
35 for (
int i = 0; i < _nsad_ops; i++) {
36 __m128i c = _mm_sad_epu8(*(__m128i *) pp, *(__m128i *) cp);
37 d = _mm_add_epi16(c, d);
42 __m128i e = _mm_srli_si128(d, 8);
43 __m128i f = _mm_add_epi32(d, e);
45 int32_t
score = _mm_cvtsi128_si32(f);
48 for(
int i=0; i<_descriptor_len; i++) {
49 score += abs(ref_desc[i] - target_desc[i]);
55 int getWorstScore()
const {
56 return _descriptor_len * 255;
Calculates the Sum of Absolute Deviations (SAD) score between two vectors of length descriptor_len...
Definition: sad.hpp:17
quick and dirty profiling tool.inspired by the matlab tic/toc command
Definition: camera_intrinsics.hpp:6
int32_t score(const uint8_t *ref_desc, const uint8_t *target_desc)
Definition: sad.hpp:29