1 #pragma GCC diagnostic warning "-Wuninitialized" 29 #include <aruco/boarddetector.h> 30 #define _USE_MATH_DEFINES 41 BoardDetector::BoardDetector(
bool setYPerpendicular)
42 : _setYPerpendicular(setYPerpendicular),
78 return detect ( detectedMarkers, BConf,Bdetected,cp.CameraMatrix,cp.Distorsion,markerSizeMeters );
83 if (BConf.size()==0)
throw cv::Exception(8881,
"BoardDetector::detect",
"Invalid BoardConfig that is empty",__FILE__,__LINE__);
84 if (BConf[0].size()<2)
throw cv::Exception(8881,
"BoardDetector::detect",
"Invalid BoardConfig that is empty 2",__FILE__,__LINE__);
90 ssize=cv::norm ( BConf[0][0]-BConf[0][1] );
96 for (
unsigned int i=0;i<detectedMarkers.size();i++ )
100 Bdetected.push_back ( detectedMarkers[i] );
101 Bdetected.back().ssize=ssize;
105 Bdetected.
conf=BConf;
108 bool hasEnoughInfoForRTvecCalculation=
false;
109 if ( Bdetected.size() >=1 )
111 if ( camMatrix.rows!=0 )
119 if ( hasEnoughInfoForRTvecCalculation )
122 double marker_meter_per_pix=0;
124 else marker_meter_per_pix=1;
127 Mat objPoints ( 4*Bdetected.size(),3,CV_32FC1 );
128 Mat imagePoints ( 4*Bdetected.size(),2,CV_32FC1 );
131 for (
size_t i=0;i<Bdetected.size();i++ )
135 for (
int p=0;p<4;p++ )
137 imagePoints.at<
float> ( ( i*4 ) +p,0 ) =Bdetected[i][p].x;
138 imagePoints.at<
float> ( ( i*4 ) +p,1 ) =Bdetected[i][p].y;
141 objPoints.at<
float> ( ( i*4 ) +p,0 ) = Minfo[p].x*marker_meter_per_pix;
142 objPoints.at<
float> ( ( i*4 ) +p,1 ) = Minfo[p].y*marker_meter_per_pix;
143 objPoints.at<
float> ( ( i*4 ) +p,2 ) = Minfo[p].z*marker_meter_per_pix;
147 if (distCoeff.total()==0) distCoeff=cv::Mat::zeros(1,4,CV_32FC1 );
150 cv::solvePnP(objPoints,imagePoints,camMatrix,distCoeff,rvec,tvec );
151 rvec.convertTo(Bdetected.
Rvec,CV_32FC1);
152 tvec.convertTo(Bdetected.
Tvec,CV_32FC1);
160 float prob=float( Bdetected.size() ) /
double ( Bdetected.
conf.size() );
166 cv::Mat R ( 3,3,CV_32FC1 );
167 Rodrigues ( rotation, R );
169 cv::Mat RX=cv::Mat::eye ( 3,3,CV_32FC1 );
170 float angleRad=-M_PI/2;
171 RX.at<
float> ( 1,1 ) =cos ( angleRad );
172 RX.at<
float> ( 1,2 ) =-sin ( angleRad );
173 RX.at<
float> ( 2,1 ) =sin ( angleRad );
174 RX.at<
float> ( 2,2 ) =cos ( angleRad );
178 Rodrigues ( R,rotation );
vector< Marker > _vmarkers
MarkerDetector _mdetector
void detect(const cv::Mat &input, std::vector< Marker > &detectedMarkers, cv::Mat camMatrix=cv::Mat(), cv::Mat distCoeff=cv::Mat(), float markerSizeMeters=-1, bool setYPerpendicular=true)
CameraParameters _camParams
void setParams(const BoardConfiguration &bc, const CameraParameters &cp, float markerSizeMeters=-1)
int getIndexOfMarkerId(int id) const
float detect(const cv::Mat &im)
const MarkerInfo & getMarkerInfo(int id) const
Parameters of the camera.
This class defines a board with several markers. A Board contains several markers so that they are mo...
BoardConfiguration _bconf
void rotateXAxis(cv::Mat &rotation)