1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

optimize: replace push_back with emplace_back in core loops

Replaces wasteful temporary object construction with in-place construction using emplace_back. Covers hot paths in objdetect, imgproc, and stitching modules.
This commit is contained in:
AdwaithBatchu
2025-12-19 11:56:20 +05:30
parent b157553e55
commit 5f0bd387db
5 changed files with 50 additions and 50 deletions
+17 -17
View File
@@ -412,9 +412,9 @@ void QRDetect::fixationPoints(vector<Point2f> &local_point)
list_area_pnt.push_back(current_point);
vector<LineIterator> list_line_iter;
list_line_iter.push_back(LineIterator(bin_barcode, current_point, left_point));
list_line_iter.push_back(LineIterator(bin_barcode, current_point, central_point));
list_line_iter.push_back(LineIterator(bin_barcode, current_point, right_point));
list_line_iter.emplace_back(bin_barcode, current_point, left_point);
list_line_iter.emplace_back(bin_barcode, current_point, central_point);
list_line_iter.emplace_back(bin_barcode, current_point, right_point);
for (size_t k = 0; k < list_line_iter.size(); k++)
{
@@ -757,7 +757,7 @@ vector<Point2f> QRDetect::getQuadrilateral(vector<Point2f> angle_list)
{
int x = cvRound(angle_list[i].x);
int y = cvRound(angle_list[i].y);
locations.push_back(Point(x, y));
locations.emplace_back(x,y);
}
vector<Point> integer_hull;
@@ -2217,13 +2217,13 @@ bool QRDecode::straightenQRCodeInParts()
vector<Point2f> perspective_points;
perspective_points.push_back(Point2f(0.0, start_cut));
perspective_points.push_back(Point2f(perspective_curved_size, start_cut));
perspective_points.emplace_back(0.0, start_cut);
perspective_points.emplace_back(perspective_curved_size, start_cut);
perspective_points.push_back(Point2f(perspective_curved_size, start_cut + dist));
perspective_points.push_back(Point2f(0.0, start_cut+dist));
perspective_points.emplace_back(perspective_curved_size, start_cut + dist);
perspective_points.emplace_back(0.0, start_cut+dist);
perspective_points.push_back(Point2f(perspective_curved_size * 0.5f, start_cut + dist * 0.5f));
perspective_points.emplace_back(perspective_curved_size * 0.5f, start_cut + dist * 0.5f);
if (i == 1)
{
@@ -2294,13 +2294,13 @@ bool QRDecode::straightenQRCodeInParts()
}
vector<Point2f> perspective_straight_points;
perspective_straight_points.push_back(Point2f(0.f, 0.f));
perspective_straight_points.push_back(Point2f(perspective_curved_size, 0.f));
perspective_straight_points.emplace_back(0.f, 0.f);
perspective_straight_points.emplace_back(perspective_curved_size, 0.f);
perspective_straight_points.push_back(Point2f(perspective_curved_size, perspective_curved_size));
perspective_straight_points.push_back(Point2f(0.f, perspective_curved_size));
perspective_straight_points.emplace_back(perspective_curved_size, perspective_curved_size);
perspective_straight_points.emplace_back(0.f, perspective_curved_size);
perspective_straight_points.push_back(Point2f(perspective_curved_size * 0.5f, perspective_curved_size * 0.5f));
perspective_straight_points.emplace_back(perspective_curved_size * 0.5f, perspective_curved_size * 0.5f);
Mat H = findHomography(original_curved_points, perspective_straight_points);
if (H.empty())
@@ -3319,9 +3319,9 @@ void QRDetectMulti::fixationPoints(vector<Point2f> &local_point)
list_area_pnt.push_back(current_point);
vector<LineIterator> list_line_iter;
list_line_iter.push_back(LineIterator(bin_barcode_temp, current_point, left_point));
list_line_iter.push_back(LineIterator(bin_barcode_temp, current_point, central_point));
list_line_iter.push_back(LineIterator(bin_barcode_temp, current_point, right_point));
list_line_iter.emplace_back(bin_barcode_temp, current_point, left_point);
list_line_iter.emplace_back(bin_barcode_temp, current_point, central_point);
list_line_iter.emplace_back(bin_barcode_temp, current_point, right_point);
for (size_t k = 0; k < list_line_iter.size(); k++)
{