cvdrawingutils.cpp
Go to the documentation of this file.
00001 /*****************************
00002 Copyright 2011 Rafael Muñoz Salinas. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without modification, are
00005 permitted provided that the following conditions are met:
00006 
00007    1. Redistributions of source code must retain the above copyright notice, this list of
00008       conditions and the following disclaimer.
00009 
00010    2. Redistributions in binary form must reproduce the above copyright notice, this list
00011       of conditions and the following disclaimer in the documentation and/or other materials
00012       provided with the distribution.
00013 
00014 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
00015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00016 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
00017 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00018 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00019 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00020 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00021 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00022 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023 
00024 The views and conclusions contained in the software and documentation are those of the
00025 authors and should not be interpreted as representing official policies, either expressed
00026 or implied, of Rafael Muñoz Salinas.
00027 ********************************/
00028 #include <aruco/cvdrawingutils.h>
00029 using namespace cv;
00030 namespace aruco {
00031     /****
00032  *
00033  *
00034  *
00035  ****/
00036     void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Marker &m,const CameraParameters &CP)
00037     {
00038 
00039         float size=m.ssize*3;
00040         Mat objectPoints (4,3,CV_32FC1);
00041         objectPoints.at<float>(0,0)=0;
00042         objectPoints.at<float>(0,1)=0;
00043         objectPoints.at<float>(0,2)=0;
00044         objectPoints.at<float>(1,0)=size;
00045         objectPoints.at<float>(1,1)=0;
00046         objectPoints.at<float>(1,2)=0;
00047         objectPoints.at<float>(2,0)=0;
00048         objectPoints.at<float>(2,1)=size;
00049         objectPoints.at<float>(2,2)=0;
00050         objectPoints.at<float>(3,0)=0;
00051         objectPoints.at<float>(3,1)=0;
00052         objectPoints.at<float>(3,2)=size;
00053 
00054         vector<Point2f> imagePoints;
00055         cv::projectPoints( objectPoints, m.Rvec,m.Tvec, CP.CameraMatrix,CP.Distorsion,   imagePoints);
00056         //draw lines of different colours
00057         cv::line(Image,imagePoints[0],imagePoints[1],Scalar(255,0,0,255),1,CV_AA);
00058         cv::line(Image,imagePoints[0],imagePoints[2],Scalar(0,255,0,255),1,CV_AA);
00059         cv::line(Image,imagePoints[0],imagePoints[3],Scalar(0,0,255,255),1,CV_AA);
00060         putText(Image,"x", imagePoints[1],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255,0,0,255),2);
00061         putText(Image,"y", imagePoints[2],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0,255,0,255),2);
00062         putText(Image,"z", imagePoints[3],FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0,0,255,255),2);
00063     }
00064 
00065     /****
00066  *
00067  *
00068  *
00069  ****/
00070     void CvDrawingUtils::draw3dCube(cv::Mat &Image,Marker &m,const CameraParameters &CP)
00071     {
00072         Mat objectPoints (8,3,CV_32FC1);
00073         double halfSize=m.ssize/2;
00074         objectPoints.at<float>(0,0)=-halfSize;
00075         objectPoints.at<float>(0,1)=0;
00076         objectPoints.at<float>(0,2)=-halfSize;
00077         objectPoints.at<float>(1,0)=halfSize;
00078         objectPoints.at<float>(1,1)=0;
00079         objectPoints.at<float>(1,2)=-halfSize;
00080         objectPoints.at<float>(2,0)=halfSize;
00081         objectPoints.at<float>(2,1)=0;
00082         objectPoints.at<float>(2,2)=halfSize;
00083         objectPoints.at<float>(3,0)=-halfSize;
00084         objectPoints.at<float>(3,1)=0;
00085         objectPoints.at<float>(3,2)=halfSize;
00086 
00087         objectPoints.at<float>(4,0)=-halfSize;
00088         objectPoints.at<float>(4,1)=m.ssize;
00089         objectPoints.at<float>(4,2)=-halfSize;
00090         objectPoints.at<float>(5,0)=halfSize;
00091         objectPoints.at<float>(5,1)=m.ssize;
00092         objectPoints.at<float>(5,2)=-halfSize;
00093         objectPoints.at<float>(6,0)=halfSize;
00094         objectPoints.at<float>(6,1)=m.ssize;
00095         objectPoints.at<float>(6,2)=halfSize;
00096         objectPoints.at<float>(7,0)=-halfSize;
00097         objectPoints.at<float>(7,1)=m.ssize;
00098         objectPoints.at<float>(7,2)=halfSize;
00099 
00100         vector<Point2f> imagePoints;
00101         projectPoints( objectPoints, m.Rvec,m.Tvec,  CP.CameraMatrix,CP.Distorsion,   imagePoints);
00102         //draw lines of different colours
00103         for (int i=0;i<4;i++)
00104             cv::line(Image,imagePoints[i],imagePoints[(i+1)%4],Scalar(0,0,255,255),1,CV_AA);
00105 
00106         for (int i=0;i<4;i++)
00107             cv::line(Image,imagePoints[i+4],imagePoints[4+(i+1)%4],Scalar(0,0,255,255),1,CV_AA);
00108 
00109         for (int i=0;i<4;i++)
00110             cv::line(Image,imagePoints[i],imagePoints[i+4],Scalar(0,0,255,255),1,CV_AA);
00111 
00112     }
00113 
00114 
00115     /****
00116  *
00117  *
00118  *
00119  ****/
00120     void CvDrawingUtils::draw3dAxis(cv::Mat &Image,Board &B,const CameraParameters &CP)
00121     {
00122         Mat objectPoints (4,3,CV_32FC1);
00123         objectPoints.at<float>(0,0)=0;objectPoints.at<float>(0,1)=0;objectPoints.at<float>(0,2)=0;
00124         objectPoints.at<float>(1,0)=2*B[0].ssize;objectPoints.at<float>(1,1)=0;objectPoints.at<float>(1,2)=0;
00125         objectPoints.at<float>(2,0)=0;objectPoints.at<float>(2,1)=2*B[0].ssize;objectPoints.at<float>(2,2)=0;
00126         objectPoints.at<float>(3,0)=0;objectPoints.at<float>(3,1)=0;objectPoints.at<float>(3,2)=2*B[0].ssize;
00127 
00128         vector<Point2f> imagePoints;
00129         projectPoints( objectPoints, B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion,   imagePoints);
00130         //draw lines of different colours
00131         cv::line(Image,imagePoints[0],imagePoints[1],Scalar(0,0,255,255),2,CV_AA);
00132         cv::line(Image,imagePoints[0],imagePoints[2],Scalar(0,255,0,255),2,CV_AA);
00133         cv::line(Image,imagePoints[0],imagePoints[3],Scalar(255,0,0,255),2,CV_AA);
00134 
00135         putText(Image,"X", imagePoints[1],FONT_HERSHEY_SIMPLEX, 1, Scalar(0,0,255,255),2);
00136         putText(Image,"Y", imagePoints[2],FONT_HERSHEY_SIMPLEX, 1, Scalar(0,255,0,255),2);
00137         putText(Image,"Z", imagePoints[3],FONT_HERSHEY_SIMPLEX, 1, Scalar(255,0,0,255),2);
00138     }
00139 
00140 
00141     /****
00142  *
00143  *
00144  *
00145  ****/
00146     void CvDrawingUtils::draw3dCube(cv::Mat &Image,Board &B,const CameraParameters &CP)
00147     {
00148 
00149         float cubeSize=B[0].ssize;
00150         float txz=-cubeSize/2;
00151         Mat objectPoints (8,3,CV_32FC1);
00152         objectPoints.at<float>(0,0)=txz;objectPoints.at<float>(0,1)=0;objectPoints.at<float>(0,2)=txz;
00153         objectPoints.at<float>(1,0)=txz+cubeSize;objectPoints.at<float>(1,1)=0;objectPoints.at<float>(1,2)=txz;
00154         objectPoints.at<float>(2,0)=txz+cubeSize;objectPoints.at<float>(2,1)=cubeSize;objectPoints.at<float>(2,2)=txz;
00155         objectPoints.at<float>(3,0)=txz;objectPoints.at<float>(3,1)=cubeSize;objectPoints.at<float>(3,2)=txz;
00156 
00157         objectPoints.at<float>(4,0)=txz;objectPoints.at<float>(4,1)=0;objectPoints.at<float>(4,2)=txz+cubeSize;
00158         objectPoints.at<float>(5,0)=txz+cubeSize;objectPoints.at<float>(5,1)=0;objectPoints.at<float>(5,2)=txz+cubeSize;
00159         objectPoints.at<float>(6,0)=txz+cubeSize;objectPoints.at<float>(6,1)=cubeSize;objectPoints.at<float>(6,2)=txz+cubeSize;
00160         objectPoints.at<float>(7,0)=txz;objectPoints.at<float>(7,1)=cubeSize;objectPoints.at<float>(7,2)=txz+cubeSize;
00161 
00162         vector<Point2f> imagePoints;
00163         projectPoints( objectPoints,B.Rvec,B.Tvec, CP.CameraMatrix, CP.Distorsion,   imagePoints);
00164         //draw lines of different colours
00165         for(int i=0;i<4;i++)
00166             cv::line(Image,imagePoints[i],imagePoints[(i+1)%4],Scalar(0,0,255,255),1,CV_AA);
00167 
00168         for(int i=0;i<4;i++)
00169             cv::line(Image,imagePoints[i+4],imagePoints[4+(i+1)%4],Scalar(0,0,255,255),1,CV_AA);
00170 
00171         for(int i=0;i<4;i++)
00172             cv::line(Image,imagePoints[i],imagePoints[i+4],Scalar(0,0,255,255),1,CV_AA);
00173     }
00174 
00175 }


aruco
Author(s): Rafael Muñoz Salinas , Bence Magyar
autogenerated on Thu Jun 6 2019 17:52:15