libvibe++ : a generic C++ library for the ViBe algorithm
Manhattan.h
Go to the documentation of this file.
1 /* Copyright - Benjamin Laugraud <blaugraud@ulg.ac.be> - 2016
2  * Copyright - Marc Van Droogenbroeck <m.vandroogenbroeck@ulg.ac.be> - 2016
3  *
4  * ViBe is covered by a patent (see http://www.telecom.ulg.ac.be/research/vibe).
5  *
6  * Permission to use ViBe without payment of fee is granted for nonprofit
7  * educational and research purposes only.
8  *
9  * This work may not be copied or reproduced in whole or in part for any
10  * purpose.
11  *
12  * Copying, reproduction, or republishing for any purpose shall require a
13  * license. Please contact the authors in such cases. All the code is provided
14  * without any guarantee.
15  */
16 
17 /**
18  @file Manhattan.h
19  @brief Distance function for computing the Euclidean distance between the pixel and samples of the model.
20 
21  @author Benjamin Laungraud and Marc Van Droogenbroeck
22 
23  @date June 2016
24 */
25 
26 #ifndef _LIB_VIBE_XX_COMMON_DISTANCES_MANHATTAN_H_
27 #define _LIB_VIBE_XX_COMMON_DISTANCES_MANHATTAN_H_
28 
29 #include "../math/AbsoluteValue.h"
30 #include "../metaprograms/DistanceL1.h"
31 #include "../system/inline.h"
32 #include "../system/types.h"
33 
34 #define LIB_VIBE_XX_MANHATTAN_MAP_FLOAT_FACTOR(CHANNELS, FACTOR_VAL) \
35  template <> \
36  struct ManhattanFactor<CHANNELS> { \
37  static const double FACTOR; \
38  }; \
39  \
40  const double ManhattanFactor<CHANNELS>::FACTOR = FACTOR_VAL;
41 
42 #define LIB_VIBE_XX_MANHATTAN_MAP_UINTG_FACTOR(CHANNELS, FACTOR_VAL) \
43  template <> \
44  struct ManhattanFactor<CHANNELS> { \
45  static const uint32_t FACTOR = FACTOR_VAL; \
46  };
47 
48 namespace ViBe {
49  namespace internals {
50  /* ====================================================================== *
51  * ManhattanFactor<Channels> *
52  * ====================================================================== */
53 
54  template <int32_t Channels>
55  struct ManhattanFactor {};
56 
57  LIB_VIBE_XX_MANHATTAN_MAP_UINTG_FACTOR(1, 1)
58  LIB_VIBE_XX_MANHATTAN_MAP_FLOAT_FACTOR(3, 4.5)
59  } /* _NS_internals_ */
60 
61  /* ======================================================================== *
62  * Manhattan<Channels> *
63  * ======================================================================== */
64  template <int32_t Channels>
65  struct Manhattan {
66  STRONG_INLINE static int32_t distance(
67  const uint8_t* pixel1,
68  const uint8_t* pixel2,
69  uint32_t threshold
70  ) {
71  return (
72  internals::DistanceL1<Channels>::add(pixel1, pixel2) <=
74  );
75  }
76  };
77 } /* _NS_ViBe_ */
78 
79 #endif /* _LIB_VIBE_XX_COMMON_DISTANCES_MANHATTAN_H_ */

License/Copyright

This code is copyrighted by the University of Liège, Belgium. 
It is only shared for research purposes. Please do not distribute it. 
B. Laugraud and M. Van Droogenbroeck, May 2016.