LibMultiSense
LibMultiSense Documentation
ApriltagDetections.hh
Go to the documentation of this file.
1 
39 #ifndef LibMultiSense_ApriltagDetections
40 #define LibMultiSense_ApriltagDetections
41 
42 #include "utility/Portability.hh"
43 
44 namespace crl {
45 namespace multisense {
46 namespace details {
47 namespace wire {
48 
50 public:
52  static CRL_CONSTEXPR VersionType VERSION = 1;
53 
54 #ifdef SENSORPOD_FIRMWARE
55  IdType id;
56  VersionType version;
57 #endif // SENSORPOD_FIRMWARE
58 
59  // The frame ID of the image that the apriltags were detected on
60  int64_t frameId;
61 
62  // The frame timestamp (nanoseconds) of the image that the apriltags were detected on
63  int64_t timestamp;
64 
65  // The image source that the apriltags were detected on
66  char imageSource[32];
67 
68  // Success flag to indicate whether for the apriltag algorithm ran successfully
69  uint8_t success;
70 
71  // The number of apriltags that were detected
72  uint32_t numDetections;
73 
74  //
75  // Constructors
76 
78 #ifdef SENSORPOD_FIRMWARE
79  id(ID),
80  version(VERSION),
81 #endif // SENSORPOD_FIRMWARE
82  frameId(0),
83  timestamp(0),
84  success(0),
85  numDetections(0)
86  {
87  strncpy(imageSource, "", sizeof(imageSource));
88  };
89 };
90 
92 public:
94 
95  // The family of the tag
96  char family[32];
97 
98  // The ID of the tag
99  uint32_t id;
100 
101  // The hamming distance between the detection and the real code
102  uint8_t hamming;
103 
104  // The quality/confidence of the binary decoding process
105  // average difference between intensity of data bit vs decision thresh.
106  // Higher is better. Only useful for small tags
108 
109  // The 3x3 homography matrix describing the projection from an
110  // "ideal" tag (with corners at (-1,1), (1,1), (1,-1), and (-1,
111  // -1)) to pixels in the image
112  double tagToImageHomography[3][3];
113 
114  // The 2D position of the origin of the tag in the image
115  double center[2];
116 
117  // The 4 tag corner pixel locations in the order:
118  // point 0: [-squareLength / 2, squareLength / 2]
119  // point 1: [ squareLength / 2, squareLength / 2]
120  // point 2: [ squareLength / 2, -squareLength / 2]
121  // point 3: [-squareLength / 2, -squareLength / 2]
122  double corners[4][2];
123 
124 #ifndef SENSORPOD_FIRMWARE
125  //
126  // Serialization routine
127 
128  template<class Archive>
129  void serialize(Archive& message,
130  const VersionType version)
131  {
132  (void) version;
133 
134  SER_ARRAY_1(family, 32);
135  message & id;
136  message & hamming;
137  message & decisionMargin;
139  SER_ARRAY_1(center, 2);
140  SER_ARRAY_2(corners, 4, 2);
141  }
142 #endif // !SENSORPOD_FIRMWARE
143 };
144 
146 public:
147 
148  //
149  // Apriltag detections
150 
151  std::vector<ApriltagDetection> detections;
152 
153 #ifndef SENSORPOD_FIRMWARE
154 
155  //
156  // Constructors
157 
159 
161 
162  //
163  // Serialization routine
164 
165  template<class Archive>
166  void serialize(Archive& message,
167  const VersionType version)
168  {
169  (void) version;
170 
171  message & frameId;
172  message & timestamp;
174  message & success;
175  message & numDetections;
176 
177  const uint32_t wireBytes = static_cast<uint32_t>(numDetections * sizeof(ApriltagDetection));
178 
179  if (typeid(Archive) == typeid(utility::BufferStreamWriter)) {
180 
181  message.write(reinterpret_cast<void*>(detections.data()), wireBytes);
182 
183  } else {
184 
185  void *rawDetectionsData = message.peek();
186  message.seek(message.tell() + wireBytes);
187 
188  detections.resize(numDetections);
189  memcpy(detections.data(), rawDetectionsData, wireBytes);
190  }
191 
192  }
193 #endif // !SENSORPOD_FIRMWARE
194 };
195 
196 }}}} // namespaces
197 
198 #endif
SER_ARRAY_1
#define SER_ARRAY_1(a_, n_)
Definition: Protocol.hh:347
crl::multisense::details::wire::ID_DATA_APRILTAG_DETECTIONS_MESSAGE
static CRL_CONSTEXPR IdType ID_DATA_APRILTAG_DETECTIONS_MESSAGE
Definition: Protocol.hh:235
crl::multisense::details::wire::ApriltagDetectionsHeader
Definition: ApriltagDetections.hh:49
crl::multisense::details::wire::ApriltagDetections::detections
std::vector< ApriltagDetection > detections
Definition: ApriltagDetections.hh:151
crl::multisense::details::wire::ApriltagDetections::ApriltagDetections
ApriltagDetections(utility::BufferStreamReader &r, VersionType v)
Definition: ApriltagDetections.hh:158
crl::multisense::details::wire::ApriltagDetectionsHeader::ApriltagDetectionsHeader
ApriltagDetectionsHeader()
Definition: ApriltagDetections.hh:77
Portability.hh
WIRE_HEADER_ATTRIBS_
#define WIRE_HEADER_ATTRIBS_
Definition: Protocol.hh:65
CRL_CONSTEXPR
#define CRL_CONSTEXPR
Definition: Portability.hh:49
crl::multisense::details::wire::ApriltagDetections::serialize
void serialize(Archive &message, const VersionType version)
Definition: ApriltagDetections.hh:166
crl::multisense::details::wire::ApriltagDetection::center
double center[2]
Definition: ApriltagDetections.hh:115
SER_ARRAY_2
#define SER_ARRAY_2(a_, n_, m_)
Definition: Protocol.hh:351
crl::multisense::details::wire::ApriltagDetection
Definition: ApriltagDetections.hh:91
crl::multisense::details::wire::ApriltagDetection::corners
double corners[4][2]
Definition: ApriltagDetections.hh:122
crl::multisense::details::wire::ApriltagDetection::hamming
uint8_t hamming
Definition: ApriltagDetections.hh:102
crl::multisense::details::wire::ApriltagDetections
Definition: ApriltagDetections.hh:145
crl
Definition: BufferStream.hh:51
crl::multisense::details::wire::ApriltagDetectionsHeader::success
uint8_t success
Definition: ApriltagDetections.hh:69
crl::multisense::details::wire::ApriltagDetectionsHeader::frameId
int64_t frameId
Definition: ApriltagDetections.hh:60
crl::multisense::details::wire::ApriltagDetection::id
uint32_t id
Definition: ApriltagDetections.hh:99
crl::multisense::details::wire::VersionType
uint16_t VersionType
Definition: Protocol.hh:137
crl::multisense::details::utility::BufferStreamWriter
Definition: BufferStream.hh:259
crl::multisense::details::wire::ApriltagDetection::family
char family[32]
Definition: ApriltagDetections.hh:96
crl::multisense::details::wire::ApriltagDetectionsHeader::numDetections
uint32_t numDetections
Definition: ApriltagDetections.hh:72
crl::multisense::details::wire::ApriltagDetections::ApriltagDetections
ApriltagDetections()
Definition: ApriltagDetections.hh:160
crl::multisense::details::wire::ApriltagDetection::serialize
void serialize(Archive &message, const VersionType version)
Definition: ApriltagDetections.hh:129
crl::multisense::details::wire::ApriltagDetection::VERSION
static CRL_CONSTEXPR VersionType VERSION
Definition: ApriltagDetections.hh:93
crl::multisense::details::wire::ApriltagDetectionsHeader::imageSource
char imageSource[32]
Definition: ApriltagDetections.hh:66
crl::multisense::details::utility::BufferStreamReader
Definition: BufferStream.hh:192
multisense
Definition: MultiSenseChannel.hh:44
crl::multisense::details::wire::ApriltagDetection::decisionMargin
float decisionMargin
Definition: ApriltagDetections.hh:107
crl::multisense::details::wire::ApriltagDetection::tagToImageHomography
double tagToImageHomography[3][3]
Definition: ApriltagDetections.hh:112
crl::multisense::details::wire::ApriltagDetectionsHeader::timestamp
int64_t timestamp
Definition: ApriltagDetections.hh:63
crl::multisense::details::wire::IdType
uint16_t IdType
Definition: Protocol.hh:136