Skip to content

Commit 6004438

Browse files
author
AleksandrPanov
committed
remove camParams, and add cornerIndex check
1 parent ed0094c commit 6004438

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ struct CV_EXPORTS_W DetectorParameters {
206206
* @param parameters marker detection parameters
207207
* @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a
208208
* correct codification. Useful for debugging purposes.
209-
* @param cameraMatrix optional input 3x3 floating-point camera matrix
210-
* \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
211-
* @param distCoeff optional vector of distortion coefficients
212-
* \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
213209
*
214210
* Performs marker detection in the input image. Only markers included in the specific dictionary
215211
* are searched. For each detected marker, it returns the 2D position of its corner in the image
@@ -220,7 +216,7 @@ struct CV_EXPORTS_W DetectorParameters {
220216
*/
221217
CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
222218
OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
223-
OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray());
219+
OutputArrayOfArrays rejectedImgPoints = noArray());
224220

225221

226222

modules/aruco/src/aruco.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ class MarkerSubpixelParallel : public ParallelLoopBody {
857857
* @param nContours, contour-container
858858
*/
859859
static 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
*/
1003995
class 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
*/
11631153
void 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

Comments
 (0)