mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #25045 from AleksandrPanov:aruco_fix_unnecessary_copying
fix unnecessary copying in ArucoDetector
This commit is contained in:
commit
318b7ec3e6
@ -145,10 +145,8 @@ static void _findMarkerContours(const Mat &in, vector<vector<Point2f> > &candida
|
|||||||
minPerimeterPixels = 4*minSize;
|
minPerimeterPixels = 4*minSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat contoursImg;
|
|
||||||
in.copyTo(contoursImg);
|
|
||||||
vector<vector<Point> > contours;
|
vector<vector<Point> > contours;
|
||||||
findContours(contoursImg, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
findContours(in, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
||||||
// now filter list of contours
|
// now filter list of contours
|
||||||
for(unsigned int i = 0; i < contours.size(); i++) {
|
for(unsigned int i = 0; i < contours.size(); i++) {
|
||||||
// check perimeter
|
// check perimeter
|
||||||
@ -161,8 +159,7 @@ static void _findMarkerContours(const Mat &in, vector<vector<Point2f> > &candida
|
|||||||
if(approxCurve.size() != 4 || !isContourConvex(approxCurve)) continue;
|
if(approxCurve.size() != 4 || !isContourConvex(approxCurve)) continue;
|
||||||
|
|
||||||
// check min distance between corners
|
// check min distance between corners
|
||||||
double minDistSq =
|
double minDistSq = max(in.cols, in.rows) * max(in.cols, in.rows);
|
||||||
max(contoursImg.cols, contoursImg.rows) * max(contoursImg.cols, contoursImg.rows);
|
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
double d = (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) *
|
double d = (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) *
|
||||||
(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<vector<Point2f> > &candida
|
|||||||
bool tooNearBorder = false;
|
bool tooNearBorder = false;
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
if(approxCurve[j].x < minDistanceToBorder || approxCurve[j].y < minDistanceToBorder ||
|
if(approxCurve[j].x < minDistanceToBorder || approxCurve[j].y < minDistanceToBorder ||
|
||||||
approxCurve[j].x > contoursImg.cols - 1 - minDistanceToBorder ||
|
approxCurve[j].x > in.cols - 1 - minDistanceToBorder ||
|
||||||
approxCurve[j].y > contoursImg.rows - 1 - minDistanceToBorder)
|
approxCurve[j].y > in.rows - 1 - minDistanceToBorder)
|
||||||
tooNearBorder = true;
|
tooNearBorder = true;
|
||||||
}
|
}
|
||||||
if(tooNearBorder) continue;
|
if(tooNearBorder) continue;
|
||||||
|
|
||||||
@ -883,7 +880,7 @@ void ArucoDetector::detectMarkers(InputArray _image, OutputArrayOfArrays _corner
|
|||||||
detectorParams.minMarkerLengthRatioOriginalImg == 0.0));
|
detectorParams.minMarkerLengthRatioOriginalImg == 0.0));
|
||||||
|
|
||||||
Mat grey;
|
Mat grey;
|
||||||
_convertToGrey(_image.getMat(), grey);
|
_convertToGrey(_image, grey);
|
||||||
|
|
||||||
// Aruco3 functionality is the extension of Aruco.
|
// Aruco3 functionality is the extension of Aruco.
|
||||||
// The description can be found in:
|
// The description can be found in:
|
||||||
|
@ -38,12 +38,12 @@ void _copyVector2Output(vector<vector<Point2f> > &vec, OutputArrayOfArrays out,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _convertToGrey(InputArray _in, OutputArray _out) {
|
void _convertToGrey(InputArray _in, Mat& _out) {
|
||||||
CV_Assert(_in.type() == CV_8UC1 || _in.type() == CV_8UC3);
|
CV_Assert(_in.type() == CV_8UC1 || _in.type() == CV_8UC3 || _in.type() == CV_8UC4);
|
||||||
if(_in.type() == CV_8UC3)
|
if(_in.type() != CV_8UC1)
|
||||||
cvtColor(_in, _out, COLOR_BGR2GRAY);
|
cvtColor(_in, _out, COLOR_BGR2GRAY);
|
||||||
else
|
else
|
||||||
_in.copyTo(_out);
|
_out = _in.getMat();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ namespace aruco {
|
|||||||
void _copyVector2Output(std::vector<std::vector<Point2f> > &vec, OutputArrayOfArrays out, const float scale = 1.f);
|
void _copyVector2Output(std::vector<std::vector<Point2f> > &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<typename T>
|
template<typename T>
|
||||||
inline bool readParameter(const std::string& name, T& parameter, const FileNode& node)
|
inline bool readParameter(const std::string& name, T& parameter, const FileNode& node)
|
||||||
|
Loading…
Reference in New Issue
Block a user