Skip to content

Commit 77e648f

Browse files
author
AleksandrPanov
committed
remove camParams and add cornerIndex check
1 parent ed0094c commit 77e648f

File tree

2 files changed

+10
-39
lines changed

2 files changed

+10
-39
lines changed

modules/aruco/include/opencv2/aruco.hpp

+1-5
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

+9-34
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;
@@ -907,35 +908,15 @@ static Point2f _getCrossPoint(Point3f nLine1, Point3f nLine2){
907908
return Vec2f(A.solve(B).val);
908909
}
909910

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-
925911
/**
926912
* Refine Corners using the contour vector :: Called from function detectMarkers
927913
* @param nContours, contour-container
928914
* @param nCorners, candidate Corners
929915
* @param camMatrix, cameraMatrix input 3x3 floating-point camera matrix
930916
* @param distCoeff, distCoeffs vector of distortion coefficient
931917
*/
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){
933919
vector<Point2f> contour2f(nContours.begin(), nContours.end());
934-
935-
if(!camMatrix.empty() && !distCoeff.empty()){
936-
undistortPoints(contour2f, contour2f, camMatrix, distCoeff);
937-
}
938-
939920
/* 5 groups :: to group the edges
940921
* 4 - classified by its corner
941922
* 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
953934
}
954935
cntPts[group].push_back(contour2f[i]);
955936
}
956-
937+
for (int i = 0; i < 4; i++)
938+
CV_Assert(cornerIndex[i] != -1);
957939
// saves extra group into corresponding
958940
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");
960941
for( unsigned int i=0; i < cntPts[4].size() ; i++ )
961942
cntPts[group].push_back(cntPts[4].at(i));
962943
cntPts[4].clear();
@@ -989,10 +970,6 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
989970
else
990971
nCorners[i] = _getCrossPoint(lines[ i ], lines[ (i+3)%4 ]); // 30 01 12 23
991972
}
992-
993-
if(!camMatrix.empty() && !distCoeff.empty()){
994-
_distortPoints(nCorners, camMatrix, distCoeff);
995-
}
996973
}
997974

998975

@@ -1002,13 +979,13 @@ static void _refineCandidateLines(std::vector<Point>& nContours, std::vector<Poi
1002979
*/
1003980
class MarkerContourParallel : public ParallelLoopBody {
1004981
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){}
1007984

1008985
void operator()(const Range &range) const CV_OVERRIDE {
1009986

1010987
for(int i = range.start; i < range.end; i++) {
1011-
_refineCandidateLines(contours[i], candidates[i], camMatrix, distCoeff);
988+
_refineCandidateLines(contours[i], candidates[i]);
1012989
}
1013990
}
1014991

@@ -1019,8 +996,6 @@ class MarkerContourParallel : public ParallelLoopBody {
1019996

1020997
vector< vector< Point > >& contours;
1021998
vector< vector< Point2f > >& candidates;
1022-
const Mat& camMatrix;
1023-
const Mat& distCoeff;
1024999
};
10251000

10261001
#ifdef APRIL_DEBUG
@@ -1162,7 +1137,7 @@ static void _apriltag(Mat im_orig, const Ptr<DetectorParameters> & _params, std:
11621137
*/
11631138
void detectMarkers(InputArray _image, const Ptr<Dictionary> &_dictionary, OutputArrayOfArrays _corners,
11641139
OutputArray _ids, const Ptr<DetectorParameters> &_params,
1165-
OutputArrayOfArrays _rejectedImgPoints, InputArrayOfArrays camMatrix, InputArrayOfArrays distCoeff) {
1140+
OutputArrayOfArrays _rejectedImgPoints) {
11661141

11671142
CV_Assert(!_image.empty());
11681143

@@ -1221,7 +1196,7 @@ void detectMarkers(InputArray _image, const Ptr<Dictionary> &_dictionary, Output
12211196
if(! _ids.empty()){
12221197

12231198
// 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));
12251200

12261201
// copy the corners to the output array
12271202
_copyVector2Output(candidates, _corners);

0 commit comments

Comments
 (0)