MIRA
Marker.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * All rights reserved.
5  *
6  * Redistribution and modification of this code is strictly prohibited.
7  *
8  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
9  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
10  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HS BEEN
11  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12  *
13  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
14  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
16  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
17  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
18  */
19 
28 #ifndef _MLAB_LOCALIZATION_MARKER_H_
29 #define _MLAB_LOCALIZATION_MARKER_H_
30 
31 #include <opencv2/calib3d/calib3d.hpp>
32 
33 #include <factory/Factory.h>
34 
35 #include <transform/Pose.h>
36 
37 namespace mira { namespace localization {
38 
40 
42 class Marker : public Object
43 {
45 public:
46  Marker() {}
47 
49  // the translation and rotational vector computed by cv::solvePnP.
50  Marker(const cv::Mat& Tvec, const cv::Mat& Rvec)
51  {
52  if (Tvec.rows != 3 || Tvec.cols != 1)
53  MIRA_THROW(XInvalidParameter, "Can't construct marker pose: "
54  "Unexpected size of tvec (rows=" << Tvec.rows << ", cols=" << Tvec.cols <<")");
55  if (Rvec.rows != 3 || Rvec.cols != 1)
56  MIRA_THROW(XInvalidParameter, "Can't construct marker pose: "
57  "Unexpected size of rvec (rows=" << Rvec.rows << ", cols=" << Rvec.cols <<")");
58 
59  // convert rvec to (3x3) rotation matrix
60  cv::Mat rotMat(3, 3, CV_32F);
61  cv::Rodrigues(Rvec, rotMat);
62 
63  // ... convert to Eigen matrix
64  Eigen::Map<Eigen::Matrix3f> eigenRotMat((float*)rotMat.data);
65 
66  // ... and compute the euler angles
67  Eigen::Vector3f ea = eulerAngles(eigenRotMat, 2, 1, 0);
68 
69  pose = Pose3(Tvec.at<float>(0, 0), Tvec.at<float>(0, 1), Tvec.at<float>(0, 2),
70  ea[0], ea[1], -ea[2]);
71  }
72 
73  template<typename Reflector>
74  void reflect(Reflector& r)
75  {
77 
78  r.member("Pose", pose, "Marker pose", REFLECT_CTRLFLAG_MEMBER_AS_ROPROPERTY);
79  r.member("ID", id, "Identifier", REFLECT_CTRLFLAG_MEMBER_AS_ROPROPERTY);
80 
81  if (version >= 2)
82  r.member("Timestamp", markerTimestamp, "Timestamp", REFLECT_CTRLFLAG_MEMBER_AS_ROPROPERTY);
83  }
84 
85 public:
87  std::string id;
89 };
90 
92 
94 typedef boost::shared_ptr<Marker> MarkerPtr;
95 
97 typedef std::multimap<std::string, MarkerPtr> MarkerMap;
98 
100 
101 }} // namespace
102 
103 #endif
RigidTransform< float, 3 > Pose3
Marker()
Definition: Marker.h:46
std::multimap< std::string, MarkerPtr > MarkerMap
A map of markers.
Definition: Marker.h:97
Pose3 pose
Definition: Marker.h:86
std::string id
Pose of the marker.
Definition: Marker.h:87
#define MIRA_THROW(ex, msg)
boost::shared_ptr< Marker > MarkerPtr
Marker pointer.
Definition: Marker.h:94
Base marker type.
Definition: Marker.h:42
void reflect(Reflector &r)
Definition: Marker.h:74
Time markerTimestamp
ID/content of the marker.
Definition: Marker.h:88
#define MIRA_OBJECT(classIdentifier)
Eigen::Matrix< typename Eigen::MatrixBase< Derived >::Scalar, 3, 1 > eulerAngles(const Eigen::MatrixBase< Derived > &mat, typename Eigen::MatrixBase< Derived >::Index a0, typename Eigen::MatrixBase< Derived >::Index a1, typename Eigen::MatrixBase< Derived >::Index a2)
static Time invalid()
Marker(const cv::Mat &Tvec, const cv::Mat &Rvec)
Construct a marker and initialize the pose of the marker by using.
Definition: Marker.h:50
typedef Mat
REFLECT_CTRLFLAG_MEMBER_AS_ROPROPERTY