@@ -857,6 +857,7 @@ class MarkerSubpixelParallel : public ParallelLoopBody {
857
857
* @param nContours, contour-container
858
858
*/
859
859
static Point3f _interpolate2Dline (const std::vector<cv::Point2f>& nContours){
860
+ CV_Assert (nContours.size () >= 2 );
860
861
float minX, minY, maxX, maxY;
861
862
minX = maxX = nContours[0 ].x ;
862
863
minY = maxY = nContours[0 ].y ;
@@ -907,35 +908,15 @@ static Point2f _getCrossPoint(Point3f nLine1, Point3f nLine2){
907
908
return Vec2f (A.solve (B).val );
908
909
}
909
910
910
- static void _distortPoints (vector<cv::Point2f>& in, const Mat& camMatrix, const Mat& distCoeff) {
911
- // trivial extrinsics
912
- Matx31f Rvec (0 ,0 ,0 );
913
- Matx31f Tvec (0 ,0 ,0 );
914
-
915
- // calculate 3d points and then reproject, so opencv makes the distortion internally
916
- vector<cv::Point3f> cornersPoints3d;
917
- for (unsigned int i = 0 ; i < in.size (); i++){
918
- float x= (in[i].x - float (camMatrix.at <double >(0 , 2 ))) / float (camMatrix.at <double >(0 , 0 ));
919
- float y= (in[i].y - float (camMatrix.at <double >(1 , 2 ))) / float (camMatrix.at <double >(1 , 1 ));
920
- cornersPoints3d.push_back (Point3f (x,y,1 ));
921
- }
922
- cv::projectPoints (cornersPoints3d, Rvec, Tvec, camMatrix, distCoeff, in);
923
- }
924
-
925
911
/* *
926
912
* Refine Corners using the contour vector :: Called from function detectMarkers
927
913
* @param nContours, contour-container
928
914
* @param nCorners, candidate Corners
929
915
* @param camMatrix, cameraMatrix input 3x3 floating-point camera matrix
930
916
* @param distCoeff, distCoeffs vector of distortion coefficient
931
917
*/
932
- static void _refineCandidateLines (std::vector<Point >& nContours, std::vector<Point2f>& nCorners, const Mat& camMatrix, const Mat& distCoeff ){
918
+ static void _refineCandidateLines (std::vector<Point >& nContours, std::vector<Point2f>& nCorners){
933
919
vector<Point2f> contour2f (nContours.begin (), nContours.end ());
934
-
935
- if (!camMatrix.empty () && !distCoeff.empty ()){
936
- undistortPoints (contour2f, contour2f, camMatrix, distCoeff);
937
- }
938
-
939
920
/* 5 groups :: to group the edges
940
921
* 4 - classified by its corner
941
922
* extra group - (temporary) if contours do not begin with a corner
@@ -953,10 +934,10 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
953
934
}
954
935
cntPts[group].push_back (contour2f[i]);
955
936
}
956
-
937
+ for (int i = 0 ; i < 4 ; i++)
938
+ CV_Assert (cornerIndex[i] != -1 );
957
939
// saves extra group into corresponding
958
940
if ( !cntPts[4 ].empty () ){
959
- CV_CheckLT (group, 4 , " FIXIT: avoiding infinite loop: implementation should be revised: https://github.com/opencv/opencv_contrib/issues/2738" );
960
941
for ( unsigned int i=0 ; i < cntPts[4 ].size () ; i++ )
961
942
cntPts[group].push_back (cntPts[4 ].at (i));
962
943
cntPts[4 ].clear ();
@@ -989,10 +970,6 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
989
970
else
990
971
nCorners[i] = _getCrossPoint (lines[ i ], lines[ (i+3 )%4 ]); // 30 01 12 23
991
972
}
992
-
993
- if (!camMatrix.empty () && !distCoeff.empty ()){
994
- _distortPoints (nCorners, camMatrix, distCoeff);
995
- }
996
973
}
997
974
998
975
@@ -1002,13 +979,13 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
1002
979
*/
1003
980
class MarkerContourParallel : public ParallelLoopBody {
1004
981
public:
1005
- MarkerContourParallel ( vector< vector< Point > >& _contours, vector< vector< Point2f > >& _candidates, const Mat& _camMatrix, const Mat& _distCoeff )
1006
- : contours(_contours), candidates(_candidates), camMatrix(_camMatrix), distCoeff(_distCoeff) {}
982
+ MarkerContourParallel ( vector< vector< Point > >& _contours, vector< vector< Point2f > >& _candidates)
983
+ : contours(_contours), candidates(_candidates){}
1007
984
1008
985
void operator ()(const Range &range) const CV_OVERRIDE {
1009
986
1010
987
for (int i = range.start ; i < range.end ; i++) {
1011
- _refineCandidateLines (contours[i], candidates[i], camMatrix, distCoeff );
988
+ _refineCandidateLines (contours[i], candidates[i]);
1012
989
}
1013
990
}
1014
991
@@ -1019,8 +996,6 @@ class MarkerContourParallel : public ParallelLoopBody {
1019
996
1020
997
vector< vector< Point > >& contours;
1021
998
vector< vector< Point2f > >& candidates;
1022
- const Mat& camMatrix;
1023
- const Mat& distCoeff;
1024
999
};
1025
1000
1026
1001
#ifdef APRIL_DEBUG
@@ -1162,7 +1137,7 @@ static void _apriltag(Mat im_orig, const Ptr<DetectorParameters> & _params, std:
1162
1137
*/
1163
1138
void detectMarkers (InputArray _image, const Ptr <Dictionary> &_dictionary, OutputArrayOfArrays _corners,
1164
1139
OutputArray _ids, const Ptr <DetectorParameters> &_params,
1165
- OutputArrayOfArrays _rejectedImgPoints, InputArrayOfArrays camMatrix, InputArrayOfArrays distCoeff ) {
1140
+ OutputArrayOfArrays _rejectedImgPoints) {
1166
1141
1167
1142
CV_Assert (!_image.empty ());
1168
1143
@@ -1221,7 +1196,7 @@ void detectMarkers(InputArray _image, const Ptr<Dictionary> &_dictionary, Output
1221
1196
if (! _ids.empty ()){
1222
1197
1223
1198
// do corner refinement using the contours for each detected markers
1224
- parallel_for_ (Range (0 , _corners.cols ()), MarkerContourParallel (contours, candidates, camMatrix. getMat (), distCoeff. getMat () ));
1199
+ parallel_for_ (Range (0 , _corners.cols ()), MarkerContourParallel (contours, candidates));
1225
1200
1226
1201
// copy the corners to the output array
1227
1202
_copyVector2Output (candidates, _corners);
0 commit comments