Skip to content

Commit b450dd7

Browse files
authored
Merge pull request opencv#19565 from cyyever:minor_fix
Local objects optimization in calibration init * use emplace_back * use {} initilization * remove a tailing white space
1 parent 2e42926 commit b450dd7

File tree

5 files changed

+35
-37
lines changed

5 files changed

+35
-37
lines changed

modules/calib3d/src/calibinit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ void ChessBoardDetector::generateQuads(const cv::Mat& image_, int flags)
18421842
if (boardIdx != parentIdx && (boardIdx < 0 || contour_child_counter[boardIdx] < contour_child_counter[parentIdx]))
18431843
boardIdx = parentIdx;
18441844

1845-
contour_quads.push_back(QuadCountour(pt, parentIdx));
1845+
contour_quads.emplace_back(pt, parentIdx);
18461846
}
18471847

18481848
size_t total = contour_quads.size();

modules/calib3d/src/checkchessboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void icvGetQuadrangleHypotheses(const std::vector<std::vector< cv::Point
7878
continue;
7979
}
8080

81-
quads.push_back(std::pair<float, int>(box_size, class_id));
81+
quads.emplace_back(box_size, class_id);
8282
}
8383
}
8484

modules/calib3d/src/circlesgrid.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ void CirclesGridClusterFinder::rectifyPatternPoints(const std::vector<cv::Point2
384384
{
385385
//indices of corner points in pattern
386386
std::vector<Point> trueIndices;
387-
trueIndices.push_back(Point(0, 0));
388-
trueIndices.push_back(Point(patternSize.width - 1, 0));
387+
trueIndices.emplace_back(0, 0);
388+
trueIndices.emplace_back(patternSize.width - 1, 0);
389389
if(isAsymmetricGrid)
390390
{
391-
trueIndices.push_back(Point(patternSize.width - 1, 1));
392-
trueIndices.push_back(Point(patternSize.width - 1, patternSize.height - 2));
391+
trueIndices.emplace_back(patternSize.width - 1, 1);
392+
trueIndices.emplace_back(patternSize.width - 1, patternSize.height - 2);
393393
}
394-
trueIndices.push_back(Point(patternSize.width - 1, patternSize.height - 1));
395-
trueIndices.push_back(Point(0, patternSize.height - 1));
394+
trueIndices.emplace_back(patternSize.width - 1, patternSize.height - 1);
395+
trueIndices.emplace_back(0, patternSize.height - 1);
396396

397397
std::vector<Point2f> idealPoints;
398398
for(size_t idx=0; idx<trueIndices.size(); idx++)
@@ -401,11 +401,11 @@ void CirclesGridClusterFinder::rectifyPatternPoints(const std::vector<cv::Point2
401401
int j = trueIndices[idx].x;
402402
if(isAsymmetricGrid)
403403
{
404-
idealPoints.push_back(Point2f((2*j + i % 2)*squareSize, i*squareSize));
404+
idealPoints.emplace_back((2*j + i % 2)*squareSize, i*squareSize);
405405
}
406406
else
407407
{
408-
idealPoints.push_back(Point2f(j*squareSize, i*squareSize));
408+
idealPoints.emplace_back(j*squareSize, i*squareSize);
409409
}
410410
}
411411

@@ -477,7 +477,7 @@ void Graph::addVertex(size_t id)
477477
{
478478
CV_Assert( !doesVertexExist( id ) );
479479

480-
vertices.insert(std::pair<size_t, Vertex> (id, Vertex()));
480+
vertices.emplace(id, Vertex());
481481
}
482482

483483
void Graph::addEdge(size_t id1, size_t id2)
@@ -887,10 +887,9 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
887887
convertPointsFromHomogeneous(dstKeypointsMat, dstKeypoints);
888888

889889
warpedKeypoints.clear();
890-
for (size_t i = 0; i < dstKeypoints.size(); i++)
890+
for (auto &pt:dstKeypoints)
891891
{
892-
Point2f pt = dstKeypoints[i];
893-
warpedKeypoints.push_back(pt);
892+
warpedKeypoints.emplace_back(std::move(pt));
894893
}
895894

896895
return H;
@@ -1526,35 +1525,35 @@ void CirclesGridFinder::getCornerSegments(const std::vector<std::vector<size_t>
15261525

15271526
//all 8 segments with one end in a corner
15281527
std::vector<Segment> corner;
1529-
corner.push_back(Segment(keypoints[points[1][0]], keypoints[points[0][0]]));
1530-
corner.push_back(Segment(keypoints[points[0][0]], keypoints[points[0][1]]));
1528+
corner.emplace_back(keypoints[points[1][0]], keypoints[points[0][0]]);
1529+
corner.emplace_back(keypoints[points[0][0]], keypoints[points[0][1]]);
15311530
segments.push_back(corner);
1532-
cornerIndices.push_back(Point(0, 0));
1533-
firstSteps.push_back(Point(1, 0));
1534-
secondSteps.push_back(Point(0, 1));
1531+
cornerIndices.emplace_back(0, 0);
1532+
firstSteps.emplace_back(1, 0);
1533+
secondSteps.emplace_back(0, 1);
15351534
corner.clear();
15361535

1537-
corner.push_back(Segment(keypoints[points[0][w - 2]], keypoints[points[0][w - 1]]));
1538-
corner.push_back(Segment(keypoints[points[0][w - 1]], keypoints[points[1][w - 1]]));
1536+
corner.emplace_back(keypoints[points[0][w - 2]], keypoints[points[0][w - 1]]);
1537+
corner.emplace_back(keypoints[points[0][w - 1]], keypoints[points[1][w - 1]]);
15391538
segments.push_back(corner);
1540-
cornerIndices.push_back(Point(w - 1, 0));
1541-
firstSteps.push_back(Point(0, 1));
1542-
secondSteps.push_back(Point(-1, 0));
1539+
cornerIndices.emplace_back(w - 1, 0);
1540+
firstSteps.emplace_back(0, 1);
1541+
secondSteps.emplace_back(-1, 0);
15431542
corner.clear();
15441543

1545-
corner.push_back(Segment(keypoints[points[h - 2][w - 1]], keypoints[points[h - 1][w - 1]]));
1546-
corner.push_back(Segment(keypoints[points[h - 1][w - 1]], keypoints[points[h - 1][w - 2]]));
1544+
corner.emplace_back(keypoints[points[h - 2][w - 1]], keypoints[points[h - 1][w - 1]]);
1545+
corner.emplace_back(keypoints[points[h - 1][w - 1]], keypoints[points[h - 1][w - 2]]);
15471546
segments.push_back(corner);
1548-
cornerIndices.push_back(Point(w - 1, h - 1));
1549-
firstSteps.push_back(Point(-1, 0));
1550-
secondSteps.push_back(Point(0, -1));
1547+
cornerIndices.emplace_back(w - 1, h - 1);
1548+
firstSteps.emplace_back(-1, 0);
1549+
secondSteps.emplace_back(0, -1);
15511550
corner.clear();
15521551

1553-
corner.push_back(Segment(keypoints[points[h - 1][1]], keypoints[points[h - 1][0]]));
1554-
corner.push_back(Segment(keypoints[points[h - 1][0]], keypoints[points[h - 2][0]]));
1555-
cornerIndices.push_back(Point(0, h - 1));
1556-
firstSteps.push_back(Point(0, -1));
1557-
secondSteps.push_back(Point(1, 0));
1552+
corner.emplace_back(keypoints[points[h - 1][1]], keypoints[points[h - 1][0]]);
1553+
corner.emplace_back(keypoints[points[h - 1][0]], keypoints[points[h - 2][0]]);
1554+
cornerIndices.emplace_back(0, h - 1);
1555+
firstSteps.emplace_back(0, -1);
1556+
secondSteps.emplace_back(1, 0);
15581557
segments.push_back(corner);
15591558
corner.clear();
15601559

modules/core/src/system.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ struct HWFeatures
345345

346346
HWFeatures(bool run_initialize = false)
347347
{
348-
memset( have, 0, sizeof(have[0]) * MAX_FEATURE );
349348
if (run_initialize)
350349
initialize();
351350
}
@@ -730,7 +729,7 @@ struct HWFeatures
730729
}
731730
}
732731

733-
bool have[MAX_FEATURE+1];
732+
bool have[MAX_FEATURE+1]{};
734733
};
735734

736735
static HWFeatures featuresEnabled(true), featuresDisabled = HWFeatures(false);

modules/imgproc/src/subdivision2d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int Subdiv2D::newEdge()
229229
{
230230
if( freeQEdge <= 0 )
231231
{
232-
qedges.push_back(QuadEdge());
232+
qedges.emplace_back();
233233
freeQEdge = (int)(qedges.size()-1);
234234
}
235235
int edge = freeQEdge*4;

0 commit comments

Comments
 (0)