From f4754d23984126de847279f4abad4ae713d9e386 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 5 Oct 2014 19:55:05 +0200 Subject: flush and push --- ftnoir_tracker_aruco/include/aruco.h | 29 ++--- ftnoir_tracker_aruco/include/arucofidmarkers.h | 15 +-- ftnoir_tracker_aruco/include/board.h | 168 +++++++++++++++++++++++++ ftnoir_tracker_aruco/include/boarddetector.h | 139 ++++++++++++++++++++ ftnoir_tracker_aruco/include/cvdrawingutils.h | 21 ++-- ftnoir_tracker_aruco/include/exports.h | 4 +- ftnoir_tracker_aruco/include/markerdetector.h | 16 +-- 7 files changed, 355 insertions(+), 37 deletions(-) create mode 100644 ftnoir_tracker_aruco/include/board.h create mode 100644 ftnoir_tracker_aruco/include/boarddetector.h (limited to 'ftnoir_tracker_aruco/include') diff --git a/ftnoir_tracker_aruco/include/aruco.h b/ftnoir_tracker_aruco/include/aruco.h index 8ea583a8..569b95fb 100644 --- a/ftnoir_tracker_aruco/include/aruco.h +++ b/ftnoir_tracker_aruco/include/aruco.h @@ -26,12 +26,12 @@ The views and conclusions contained in the software and documentation are those authors and should not be interpreted as representing official policies, either expressed or implied, of Rafael Muñoz Salinas. - - + + \mainpage ArUco: Augmented Reality library from the University of Cordoba -ArUco is a minimal C++ library for detection of Augmented Reality markers based on OpenCv exclusively. +ArUco is a minimal C++ library for detection of Augmented Reality markers based on OpenCv exclusively. It is an educational project to show student how to detect augmented reality markers and it is provided under BSD license. @@ -54,11 +54,11 @@ Aruco allows the possibility to employ board. Boards are markers composed by an The library comes with five applications that will help you to learn how to use the library: - aruco_create_marker: which creates marker and saves it in a jpg file you can print. - - aruco_simple : simple test aplication that detects the markers in a image + - aruco_simple : simple test aplication that detects the markers in a image - aruco_test: this is the main application for detection. It reads images either from the camera of from a video and detect markers. Additionally, if you provide the intrinsics of the camera(obtained by OpenCv calibration) and the size of the marker in meters, the library calculates the marker intrinsics so that you can easily create your AR applications. - aruco_test_gl: shows how to use the library AR applications using OpenGL for rendering - aruco_create_board: application that helps you to create a board - - aruco_simple_board: simple test aplication that detects a board of markers in a image + - aruco_simple_board: simple test aplication that detects a board of markers in a image - aruco_test_board: application that detects boards - aruco_test_board_gl: application that detects boards and uses OpenGL to draw @@ -66,7 +66,7 @@ The library comes with five applications that will help you to learn how to use The ArUco library contents are divided in two main directories. The src directory, which contains the library itself. And the utils directory which contains the applications. -The library main classes are: +The library main classes are: - aruco::CameraParameters: represent the information of the camera that captures the images. Here you must set the calibration info. - aruco::Marker: which represent a marker detected in the image - aruco::MarkerDetector: that is in charge of deteting the markers in a image Detection is done by simple calling the member funcion ArMarkerDetector::detect(). Additionally, the classes contain members to create the required matrices for rendering using OpenGL. See aruco_test_gl for details @@ -101,33 +101,34 @@ The library has been compiled using MinGW and codeblocks. Below I describe the b -# Download the source code and compile it using cmake and codeblocks. Note: install the library in C:\ if you want it to be easily detected by cmake afterwards - step 4) aruco -# Download and decompress. - -# Open cmake gui application and set the path to the main library directory and also set a path where the project is going to be built. + -# Open cmake gui application and set the path to the main library directory and also set a path where the project is going to be built. -# Generate the codeblock project. -# Open the project with codeblock and compile then, install. The programs will be probably generated into the bin directory OpenGL: by default, the mingw version installed has not the glut library. So, the opengl programs are not compiled. If you want to compile with OpenGL support, you must install glut, or prefereably freeglut. -Thus, - - Download the library (http://www.martinpayne.me.uk/software/development/GLUT/freeglut-MinGW.zip) for mingw. - - Decompress in a directory X. +Thus, + - Download the library (http://www.martinpayne.me.uk/software/development/GLUT/freeglut-MinGW.zip) for mingw. + - Decompress in a directory X. - Then, rerun cmake setting the variable GLU_PATH to that directory (>cmake .. -DGLUT_PATH="C:\X") - Finally, recompile and test. Indeed, you should move the freeglut.dll to the directory with the binaries or to any other place in the PATH. CONCLUSION: Move to Linux, things are simpler :P - -\section Testing + +\section Testing For testing the applications, the library provides videos and the corresponding camera parameters of these videos. Into the directories you will find information on how to run the examples. - + \section Final Notes - REQUIREMENTS: OpenCv >= 2.1.0. and OpenGL for (aruco_test_gl and aruco_test_board_gl) - CONTACT: Rafael Munoz-Salinas: rmsalinas@uco.es - This libary is free software and come with no guaratee! - + */ #include "markerdetector.h" +#include "boarddetector.h" #include "cvdrawingutils.h" diff --git a/ftnoir_tracker_aruco/include/arucofidmarkers.h b/ftnoir_tracker_aruco/include/arucofidmarkers.h index 15eb8e4c..7dad4672 100644 --- a/ftnoir_tracker_aruco/include/arucofidmarkers.h +++ b/ftnoir_tracker_aruco/include/arucofidmarkers.h @@ -31,6 +31,7 @@ or implied, of Rafael Muñoz Salinas. #include #include "exports.h" #include "marker.h" +#include "board.h" namespace aruco { class ARUCO_EXPORTS FiducidalMarkers { @@ -79,7 +80,7 @@ public: * @param gridSize grid layout (numer of sqaures in x and Y) * @param MarkerSize size of markers sides in pixels * @param MarkerDistance distance between the markers - * @param TInfo output + * @param TInfo output * @param excludedIds set of ids excluded from the board */ static cv::Mat createBoardImage( cv::Size gridSize,int MarkerSize,int MarkerDistance, BoardConfiguration& TInfo ,vector *excludedIds=NULL ) throw (cv::Exception); @@ -88,24 +89,24 @@ public: /**Creates a printable image of a board in chessboard_like manner * @param gridSize grid layout (numer of sqaures in x and Y) * @param MarkerSize size of markers sides in pixels - * @param TInfo output + * @param TInfo output * @param setDataCentered indicates if the center is set at the center of the board. Otherwise it is the left-upper corner - * + * */ static cv::Mat createBoardImage_ChessBoard( cv::Size gridSize,int MarkerSize, BoardConfiguration& TInfo ,bool setDataCentered=true ,vector *excludedIds=NULL) throw (cv::Exception); - /**Creates a printable image of a board in a frame fashion + /**Creates a printable image of a board in a frame fashion * @param gridSize grid layout (numer of sqaures in x and Y) * @param MarkerSize size of markers sides in pixels * @param MarkerDistance distance between the markers - * @param TInfo output + * @param TInfo output * @param setDataCentered indicates if the center is set at the center of the board. Otherwise it is the left-upper corner - * + * */ static cv::Mat createBoardImage_Frame( cv::Size gridSize,int MarkerSize,int MarkerDistance, BoardConfiguration& TInfo ,bool setDataCentered=true,vector *excludedIds=NULL ) throw (cv::Exception); private: - + static vector getListOfValidMarkersIds_random(int nMarkers,vector *excluded) throw (cv::Exception); static cv::Mat rotate(const cv::Mat & in); static int hammDistMarker(cv::Mat bits); diff --git a/ftnoir_tracker_aruco/include/board.h b/ftnoir_tracker_aruco/include/board.h new file mode 100644 index 00000000..c1d79292 --- /dev/null +++ b/ftnoir_tracker_aruco/include/board.h @@ -0,0 +1,168 @@ +/***************************** +Copyright 2011 Rafael Muñoz Salinas. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those of the +authors and should not be interpreted as representing official policies, either expressed +or implied, of Rafael Muñoz Salinas. +********************************/ +#ifndef _Aruco_board_h +#define _Aruco_board_h +#include +#include +#include +#include "exports.h" +#include "marker.h" +using namespace std; +namespace aruco { +/** + * 3d representation of a marker + */ +struct ARUCO_EXPORTS MarkerInfo:public vector { + MarkerInfo() {} + MarkerInfo(int _id) {id=_id; } + MarkerInfo(const MarkerInfo&MI): vector(MI){id=MI.id; } + MarkerInfo & operator=(const MarkerInfo&MI){ + vector ::operator=(MI); + id=MI.id; + return *this; + } + int id;//maker id +}; + +/**\brief This class defines a board with several markers. + * A Board contains several markers so that they are more robustly detected. + * + * In general, a board is a set of markers. So BoardConfiguration is only a list + * of the id of the markers along with the position of their corners. + * + * The position of the corners can be specified either in pixels (in a non-specific size) or in meters. + * The first is the typical case in which you generate the image of board and the print it. Since you do not know in advance the real + * size of the markers, their corners are specified in pixels, and then, the translation to meters can be made once you know the real size. + * + * On the other hand, you may want to have the information of your boards in meters. The BoardConfiguration allows you to do so. + * + * The point is in the mInfoType variable. It can be either PIX or METERS according to your needs. + * +*/ + + +class ARUCO_EXPORTS BoardConfiguration: public vector +{ + friend class Board; +public: + enum MarkerInfoType {NONE=-1,PIX=0,METERS=1};//indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally + //variable indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally + int mInfoType; + /** + */ + BoardConfiguration(); + + /** + */ + BoardConfiguration(const BoardConfiguration &T); + + /** + */ + BoardConfiguration & operator=(const BoardConfiguration &T); + /**Saves the board info to a file + */ + void saveToFile(string sfile)throw (cv::Exception); + /**Reads board info from a file + */ + void readFromFile(string sfile)throw (cv::Exception); + /**Indicates if the corners are expressed in meters + */ + bool isExpressedInMeters()const { + return mInfoType==METERS; + } + /**Indicates if the corners are expressed in meters + */ + bool isExpressedInPixels()const { + return mInfoType==PIX; + } + /**Returns the index of the marker with id indicated, if is in the list + */ + int getIndexOfMarkerId(int id)const; + /**Returns the Info of the marker with id specified. If not in the set, throws exception + */ + const MarkerInfo& getMarkerInfo(int id)const throw (cv::Exception); + /**Set in the list passed the set of the ids + */ + void getIdList(vector &ids,bool append=true)const; +private: + /**Saves the board info to a file + */ + void saveToFile(cv::FileStorage &fs)throw (cv::Exception); + /**Reads board info from a file + */ + void readFromFile(cv::FileStorage &fs)throw (cv::Exception); +}; + +/** +*/ +class ARUCO_EXPORTS Board:public vector +{ + +public: + BoardConfiguration conf; + //matrices of rotation and translation respect to the camera + cv::Mat Rvec,Tvec; + /** + */ + Board() + { + Rvec.create(3,1,CV_32FC1); + Tvec.create(3,1,CV_32FC1); + for (int i=0;i<3;i++) + Tvec.at(i,0)=Rvec.at(i,0)=-999999; + } + + /**Given the extrinsic camera parameters returns the GL_MODELVIEW matrix for opengl. + * Setting this matrix, the reference corrdinate system will be set in this board + */ + void glGetModelViewMatrix(double modelview_matrix[16])throw(cv::Exception); + + /** + * Returns position vector and orientation quaternion for an Ogre scene node or entity. + * Use: + * ... + * Ogre::Vector3 ogrePos (position[0], position[1], position[2]); + * Ogre::Quaternion ogreOrient (orientation[0], orientation[1], orientation[2], orientation[3]); + * mySceneNode->setPosition( ogrePos ); + * mySceneNode->setOrientation( ogreOrient ); + * ... + */ + void OgreGetPoseParameters( double position[3], double orientation[4] )throw(cv::Exception); + + + /**Save this from a file + */ + void saveToFile(string filePath)throw(cv::Exception); + /**Read this from a file + */ + void readFromFile(string filePath)throw(cv::Exception); + +}; +} + +#endif diff --git a/ftnoir_tracker_aruco/include/boarddetector.h b/ftnoir_tracker_aruco/include/boarddetector.h new file mode 100644 index 00000000..a0ee2361 --- /dev/null +++ b/ftnoir_tracker_aruco/include/boarddetector.h @@ -0,0 +1,139 @@ +/***************************** +Copyright 2011 Rafael Muñoz Salinas. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those of the +authors and should not be interpreted as representing official policies, either expressed +or implied, of Rafael Muñoz Salinas. +********************************/ +#ifndef _Aruco_BoardDetector_H +#define _Aruco_BoardDetector_H +#include +#include "exports.h" +#include "board.h" +#include "cameraparameters.h" +#include "markerdetector.h" +using namespace std; + +namespace aruco +{ + +/**\brief This class detects AR boards + * Version 1.2 + * There are two modes for board detection. + * First, the old way. (You first detect markers with MarkerDetector and then call to detect in this class. + * + * Second: New mode, marker detection is included in the class + * \code + + CameraParameters CP; + CP.readFromFile(path_cp) + BoardConfiguration BC; + BC.readFromFile(path_bc); + BoardDetector BD; + BD.setParams(BC,CP); //or only BD.setParams(BC) + //capture image + cv::Mat im; + capture_image(im); + + float prob=BD.detect(im); + if (prob>0.3) + CvDrawingUtils::draw3DAxis(im,BD.getDetectedBoard(),CP); + + \endcode + * +*/ +class ARUCO_EXPORTS BoardDetector +{ +public: + /** See discussion in @see enableRotateXAxis. + * Do not change unless you know what you are doing + */ + BoardDetector(bool setYPerperdicular=true); + + + /** + * Use if you plan to let this class to perform marker detection too + */ + void setParams(const BoardConfiguration &bc,const CameraParameters &cp, float markerSizeMeters=-1); + void setParams(const BoardConfiguration &bc); + /** + * Detect markers, and then, look for the board indicated in setParams() + * @return value indicating the likelihood of having found the marker + */ + float detect(const cv::Mat &im)throw (cv::Exception); + /**Returns a reference to the board detected + */ + Board & getDetectedBoard(){return _boardDetected;} + /**Returns a reference to the internal marker detector + */ + MarkerDetector &getMarkerDetector(){return _mdetector;} + /**Returns the vector of markers detected + */ + vector &getDetectedMarkers(){return _vmarkers;} + + + //ALTERNATIVE DETECTION METHOD, BASED ON MARKERS PREVIOUSLY DETECTED + + /** Given the markers detected, determines if there is the board passed + * @param detectedMarkers result provided by aruco::ArMarkerDetector + * @param BConf the board you want to see if is present + * @param Bdetected output information of the detected board + * @param camMatrix camera matrix with intrinsics + * @param distCoeff camera distorsion coeff + * @param camMatrix intrinsic camera information. + * @param distCoeff camera distorsion coefficient. If set Mat() if is assumed no camera distorion + * @param markerSizeMeters size of the marker sides expressed in meters + * @return value indicating the likelihood of having found the marker + */ + float detect(const vector &detectedMarkers,const BoardConfiguration &BConf, Board &Bdetected, cv::Mat camMatrix=cv::Mat(),cv::Mat distCoeff=cv::Mat(), float markerSizeMeters=-1 )throw (cv::Exception); + float detect(const vector &detectedMarkers,const BoardConfiguration &BConf, Board &Bdetected,const CameraParameters &cp, float markerSizeMeters=-1 )throw (cv::Exception); + + + /** + * By default, the Y axis is set to point up. However this is not the default + * operation mode of opencv, which produces the Z axis pointing up instead. + * So, to achieve this change, we have to rotate the X axis. + */ + void setYPerperdicular(bool enable){_setYPerperdicular=enable;} + + + + +private: + void rotateXAxis(cv::Mat &rotation); + bool _setYPerperdicular; + + //-- Functionality to detect markers inside + bool _areParamsSet; + BoardConfiguration _bconf; + Board _boardDetected; + float _markerSize; + CameraParameters _camParams; + MarkerDetector _mdetector;//internal markerdetector + vector _vmarkers;//markers detected in the call to : float detect(const cv::Mat &im); + +}; + +}; +#endif + diff --git a/ftnoir_tracker_aruco/include/cvdrawingutils.h b/ftnoir_tracker_aruco/include/cvdrawingutils.h index 24bfe630..ff67242f 100644 --- a/ftnoir_tracker_aruco/include/cvdrawingutils.h +++ b/ftnoir_tracker_aruco/include/cvdrawingutils.h @@ -33,13 +33,20 @@ namespace aruco { /**\brief A set of functions to draw in opencv images */ - class ARUCO_EXPORTS CvDrawingUtils - { - public: - static void draw3dAxis(cv::Mat &Image,Marker &m,const CameraParameters &CP); - static void draw3dCube(cv::Mat &Image,Marker &m,const CameraParameters &CP); - }; -} + class ARUCO_EXPORTS CvDrawingUtils + { + public: + + static void draw3dAxis(cv::Mat &Image,Marker &m,const CameraParameters &CP); + + static void draw3dCube(cv::Mat &Image,Marker &m,const CameraParameters &CP); + + static void draw3dAxis(cv::Mat &Image,Board &m,const CameraParameters &CP); + + static void draw3dCube(cv::Mat &Image,Board &m,const CameraParameters &CP); + + }; +}; #endif diff --git a/ftnoir_tracker_aruco/include/exports.h b/ftnoir_tracker_aruco/include/exports.h index 044a1367..aaeb94e4 100644 --- a/ftnoir_tracker_aruco/include/exports.h +++ b/ftnoir_tracker_aruco/include/exports.h @@ -37,9 +37,9 @@ or implied, of Rafael Muñoz Salinas. #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined DSO_EXPORTS - #define ARUCO_EXPORTS __declspec(dllexport) __attribute__((visibility ("default"))) + #define ARUCO_EXPORTS __declspec(dllexport) #else - #define ARUCO_EXPORTS __attribute__((visibility ("default"))) + #define ARUCO_EXPORTS __attribute__ ((visibility ("default"))) #endif diff --git a/ftnoir_tracker_aruco/include/markerdetector.h b/ftnoir_tracker_aruco/include/markerdetector.h index a4656527..6f489c34 100644 --- a/ftnoir_tracker_aruco/include/markerdetector.h +++ b/ftnoir_tracker_aruco/include/markerdetector.h @@ -52,13 +52,11 @@ class ARUCO_EXPORTS MarkerDetector contour=M.contour; idx=M.idx; } - MarkerCandidate operator=(const MarkerCandidate &M){ - if (this == &M) - return *this; + MarkerCandidate & operator=(const MarkerCandidate &M){ (*(Marker*)this)=(*(Marker*)&M); contour=M.contour; idx=M.idx; - return M; + return *this; } vector contour;//all the points of its contour @@ -69,11 +67,11 @@ public: /** * See */ - MarkerDetector() {} + MarkerDetector(); /** */ - ~MarkerDetector() {} + ~MarkerDetector(); /**Detects the markers in the image passed * @@ -353,5 +351,9 @@ private: void draw(cv::Mat out,const std::vector &markers ); }; -} + + + + +}; #endif -- cgit v1.2.3