00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <ucl_drone/opencv_utils.h>
00011
00013 cv::Mat rotationMatrixX(const double angle)
00014 {
00015 cv::Mat Rx = (cv::Mat_< double >(3, 3) << 1.0, 0.0, 0.0, 0.0, cos(angle), -sin(angle), 0.0,
00016 sin(angle), cos(angle));
00017 return Rx;
00018 }
00019
00021 cv::Mat rotationMatrixY(const double angle)
00022 {
00023 cv::Mat Ry = (cv::Mat_< double >(3, 3) << cos(angle), 0.0, sin(angle), 0.0, 1.0, 0.0, -sin(angle),
00024 0.0, cos(angle));
00025 return Ry;
00026 }
00027
00029 cv::Mat rotationMatrixZ(const double angle)
00030 {
00031 cv::Mat Rz = (cv::Mat_< double >(3, 3) << cos(angle), -sin(angle), 0.0, sin(angle), cos(angle),
00032 0.0, 0.0, 0.0, 1.0);
00033 return Rz;
00034 }
00035
00037 cv::Mat rollPitchYawToRotationMatrix(const double roll, const double pitch, const double yaw)
00038 {
00039 cv::Mat Rx = rotationMatrixX(roll);
00040 cv::Mat Ry = rotationMatrixY(pitch);
00041 cv::Mat Rz = rotationMatrixZ(yaw);
00042
00043 return Rz * Ry * Rx;
00044 }
00045
00047 cv::Mat rTMatrix(const cv::Mat rot, const double tx, const double ty, const double tz)
00048 {
00049 cv::Mat Rt = (cv::Mat_< double >(3, 4) << rot.at< double >(0, 0), rot.at< double >(0, 1),
00050 rot.at< double >(0, 2), tx, rot.at< double >(1, 0), rot.at< double >(1, 1),
00051 rot.at< double >(1, 2), ty, rot.at< double >(2, 0), rot.at< double >(2, 1),
00052 rot.at< double >(2, 2), tz);
00053 return Rt;
00054 }
00055
00056 void debugRTMatrix(cv::Mat Rt)
00057 {
00058 ROS_DEBUG("Rt = \n[ %f \t %f \t %f \t %f \n %f \t %f \t %f \t %f \n %f \t %f \t %f \t %f ]",
00059 Rt.at< double >(0, 0), Rt.at< double >(0, 1), Rt.at< double >(0, 2),
00060 Rt.at< double >(0, 3), Rt.at< double >(1, 0), Rt.at< double >(1, 1),
00061 Rt.at< double >(1, 2), Rt.at< double >(1, 3), Rt.at< double >(2, 0),
00062 Rt.at< double >(2, 1), Rt.at< double >(2, 2), Rt.at< double >(2, 3));
00063 }
00064
00066 std::vector< cv::Point2f > Points(const std::vector< cv::KeyPoint >& keypoints)
00067 {
00068 std::vector< cv::Point2f > result;
00069 for (unsigned i = 0; i < keypoints.size(); i++)
00070 {
00071 result.push_back(cv::Point2f(keypoints[i].pt.x, keypoints[i].pt.y));
00072 }
00073 return result;
00074 }