Merge pull request #19565 from cyyever:minor_fix
authorcyy <cyyever@outlook.com>
Fri, 5 Mar 2021 15:04:51 +0000 (23:04 +0800)
committerGitHub <noreply@github.com>
Fri, 5 Mar 2021 15:04:51 +0000 (15:04 +0000)
Local objects optimization in calibration init

* use emplace_back

* use {} initilization

* remove a tailing white space

modules/calib3d/src/calibinit.cpp
modules/calib3d/src/checkchessboard.cpp
modules/calib3d/src/circlesgrid.cpp
modules/core/src/system.cpp
modules/imgproc/src/subdivision2d.cpp

index 320b9ae85dba5167c2b729f9a269755bc331a808..e25dd26d21bbc7339fe9de30d40f70425e0abfaa 100644 (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();
index 904604562dfb51242f6f44e64cbb66a55bcdb22e..97876d218cf6f28bf774e20a4fb9e78f96aed6a2 100644 (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);
     }
 }
 
index d99480f882106cc7f8354fd54755df0bf6fec006..df9534f755049a35311b19827d3358f70e9e4091 100644 (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();
 
index 901a503300996a0785d868d3cceafe03da2d35d7..ef0d588113a4b794851b284f0e0ec9bc692e1c4e 100644 (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);
index c254c5f9c620318641bb5df76b378c45edad8534..99248dba77ef669809e84ce18ffbebb3fe38a732 100644 (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;