29 #include <opencv2/highgui/highgui.hpp> 30 #include <opencv2/calib3d/calib3d.hpp> 31 #include <opencv2/imgproc/imgproc.hpp> 42 float size = m.
ssize * 3;
43 Mat objectPoints(4, 3, CV_32FC1);
44 objectPoints.at<
float >(0, 0) = 0;
45 objectPoints.at<
float >(0, 1) = 0;
46 objectPoints.at<
float >(0, 2) = 0;
47 objectPoints.at<
float >(1, 0) = size;
48 objectPoints.at<
float >(1, 1) = 0;
49 objectPoints.at<
float >(1, 2) = 0;
50 objectPoints.at<
float >(2, 0) = 0;
51 objectPoints.at<
float >(2, 1) = size;
52 objectPoints.at<
float >(2, 2) = 0;
53 objectPoints.at<
float >(3, 0) = 0;
54 objectPoints.at<
float >(3, 1) = 0;
55 objectPoints.at<
float >(3, 2) = size;
57 vector< Point2f > imagePoints;
60 cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 1, CV_AA);
61 cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 1, CV_AA);
62 cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 1, CV_AA);
63 putText(Image,
"x", imagePoints[1], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 0, 255, 255), 2);
64 putText(Image,
"y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 255, 0, 255), 2);
65 putText(Image,
"z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255, 0, 0, 255), 2);
74 Mat objectPoints(8, 3, CV_32FC1);
75 double halfSize = m.
ssize / 2;
77 if (setYperpendicular) {
78 objectPoints.at<
float >(0, 0) = -halfSize;
79 objectPoints.at<
float >(0, 1) = 0;
80 objectPoints.at<
float >(0, 2) = -halfSize;
81 objectPoints.at<
float >(1, 0) = halfSize;
82 objectPoints.at<
float >(1, 1) = 0;
83 objectPoints.at<
float >(1, 2) = -halfSize;
84 objectPoints.at<
float >(2, 0) = halfSize;
85 objectPoints.at<
float >(2, 1) = 0;
86 objectPoints.at<
float >(2, 2) = halfSize;
87 objectPoints.at<
float >(3, 0) = -halfSize;
88 objectPoints.at<
float >(3, 1) = 0;
89 objectPoints.at<
float >(3, 2) = halfSize;
91 objectPoints.at<
float >(4, 0) = -halfSize;
92 objectPoints.at<
float >(4, 1) = m.
ssize;
93 objectPoints.at<
float >(4, 2) = -halfSize;
94 objectPoints.at<
float >(5, 0) = halfSize;
95 objectPoints.at<
float >(5, 1) = m.
ssize;
96 objectPoints.at<
float >(5, 2) = -halfSize;
97 objectPoints.at<
float >(6, 0) = halfSize;
98 objectPoints.at<
float >(6, 1) = m.
ssize;
99 objectPoints.at<
float >(6, 2) = halfSize;
100 objectPoints.at<
float >(7, 0) = -halfSize;
101 objectPoints.at<
float >(7, 1) = m.
ssize;
102 objectPoints.at<
float >(7, 2) = halfSize;
104 objectPoints.at<
float >(0, 0) = -halfSize;
105 objectPoints.at<
float >(0, 1) = -halfSize;
106 objectPoints.at<
float >(0, 2) = 0;
107 objectPoints.at<
float >(1, 0) = halfSize;
108 objectPoints.at<
float >(1, 1) = -halfSize;
109 objectPoints.at<
float >(1, 2) = 0;
110 objectPoints.at<
float >(2, 0) = halfSize;
111 objectPoints.at<
float >(2, 1) = halfSize;
112 objectPoints.at<
float >(2, 2) = 0;
113 objectPoints.at<
float >(3, 0) = -halfSize;
114 objectPoints.at<
float >(3, 1) = halfSize;
115 objectPoints.at<
float >(3, 2) = 0;
117 objectPoints.at<
float >(4, 0) = -halfSize;
118 objectPoints.at<
float >(4, 1) = -halfSize;
119 objectPoints.at<
float >(4, 2) = m.
ssize;
120 objectPoints.at<
float >(5, 0) = halfSize;
121 objectPoints.at<
float >(5, 1) = -halfSize;
122 objectPoints.at<
float >(5, 2) = m.
ssize;
123 objectPoints.at<
float >(6, 0) = halfSize;
124 objectPoints.at<
float >(6, 1) = halfSize;
125 objectPoints.at<
float >(6, 2) = m.
ssize;
126 objectPoints.at<
float >(7, 0) = -halfSize;
127 objectPoints.at<
float >(7, 1) = halfSize;
128 objectPoints.at<
float >(7, 2) = m.
ssize;
131 vector< Point2f > imagePoints;
134 for (
int i = 0; i < 4; i++)
135 cv::line(Image, imagePoints[i], imagePoints[(i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
137 for (
int i = 0; i < 4; i++)
138 cv::line(Image, imagePoints[i + 4], imagePoints[4 + (i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
140 for (
int i = 0; i < 4; i++)
141 cv::line(Image, imagePoints[i], imagePoints[i + 4], Scalar(0, 0, 255, 255), 1, CV_AA);
151 Mat objectPoints(4, 3, CV_32FC1);
152 objectPoints.at<
float >(0, 0) = 0;
153 objectPoints.at<
float >(0, 1) = 0;
154 objectPoints.at<
float >(0, 2) = 0;
155 objectPoints.at<
float >(1, 0) = 2 * B[0].ssize;
156 objectPoints.at<
float >(1, 1) = 0;
157 objectPoints.at<
float >(1, 2) = 0;
158 objectPoints.at<
float >(2, 0) = 0;
159 objectPoints.at<
float >(2, 1) = 2 * B[0].ssize;
160 objectPoints.at<
float >(2, 2) = 0;
161 objectPoints.at<
float >(3, 0) = 0;
162 objectPoints.at<
float >(3, 1) = 0;
163 objectPoints.at<
float >(3, 2) = 2 * B[0].ssize;
165 vector< Point2f > imagePoints;
168 cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 2, CV_AA);
169 cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 2, CV_AA);
170 cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 2, CV_AA);
172 putText(Image,
"X", imagePoints[1], FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 0, 255, 255), 2);
173 putText(Image,
"Y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 255, 0, 255), 2);
174 putText(Image,
"Z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 1, Scalar(255, 0, 0, 255), 2);
185 float cubeSize = B[0].ssize;
186 float txz = -cubeSize / 2;
187 Mat objectPoints(8, 3, CV_32FC1);
189 if (setYperpendicular) {
190 objectPoints.at<
float >(0, 0) = txz;
191 objectPoints.at<
float >(0, 1) = 0;
192 objectPoints.at<
float >(0, 2) = txz;
193 objectPoints.at<
float >(1, 0) = txz + cubeSize;
194 objectPoints.at<
float >(1, 1) = 0;
195 objectPoints.at<
float >(1, 2) = txz;
196 objectPoints.at<
float >(2, 0) = txz + cubeSize;
197 objectPoints.at<
float >(2, 1) = cubeSize;
198 objectPoints.at<
float >(2, 2) = txz;
199 objectPoints.at<
float >(3, 0) = txz;
200 objectPoints.at<
float >(3, 1) = cubeSize;
201 objectPoints.at<
float >(3, 2) = txz;
203 objectPoints.at<
float >(4, 0) = txz;
204 objectPoints.at<
float >(4, 1) = 0;
205 objectPoints.at<
float >(4, 2) = txz + cubeSize;
206 objectPoints.at<
float >(5, 0) = txz + cubeSize;
207 objectPoints.at<
float >(5, 1) = 0;
208 objectPoints.at<
float >(5, 2) = txz + cubeSize;
209 objectPoints.at<
float >(6, 0) = txz + cubeSize;
210 objectPoints.at<
float >(6, 1) = cubeSize;
211 objectPoints.at<
float >(6, 2) = txz + cubeSize;
212 objectPoints.at<
float >(7, 0) = txz;
213 objectPoints.at<
float >(7, 1) = cubeSize;
214 objectPoints.at<
float >(7, 2) = txz + cubeSize;
216 objectPoints.at<
float >(0, 0) = txz;
217 objectPoints.at<
float >(0, 2) = 0;
218 objectPoints.at<
float >(0, 1) = txz;
219 objectPoints.at<
float >(1, 0) = txz + cubeSize;
220 objectPoints.at<
float >(1, 2) = 0;
221 objectPoints.at<
float >(1, 1) = txz;
222 objectPoints.at<
float >(2, 0) = txz + cubeSize;
223 objectPoints.at<
float >(2, 2) = -cubeSize;
224 objectPoints.at<
float >(2, 1) = txz;
225 objectPoints.at<
float >(3, 0) = txz;
226 objectPoints.at<
float >(3, 2) = -cubeSize;
227 objectPoints.at<
float >(3, 1) = txz;
229 objectPoints.at<
float >(4, 0) = txz;
230 objectPoints.at<
float >(4, 2) = 0;
231 objectPoints.at<
float >(4, 1) = txz + cubeSize;
232 objectPoints.at<
float >(5, 0) = txz + cubeSize;
233 objectPoints.at<
float >(5, 2) = 0;
234 objectPoints.at<
float >(5, 1) = txz + cubeSize;
235 objectPoints.at<
float >(6, 0) = txz + cubeSize;
236 objectPoints.at<
float >(6, 2) = -cubeSize;
237 objectPoints.at<
float >(6, 1) = txz + cubeSize;
238 objectPoints.at<
float >(7, 0) = txz;
239 objectPoints.at<
float >(7, 2) = -cubeSize;
240 objectPoints.at<
float >(7, 1) = txz + cubeSize;
243 vector< Point2f > imagePoints;
246 for (
int i = 0; i < 4; i++)
247 cv::line(Image, imagePoints[i], imagePoints[(i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
249 for (
int i = 0; i < 4; i++)
250 cv::line(Image, imagePoints[i + 4], imagePoints[4 + (i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA);
252 for (
int i = 0; i < 4; i++)
253 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.