Merge pull request #19565 from cyyever:minor_fix

Local objects optimization in calibration init

* use emplace_back

* use {} initilization

* remove a tailing white space
This commit is contained in:
cyy 2021-03-05 23:04:51 +08:00 committed by GitHub
parent 2e429268ff
commit b450dd7a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 37 deletions

View File

@ -1842,7 +1842,7 @@ void ChessBoardDetector::generateQuads(const cv::Mat& image_, int flags)
if (boardIdx != parentIdx && (boardIdx < 0 || contour_child_counter[boardIdx] < contour_child_counter[parentIdx]))
boardIdx = parentIdx;
contour_quads.push_back(QuadCountour(pt, parentIdx));
contour_quads.emplace_back(pt, parentIdx);
}
size_t total = contour_quads.size();

View File

@ -78,7 +78,7 @@ static void icvGetQuadrangleHypotheses(const std::vector<std::vector< cv::Point
continue;
}
quads.push_back(std::pair<float, int>(box_size, class_id));
quads.emplace_back(box_size, class_id);
}
}

View File

@ -384,15 +384,15 @@ void CirclesGridClusterFinder::rectifyPatternPoints(const std::vector<cv::Point2
{
//indices of corner points in pattern
std::vector<Point> trueIndices;
trueIndices.push_back(Point(0, 0));
trueIndices.push_back(Point(patternSize.width - 1, 0));
trueIndices.emplace_back(0, 0);
trueIndices.emplace_back(patternSize.width - 1, 0);
if(isAsymmetricGrid)
{
trueIndices.push_back(Point(patternSize.width - 1, 1));
trueIndices.push_back(Point(patternSize.width - 1, patternSize.height - 2));
trueIndices.emplace_back(patternSize.width - 1, 1);
trueIndices.emplace_back(patternSize.width - 1, patternSize.height - 2);
}
trueIndices.push_back(Point(patternSize.width - 1, patternSize.height - 1));
trueIndices.push_back(Point(0, patternSize.height - 1));
trueIndices.emplace_back(patternSize.width - 1, patternSize.height - 1);
trueIndices.emplace_back(0, patternSize.height - 1);
std::vector<Point2f> idealPoints;
for(size_t idx=0; idx<trueIndices.size(); idx++)
@ -401,11 +401,11 @@ void CirclesGridClusterFinder::rectifyPatternPoints(const std::vector<cv::Point2
int j = trueIndices[idx].x;
if(isAsymmetricGrid)
{
idealPoints.push_back(Point2f((2*j + i % 2)*squareSize, i*squareSize));
idealPoints.emplace_back((2*j + i % 2)*squareSize, i*squareSize);
}
else
{
idealPoints.push_back(Point2f(j*squareSize, i*squareSize));
idealPoints.emplace_back(j*squareSize, i*squareSize);
}
}
@ -477,7 +477,7 @@ void Graph::addVertex(size_t id)
{
CV_Assert( !doesVertexExist( id ) );
vertices.insert(std::pair<size_t, Vertex> (id, Vertex()));
vertices.emplace(id, Vertex());
}
void Graph::addEdge(size_t id1, size_t id2)
@ -887,10 +887,9 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
convertPointsFromHomogeneous(dstKeypointsMat, dstKeypoints);
warpedKeypoints.clear();
for (size_t i = 0; i < dstKeypoints.size(); i++)
for (auto &pt:dstKeypoints)
{
Point2f pt = dstKeypoints[i];
warpedKeypoints.push_back(pt);
warpedKeypoints.emplace_back(std::move(pt));
}
return H;
@ -1526,35 +1525,35 @@ void CirclesGridFinder::getCornerSegments(const std::vector<std::vector<size_t>
//all 8 segments with one end in a corner
std::vector<Segment> corner;
corner.push_back(Segment(keypoints[points[1][0]], keypoints[points[0][0]]));
corner.push_back(Segment(keypoints[points[0][0]], keypoints[points[0][1]]));
corner.emplace_back(keypoints[points[1][0]], keypoints[points[0][0]]);
corner.emplace_back(keypoints[points[0][0]], keypoints[points[0][1]]);
segments.push_back(corner);
cornerIndices.push_back(Point(0, 0));
firstSteps.push_back(Point(1, 0));
secondSteps.push_back(Point(0, 1));
cornerIndices.emplace_back(0, 0);
firstSteps.emplace_back(1, 0);
secondSteps.emplace_back(0, 1);
corner.clear();
corner.push_back(Segment(keypoints[points[0][w - 2]], keypoints[points[0][w - 1]]));
corner.push_back(Segment(keypoints[points[0][w - 1]], keypoints[points[1][w - 1]]));
corner.emplace_back(keypoints[points[0][w - 2]], keypoints[points[0][w - 1]]);
corner.emplace_back(keypoints[points[0][w - 1]], keypoints[points[1][w - 1]]);
segments.push_back(corner);
cornerIndices.push_back(Point(w - 1, 0));
firstSteps.push_back(Point(0, 1));
secondSteps.push_back(Point(-1, 0));
cornerIndices.emplace_back(w - 1, 0);
firstSteps.emplace_back(0, 1);
secondSteps.emplace_back(-1, 0);
corner.clear();
corner.push_back(Segment(keypoints[points[h - 2][w - 1]], keypoints[points[h - 1][w - 1]]));
corner.push_back(Segment(keypoints[points[h - 1][w - 1]], keypoints[points[h - 1][w - 2]]));
corner.emplace_back(keypoints[points[h - 2][w - 1]], keypoints[points[h - 1][w - 1]]);
corner.emplace_back(keypoints[points[h - 1][w - 1]], keypoints[points[h - 1][w - 2]]);
segments.push_back(corner);
cornerIndices.push_back(Point(w - 1, h - 1));
firstSteps.push_back(Point(-1, 0));
secondSteps.push_back(Point(0, -1));
cornerIndices.emplace_back(w - 1, h - 1);
firstSteps.emplace_back(-1, 0);
secondSteps.emplace_back(0, -1);
corner.clear();
corner.push_back(Segment(keypoints[points[h - 1][1]], keypoints[points[h - 1][0]]));
corner.push_back(Segment(keypoints[points[h - 1][0]], keypoints[points[h - 2][0]]));
cornerIndices.push_back(Point(0, h - 1));
firstSteps.push_back(Point(0, -1));
secondSteps.push_back(Point(1, 0));
corner.emplace_back(keypoints[points[h - 1][1]], keypoints[points[h - 1][0]]);
corner.emplace_back(keypoints[points[h - 1][0]], keypoints[points[h - 2][0]]);
cornerIndices.emplace_back(0, h - 1);
firstSteps.emplace_back(0, -1);
secondSteps.emplace_back(1, 0);
segments.push_back(corner);
corner.clear();

View File

@ -345,7 +345,6 @@ struct HWFeatures
HWFeatures(bool run_initialize = false)
{
memset( have, 0, sizeof(have[0]) * MAX_FEATURE );
if (run_initialize)
initialize();
}
@ -730,7 +729,7 @@ struct HWFeatures
}
}
bool have[MAX_FEATURE+1];
bool have[MAX_FEATURE+1]{};
};
static HWFeatures featuresEnabled(true), featuresDisabled = HWFeatures(false);

View File

@ -229,7 +229,7 @@ int Subdiv2D::newEdge()
{
if( freeQEdge <= 0 )
{
qedges.push_back(QuadEdge());
qedges.emplace_back();
freeQEdge = (int)(qedges.size()-1);
}
int edge = freeQEdge*4;