diff --git a/modules/objdetect/src/aruco/aruco_detector.cpp b/modules/objdetect/src/aruco/aruco_detector.cpp index d5ddae8f1f..a1b04c8181 100644 --- a/modules/objdetect/src/aruco/aruco_detector.cpp +++ b/modules/objdetect/src/aruco/aruco_detector.cpp @@ -145,10 +145,8 @@ static void _findMarkerContours(const Mat &in, vector > &candida minPerimeterPixels = 4*minSize; } - Mat contoursImg; - in.copyTo(contoursImg); vector > contours; - findContours(contoursImg, contours, RETR_LIST, CHAIN_APPROX_NONE); + findContours(in, contours, RETR_LIST, CHAIN_APPROX_NONE); // now filter list of contours for(unsigned int i = 0; i < contours.size(); i++) { // check perimeter @@ -161,8 +159,7 @@ static void _findMarkerContours(const Mat &in, vector > &candida if(approxCurve.size() != 4 || !isContourConvex(approxCurve)) continue; // check min distance between corners - double minDistSq = - max(contoursImg.cols, contoursImg.rows) * max(contoursImg.cols, contoursImg.rows); + double minDistSq = max(in.cols, in.rows) * max(in.cols, in.rows); for(int j = 0; j < 4; j++) { double d = (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) * (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) + @@ -177,9 +174,9 @@ static void _findMarkerContours(const Mat &in, vector > &candida bool tooNearBorder = false; for(int j = 0; j < 4; j++) { if(approxCurve[j].x < minDistanceToBorder || approxCurve[j].y < minDistanceToBorder || - approxCurve[j].x > contoursImg.cols - 1 - minDistanceToBorder || - approxCurve[j].y > contoursImg.rows - 1 - minDistanceToBorder) - tooNearBorder = true; + approxCurve[j].x > in.cols - 1 - minDistanceToBorder || + approxCurve[j].y > in.rows - 1 - minDistanceToBorder) + tooNearBorder = true; } if(tooNearBorder) continue; @@ -883,7 +880,7 @@ void ArucoDetector::detectMarkers(InputArray _image, OutputArrayOfArrays _corner detectorParams.minMarkerLengthRatioOriginalImg == 0.0)); Mat grey; - _convertToGrey(_image.getMat(), grey); + _convertToGrey(_image, grey); // Aruco3 functionality is the extension of Aruco. // The description can be found in: diff --git a/modules/objdetect/src/aruco/aruco_utils.cpp b/modules/objdetect/src/aruco/aruco_utils.cpp index 4c0d2dc3f7..954ba11941 100644 --- a/modules/objdetect/src/aruco/aruco_utils.cpp +++ b/modules/objdetect/src/aruco/aruco_utils.cpp @@ -38,12 +38,12 @@ void _copyVector2Output(vector > &vec, OutputArrayOfArrays out, } } -void _convertToGrey(InputArray _in, OutputArray _out) { - CV_Assert(_in.type() == CV_8UC1 || _in.type() == CV_8UC3); - if(_in.type() == CV_8UC3) +void _convertToGrey(InputArray _in, Mat& _out) { + CV_Assert(_in.type() == CV_8UC1 || _in.type() == CV_8UC3 || _in.type() == CV_8UC4); + if(_in.type() != CV_8UC1) cvtColor(_in, _out, COLOR_BGR2GRAY); else - _in.copyTo(_out); + _out = _in.getMat(); } } diff --git a/modules/objdetect/src/aruco/aruco_utils.hpp b/modules/objdetect/src/aruco/aruco_utils.hpp index d7d29a7d18..009645b18b 100644 --- a/modules/objdetect/src/aruco/aruco_utils.hpp +++ b/modules/objdetect/src/aruco/aruco_utils.hpp @@ -16,9 +16,9 @@ namespace aruco { void _copyVector2Output(std::vector > &vec, OutputArrayOfArrays out, const float scale = 1.f); /** - * @brief Convert input image to gray if it is a 3-channels image + * @brief Convert input image to gray if it is a BGR or BGRA image */ -void _convertToGrey(InputArray _in, OutputArray _out); +void _convertToGrey(InputArray _in, Mat& _out); template inline bool readParameter(const std::string& name, T& parameter, const FileNode& node)