pose_estimation_base.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "pose_estimation_base.h"
33 
34 #include "ros/ros.h"
35 
38 }
39 
41 
42 static cv::Mat getRTMatrix(const cv::Mat &_rvec, const cv::Mat &_tvec) {
43  if (_rvec.empty())
44  return cv::Mat();
45  cv::Mat m = cv::Mat::eye(4, 4, CV_32FC1);
46  cv::Mat R33 = cv::Mat(m, cv::Rect(0, 0, 3, 3));
47  cv::Rodrigues(_rvec, R33);
48  for (int i = 0; i < 3; i++)
49  m.at<float>(i, 3) = _tvec.ptr<float>(0)[i];
50  return m;
51 }
52 
53 void PoseEstimationBase::estimatePose(std::vector<MarkerFiducials> &markers,
54  cv::Mat &camera_k, cv::Mat &camera_d,
55  std::vector<MarkerPose> &markerPoses) {
56  for (auto &marker:markers) {
57  // Currently we only support the default opencv pose estimation so the parameter PoseEstimatorType is not used.
58  // If you want to add additional methods than start to differentiate them here.
59  {
60  cv::Mat rv, tv;
61  cv::solvePnP(marker.object_points, marker.image_points, camera_k, camera_d, rv, tv);
62 
63  cv::Mat rvec, tvec;
64  rv.convertTo(rvec, CV_32F);
65  tv.convertTo(tvec, CV_32F);
66 
67  MarkerPose pose(marker.ids, marker.ids_confidence);
68  pose.rt_matrix = getRTMatrix(rvec, tvec);
69 
70  if (!pose.rt_matrix.empty())
71  markerPoses.push_back(pose);
72  }
73 
74  }
75 }
76 
78  return params_;
79 }
80 
82 
83 }
cv::Mat rt_matrix
Definition: marker_pose.h:44
PoseEstimationParameters & getParameters()
PoseEstimationParameters params_
void estimatePose(std::vector< MarkerFiducials > &markers, cv::Mat &camera_k, cv::Mat &camera_d, std::vector< MarkerPose > &markerPoses)
static cv::Mat getRTMatrix(const cv::Mat &_rvec, const cv::Mat &_tvec)


tuw_marker_pose_estimation
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:42:13