@@ -857,6 +857,7 @@ class MarkerSubpixelParallel : public ParallelLoopBody {
857857 * @param nContours, contour-container
858858 */
859859static Point3f _interpolate2Dline (const std::vector<cv::Point2f>& nContours){
860+ CV_Assert (nContours.size () >= 2 );
860861 float minX, minY, maxX, maxY;
861862 minX = maxX = nContours[0 ].x ;
862863 minY = maxY = nContours[0 ].y ;
@@ -929,13 +930,8 @@ static void _distortPoints(vector<cv::Point2f>& in, const Mat& camMatrix, const
929930 * @param camMatrix, cameraMatrix input 3x3 floating-point camera matrix
930931 * @param distCoeff, distCoeffs vector of distortion coefficient
931932 */
932- static void _refineCandidateLines (std::vector<Point>& nContours, std::vector<Point2f>& nCorners, const Mat& camMatrix, const Mat& distCoeff ){
933+ static void _refineCandidateLines (std::vector<Point>& nContours, std::vector<Point2f>& nCorners){
933934 vector<Point2f> contour2f (nContours.begin (), nContours.end ());
934-
935- if (!camMatrix.empty () && !distCoeff.empty ()){
936- undistortPoints (contour2f, contour2f, camMatrix, distCoeff);
937- }
938-
939935 /* 5 groups :: to group the edges
940936 * 4 - classified by its corner
941937 * extra group - (temporary) if contours do not begin with a corner
@@ -953,10 +949,10 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
953949 }
954950 cntPts[group].push_back (contour2f[i]);
955951 }
956-
952+ for (int i = 0 ; i < 4 ; i++)
953+ CV_Assert (cornerIndex[i] != -1 );
957954 // saves extra group into corresponding
958955 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" );
960956 for ( unsigned int i=0 ; i < cntPts[4 ].size () ; i++ )
961957 cntPts[group].push_back (cntPts[4 ].at (i));
962958 cntPts[4 ].clear ();
@@ -989,10 +985,6 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
989985 else
990986 nCorners[i] = _getCrossPoint (lines[ i ], lines[ (i+3 )%4 ]); // 30 01 12 23
991987 }
992-
993- if (!camMatrix.empty () && !distCoeff.empty ()){
994- _distortPoints (nCorners, camMatrix, distCoeff);
995- }
996988}
997989
998990
@@ -1002,13 +994,13 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
1002994 */
1003995class MarkerContourParallel : public ParallelLoopBody {
1004996 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) {}
997+ MarkerContourParallel ( vector< vector< Point > >& _contours, vector< vector< Point2f > >& _candidates)
998+ : contours(_contours), candidates(_candidates){}
1007999
10081000 void operator ()(const Range &range) const CV_OVERRIDE {
10091001
10101002 for (int i = range.start ; i < range.end ; i++) {
1011- _refineCandidateLines (contours[i], candidates[i], camMatrix, distCoeff );
1003+ _refineCandidateLines (contours[i], candidates[i]);
10121004 }
10131005 }
10141006
@@ -1019,8 +1011,6 @@ class MarkerContourParallel : public ParallelLoopBody {
10191011
10201012 vector< vector< Point > >& contours;
10211013 vector< vector< Point2f > >& candidates;
1022- const Mat& camMatrix;
1023- const Mat& distCoeff;
10241014};
10251015
10261016#ifdef APRIL_DEBUG
@@ -1162,7 +1152,7 @@ static void _apriltag(Mat im_orig, const Ptr<DetectorParameters> & _params, std:
11621152 */
11631153void detectMarkers (InputArray _image, const Ptr<Dictionary> &_dictionary, OutputArrayOfArrays _corners,
11641154 OutputArray _ids, const Ptr<DetectorParameters> &_params,
1165- OutputArrayOfArrays _rejectedImgPoints, InputArrayOfArrays camMatrix, InputArrayOfArrays distCoeff ) {
1155+ OutputArrayOfArrays _rejectedImgPoints) {
11661156
11671157 CV_Assert (!_image.empty ());
11681158
@@ -1221,7 +1211,7 @@ void detectMarkers(InputArray _image, const Ptr<Dictionary> &_dictionary, Output
12211211 if (! _ids.empty ()){
12221212
12231213 // do corner refinement using the contours for each detected markers
1224- parallel_for_ (Range (0 , _corners.cols ()), MarkerContourParallel (contours, candidates, camMatrix. getMat (), distCoeff. getMat () ));
1214+ parallel_for_ (Range (0 , _corners.cols ()), MarkerContourParallel (contours, candidates));
12251215
12261216 // copy the corners to the output array
12271217 _copyVector2Output (candidates, _corners);
0 commit comments