Utilities
Utilities header only library
ExtCv.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_EXT_CV_H
7 #define UTILS_EXT_CV_H
8 #include <opencv2/opencv.hpp>
9 #include <COGS/Color.h>
10 
11 
12 
14 namespace cv_ext
15 {
16 
17  inline glm::vec3 ToVec3(const cv::Point3f &vec)
18  {
19  return glm::vec3(vec.x, vec.y, vec.z);
20  }
21 
22  inline glm::vec3 ToVec3(const cv::Vec3f &vec)
23  {
24  return glm::vec3(vec[0], vec[1], vec[2]);
25  }
26 
27  inline cv::Point3f ToCvPoint3f(const glm::vec3 &vec)
28  {
29  return cv::Point3f(vec.x, vec.y, vec.z);
30  }
31 
32  inline cv::Point2f ToCvPoint2f(const glm::vec2 &vec)
33  {
34  return cv::Point2f(vec.x, vec.y);
35  }
36 
37  inline cv::Vec3f ToCvVec3f(const glm::vec3 &vec)
38  {
39  return cv::Vec3f(vec.x, vec.y, vec.z);
40  }
41 
42  inline cv::Vec2f ToCvVec2f(const glm::vec2 &vec)
43  {
44  return cv::Vec2f(vec.x, vec.y);
45  }
46 
47  inline cv::Point3f ToCvPoint3f(const cogs::Color3f &color)
48  {
49  return cv::Point3f(color.r, color.g, color.b);
50  }
51 
52  inline glm::mat3 ToMat3(const cv::Matx33d &mat)
53  {
54  glm::mat3 result(1.0f);
55  for (size_t i = 0; i < 3; ++i)
56  {
57  for (size_t j = 0; j < 3; ++j)
58  {
59  result[i][j] = static_cast<float>(mat(i, j));
60  }
61  }
62  return result;
63  }
64 
65  inline glm::mat4 ToMat4(const cv::Matx33d &mat)
66  {
67  glm::mat4 result(1.0f);
68  for (size_t i = 0; i < 3; ++i)
69  {
70  for (size_t j = 0; j < 3; ++j)
71  {
72  result[i][j] = static_cast<float>(mat(i, j));
73  }
74  }
75  return result;
76  }
77 
78 }
79 
80 #endif /* !UTILS_EXT_CV_H */
Extensions to the OpenCV library.
Definition: ExtCv.h:14