28 #include <aruco/cvdrawingutils.h> 36 void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Marker &m,
const CameraParameters &CP)
40 Mat objectPoints (4,3,CV_32FC1);
41 objectPoints.at<
float>(0,0)=0;
42 objectPoints.at<
float>(0,1)=0;
43 objectPoints.at<
float>(0,2)=0;
44 objectPoints.at<
float>(1,0)=size;
45 objectPoints.at<
float>(1,1)=0;
46 objectPoints.at<
float>(1,2)=0;
47 objectPoints.at<
float>(2,0)=0;
48 objectPoints.at<
float>(2,1)=size;
49 objectPoints.at<
float>(2,2)=0;
50 objectPoints.at<
float>(3,0)=0;
51 objectPoints.at<
float>(3,1)=0;
52 objectPoints.at<
float>(3,2)=size;
54 vector<Point2f> imagePoints;
55 cv::projectPoints( objectPoints, m.Rvec,m.Tvec, CP.CameraMatrix,CP.Distorsion, imagePoints);
57 cv::line(Image,imagePoints[0],imagePoints[1],Scalar(255,0,0,255),1,LINE_AA);
58 cv::line(Image,imagePoints[0],imagePoints[2],Scalar(0,255,0,255),1,LINE_AA);
59 cv::line(Image,imagePoints[0],imagePoints[3],Scalar(0,0,255,255),1,LINE_AA);
60 putText(Image,
"x", imagePoints[1],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255,0,0,255),2);
61 putText(Image,
"y", imagePoints[2],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0,255,0,255),2);
62 putText(Image,
"z", imagePoints[3],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0,0,255,255),2);
70 void CvDrawingUtils::draw3dCube(cv::Mat &Image,Marker &m,
const CameraParameters &CP)
72 Mat objectPoints (8,3,CV_32FC1);
73 double halfSize=m.ssize/2;
74 objectPoints.at<
float>(0,0)=-halfSize;
75 objectPoints.at<
float>(0,1)=0;
76 objectPoints.at<
float>(0,2)=-halfSize;
77 objectPoints.at<
float>(1,0)=halfSize;
78 objectPoints.at<
float>(1,1)=0;
79 objectPoints.at<
float>(1,2)=-halfSize;
80 objectPoints.at<
float>(2,0)=halfSize;
81 objectPoints.at<
float>(2,1)=0;
82 objectPoints.at<
float>(2,2)=halfSize;
83 objectPoints.at<
float>(3,0)=-halfSize;
84 objectPoints.at<
float>(3,1)=0;
85 objectPoints.at<
float>(3,2)=halfSize;
87 objectPoints.at<
float>(4,0)=-halfSize;
88 objectPoints.at<
float>(4,1)=m.ssize;
89 objectPoints.at<
float>(4,2)=-halfSize;
90 objectPoints.at<
float>(5,0)=halfSize;
91 objectPoints.at<
float>(5,1)=m.ssize;
92 objectPoints.at<
float>(5,2)=-halfSize;
93 objectPoints.at<
float>(6,0)=halfSize;
94 objectPoints.at<
float>(6,1)=m.ssize;
95 objectPoints.at<
float>(6,2)=halfSize;
96 objectPoints.at<
float>(7,0)=-halfSize;
97 objectPoints.at<
float>(7,1)=m.ssize;
98 objectPoints.at<
float>(7,2)=halfSize;
100 vector<Point2f> imagePoints;
101 projectPoints( objectPoints, m.Rvec,m.Tvec, CP.CameraMatrix,CP.Distorsion, imagePoints);
103 for (
int i=0;i<4;i++)
104 cv::line(Image,imagePoints[i],imagePoints[(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
106 for (
int i=0;i<4;i++)
107 cv::line(Image,imagePoints[i+4],imagePoints[4+(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
109 for (
int i=0;i<4;i++)
110 cv::line(Image,imagePoints[i],imagePoints[i+4],Scalar(0,0,255,255),1,LINE_AA);
120 void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Board &B,
const CameraParameters &CP)
122 Mat objectPoints (4,3,CV_32FC1);
123 objectPoints.at<
float>(0,0)=0;objectPoints.at<
float>(0,1)=0;objectPoints.at<
float>(0,2)=0;
124 objectPoints.at<
float>(1,0)=2*B[0].ssize;objectPoints.at<
float>(1,1)=0;objectPoints.at<
float>(1,2)=0;
125 objectPoints.at<
float>(2,0)=0;objectPoints.at<
float>(2,1)=2*B[0].ssize;objectPoints.at<
float>(2,2)=0;
126 objectPoints.at<
float>(3,0)=0;objectPoints.at<
float>(3,1)=0;objectPoints.at<
float>(3,2)=2*B[0].ssize;
128 vector<Point2f> imagePoints;
129 projectPoints( objectPoints, B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints);
131 cv::line(Image,imagePoints[0],imagePoints[1],Scalar(0,0,255,255),2,LINE_AA);
132 cv::line(Image,imagePoints[0],imagePoints[2],Scalar(0,255,0,255),2,LINE_AA);
133 cv::line(Image,imagePoints[0],imagePoints[3],Scalar(255,0,0,255),2,LINE_AA);
135 putText(Image,
"X", imagePoints[1],FONT_HERSHEY_SIMPLEX, 1, Scalar(0,0,255,255),2);
136 putText(Image,
"Y", imagePoints[2],FONT_HERSHEY_SIMPLEX, 1, Scalar(0,255,0,255),2);
137 putText(Image,
"Z", imagePoints[3],FONT_HERSHEY_SIMPLEX, 1, Scalar(255,0,0,255),2);
146 void CvDrawingUtils::draw3dCube(cv::Mat &Image,Board &B,
const CameraParameters &CP)
149 float cubeSize=B[0].ssize;
150 float txz=-cubeSize/2;
151 Mat objectPoints (8,3,CV_32FC1);
152 objectPoints.at<
float>(0,0)=txz;objectPoints.at<
float>(0,1)=0;objectPoints.at<
float>(0,2)=txz;
153 objectPoints.at<
float>(1,0)=txz+cubeSize;objectPoints.at<
float>(1,1)=0;objectPoints.at<
float>(1,2)=txz;
154 objectPoints.at<
float>(2,0)=txz+cubeSize;objectPoints.at<
float>(2,1)=cubeSize;objectPoints.at<
float>(2,2)=txz;
155 objectPoints.at<
float>(3,0)=txz;objectPoints.at<
float>(3,1)=cubeSize;objectPoints.at<
float>(3,2)=txz;
157 objectPoints.at<
float>(4,0)=txz;objectPoints.at<
float>(4,1)=0;objectPoints.at<
float>(4,2)=txz+cubeSize;
158 objectPoints.at<
float>(5,0)=txz+cubeSize;objectPoints.at<
float>(5,1)=0;objectPoints.at<
float>(5,2)=txz+cubeSize;
159 objectPoints.at<
float>(6,0)=txz+cubeSize;objectPoints.at<
float>(6,1)=cubeSize;objectPoints.at<
float>(6,2)=txz+cubeSize;
160 objectPoints.at<
float>(7,0)=txz;objectPoints.at<
float>(7,1)=cubeSize;objectPoints.at<
float>(7,2)=txz+cubeSize;
162 vector<Point2f> imagePoints;
163 projectPoints( objectPoints,B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints);
166 cv::line(Image,imagePoints[i],imagePoints[(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
169 cv::line(Image,imagePoints[i+4],imagePoints[4+(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
172 cv::line(Image,imagePoints[i],imagePoints[i+4],Scalar(0,0,255,255),1,LINE_AA);