29 #include <opencv2/highgui/highgui.hpp> 30 #include <opencv2/calib3d/calib3d.hpp> 31 #include <opencv2/imgproc/imgproc.hpp> 35 void CvDrawingUtils::draw3dAxis(cv::Mat &Image,
const CameraParameters &CP,
const cv::Mat &Rvec,
const cv::Mat &Tvec,
float axis_size ){
37 Mat objectPoints(4, 3, CV_32FC1);
38 objectPoints.at<
float >(0, 0) = 0;
39 objectPoints.at<
float >(0, 1) = 0;
40 objectPoints.at<
float >(0, 2) = 0;
41 objectPoints.at<
float >(1, 0) = axis_size;
42 objectPoints.at<
float >(1, 1) = 0;
43 objectPoints.at<
float >(1, 2) = 0;
44 objectPoints.at<
float >(2, 0) = 0;
45 objectPoints.at<
float >(2, 1) = axis_size;
46 objectPoints.at<
float >(2, 2) = 0;
47 objectPoints.at<
float >(3, 0) = 0;
48 objectPoints.at<
float >(3, 1) = 0;
49 objectPoints.at<
float >(3, 2) = axis_size;
51 vector< Point2f > imagePoints;
54 cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 1, CV_AA);
55 cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 1, CV_AA);
56 cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 1, CV_AA);
57 putText(Image,
"x", imagePoints[1], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 0, 255, 255), 2);
58 putText(Image,
"y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 255, 0, 255), 2);
59 putText(Image,
"z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255, 0, 0, 255), 2);
69 float size = m.
ssize * 3;
70 Mat objectPoints(4, 3, CV_32FC1);
71 objectPoints.at<
float >(0, 0) = 0;
72 objectPoints.at<
float >(0, 1) = 0;
73 objectPoints.at<
float >(0, 2) = 0;
74 objectPoints.at<
float >(1, 0) = size;
75 objectPoints.at<
float >(1, 1) = 0;
76 objectPoints.at<
float >(1, 2) = 0;
77 objectPoints.at<
float >(2, 0) = 0;
78 objectPoints.at<
float >(2, 1) = size;
79 objectPoints.at<
float >(2, 2) = 0;
80 objectPoints.at<
float >(3, 0) = 0;
81 objectPoints.at<
float >(3, 1) = 0;
82 objectPoints.at<
float >(3, 2) = size;
84 vector< Point2f > imagePoints;
87 cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 1, CV_AA);
88 cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 1, CV_AA);
89 cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 1, CV_AA);
90 putText(Image,
"x", imagePoints[1], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 0, 255, 255), 2);
91 putText(Image,
"y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 255, 0, 255), 2);
92 putText(Image,
"z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255, 0, 0, 255), 2);
101 Mat objectPoints(8, 3, CV_32FC1);
102 double halfSize = m.
ssize / 2;
105 if (setYperpendicular) {
106 objectPoints.at<
float >(0, 0) = -halfSize;
107 objectPoints.at<
float >(0, 1) = 0;
108 objectPoints.at<
float >(0, 2) = -halfSize;
109 objectPoints.at<
float >(1, 0) = halfSize;
110 objectPoints.at<
float >(1, 1) = 0;
111 objectPoints.at<
float >(1, 2) = -halfSize;
112 objectPoints.at<
float >(2, 0) = halfSize;
113 objectPoints.at<
float >(2, 1) = 0;
114 objectPoints.at<
float >(2, 2) = halfSize;
115 objectPoints.at<
float >(3, 0) = -halfSize;
116 objectPoints.at<
float >(3, 1) = 0;
117 objectPoints.at<
float >(3, 2) = halfSize;
119 objectPoints.at<
float >(4, 0) = -halfSize;
120 objectPoints.at<
float >(4, 1) = m.
ssize;
121 objectPoints.at<
float >(4, 2) = -halfSize;
122 objectPoints.at<
float >(5, 0) = halfSize;
123 objectPoints.at<
float >(5, 1) = m.
ssize;
124 objectPoints.at<
float >(5, 2) = -halfSize;
125 objectPoints.at<
float >(6, 0) = halfSize;
126 objectPoints.at<
float >(6, 1) = m.
ssize;
127 objectPoints.at<
float >(6, 2) = halfSize;
128 objectPoints.at<
float >(7, 0) = -halfSize;
129 objectPoints.at<
float >(7, 1) = m.
ssize;
130 objectPoints.at<
float >(7, 2) = halfSize;
132 objectPoints.at<
float >(0, 0) = -halfSize;
133 objectPoints.at<
float >(0, 1) = -halfSize;
134 objectPoints.at<
float >(0, 2) = 0;
135 objectPoints.at<
float >(1, 0) = halfSize;
136 objectPoints.at<
float >(1, 1) = -halfSize;
137 objectPoints.at<
float >(1, 2) = 0;
138 objectPoints.at<
float >(2, 0) = halfSize;
139 objectPoints.at<
float >(2, 1) = halfSize;
140 objectPoints.at<
float >(2, 2) = 0;
141 objectPoints.at<
float >(3, 0) = -halfSize;
142 objectPoints.at<
float >(3, 1) = halfSize;
143 objectPoints.at<
float >(3, 2) = 0;
145 objectPoints.at<
float >(4, 0) = -halfSize;
146 objectPoints.at<
float >(4, 1) = -halfSize;
147 objectPoints.at<
float >(4, 2) = m.
ssize;
148 objectPoints.at<
float >(5, 0) = halfSize;
149 objectPoints.at<
float >(5, 1) = -halfSize;
150 objectPoints.at<
float >(5, 2) = m.
ssize;
151 objectPoints.at<
float >(6, 0) = halfSize;
152 objectPoints.at<
float >(6, 1) = halfSize;
153 objectPoints.at<
float >(6, 2) = m.
ssize;
154 objectPoints.at<
float >(7, 0) = -halfSize;
155 objectPoints.at<
float >(7, 1) = halfSize;
156 objectPoints.at<
float >(7, 2) = m.
ssize;
159 vector< Point2f > imagePoints;
162 for (
int i = 0; i < 4; i++)
163 cv::line(Image, imagePoints[i], imagePoints[(i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
165 for (
int i = 0; i < 4; i++)
166 cv::line(Image, imagePoints[i + 4], imagePoints[4 + (i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
168 for (
int i = 0; i < 4; i++)
169 cv::line(Image, imagePoints[i], imagePoints[i + 4], Scalar(0, 0, 255, 255), 1, CV_AA);
This class represents a marker. It is a vector of the fours corners ot the marker.
Parameters of the camera.