old/aruco/src/aruco/cvdrawingutils.cpp
Go to the documentation of this file.
1 /*****************************
2 Copyright 2011 Rafael Muñoz Salinas. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification, are
5 permitted provided that the following conditions are met:
6 
7  1. Redistributions of source code must retain the above copyright notice, this list of
8  conditions and the following disclaimer.
9 
10  2. Redistributions in binary form must reproduce the above copyright notice, this list
11  of conditions and the following disclaimer in the documentation and/or other materials
12  provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 The views and conclusions contained in the software and documentation are those of the
25 authors and should not be interpreted as representing official policies, either expressed
26 or implied, of Rafael Muñoz Salinas.
27 ********************************/
28 #include <aruco/cvdrawingutils.h>
29 using namespace cv;
30 namespace aruco {
31  /****
32  *
33  *
34  *
35  ****/
36  void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Marker &m,const CameraParameters &CP)
37  {
38 
39  float size=m.ssize*3;
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;
53 
54  vector<Point2f> imagePoints;
55  cv::projectPoints( objectPoints, m.Rvec,m.Tvec, CP.CameraMatrix,CP.Distorsion, imagePoints);
56  //draw lines of different colours
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);
63  }
64 
65  /****
66  *
67  *
68  *
69  ****/
70  void CvDrawingUtils::draw3dCube(cv::Mat &Image,Marker &m,const CameraParameters &CP)
71  {
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;
86 
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;
99 
100  vector<Point2f> imagePoints;
101  projectPoints( objectPoints, m.Rvec,m.Tvec, CP.CameraMatrix,CP.Distorsion, imagePoints);
102  //draw lines of different colours
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);
105 
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);
108 
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);
111 
112  }
113 
114 
115  /****
116  *
117  *
118  *
119  ****/
120  void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Board &B,const CameraParameters &CP)
121  {
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;
127 
128  vector<Point2f> imagePoints;
129  projectPoints( objectPoints, B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints);
130  //draw lines of different colours
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);
134 
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);
138  }
139 
140 
141  /****
142  *
143  *
144  *
145  ****/
146  void CvDrawingUtils::draw3dCube(cv::Mat &Image,Board &B,const CameraParameters &CP)
147  {
148 
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;
156 
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;
161 
162  vector<Point2f> imagePoints;
163  projectPoints( objectPoints,B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints);
164  //draw lines of different colours
165  for(int i=0;i<4;i++)
166  cv::line(Image,imagePoints[i],imagePoints[(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
167 
168  for(int i=0;i<4;i++)
169  cv::line(Image,imagePoints[i+4],imagePoints[4+(i+1)%4],Scalar(0,0,255,255),1,LINE_AA);
170 
171  for(int i=0;i<4;i++)
172  cv::line(Image,imagePoints[i],imagePoints[i+4],Scalar(0,0,255,255),1,LINE_AA);
173  }
174 
175 }


lidar_camera_calibration
Author(s):
autogenerated on Sat Feb 6 2021 03:39:37