From 31bd84de124e813ae24df5f38af8f39d105c3976 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Sun, 18 Sep 2016 23:24:54 +0100 Subject: [PATCH 1/6] LSD: Removes unused code --- modules/imgproc/src/lsd.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 8791f0aad8..87afdc227a 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -474,7 +474,6 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, std::vector reg(img_width * img_height); // Search for line segments - unsigned int ls_count = 0; for(size_t i = 0, list_size = list.size(); i < list_size; ++i) { unsigned int adx = list[i].p.x + list[i].p.y * img_width; @@ -505,7 +504,6 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, } } // Found new line - ++ls_count; // Add the offset rec.x1 += 0.5; rec.y1 += 0.5; @@ -524,13 +522,6 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, if(w_needed) widths.push_back(rec.width); if(p_needed) precisions.push_back(rec.p); if(n_needed && doRefine >= LSD_REFINE_ADV) nfas.push_back(log_nfa); - - - // //Add the linesID to the region on the image - // for(unsigned int el = 0; el < reg_size; el++) - // { - // region.data[reg[i].x + reg[i].y * width] = ls_count; - // } } } } From f5a0b226f27fcbe949a269e897d8b41265d08ed1 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Sun, 18 Sep 2016 22:32:33 +0100 Subject: [PATCH 2/6] LSD: Optimization, avoid converting the image to double --- modules/imgproc/src/lsd.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 87afdc227a..ad344ac096 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -230,8 +230,8 @@ public: private: Mat image; - Mat_ scaled_image; - double *scaled_image_data; + Mat scaled_image; + uchar *scaled_image_data; Mat_ angles; // in rads double *angles_data; Mat_ modgrad; @@ -414,11 +414,8 @@ void LineSegmentDetectorImpl::detect(InputArray _image, OutputArray _lines, { CV_INSTRUMENT_REGION() - Mat_ img = _image.getMat(); - CV_Assert(!img.empty() && img.channels() == 1); - - // Convert image to double - img.convertTo(image, CV_64FC1); + image = _image.getMat(); + CV_Assert(!image.empty() && image.type() == CV_8UC1); std::vector lines; std::vector w, p, n; @@ -536,7 +533,7 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, angles_data = angles.ptr(0); modgrad_data = modgrad.ptr(0); - scaled_image_data = scaled_image.ptr(0); + scaled_image_data = scaled_image.ptr(0); img_width = scaled_image.cols; img_height = scaled_image.rows; @@ -555,11 +552,11 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, { for(int addr = y * img_width, addr_end = addr + img_width - 1; addr < addr_end; ++addr) { - double DA = scaled_image_data[addr + img_width + 1] - scaled_image_data[addr]; - double BC = scaled_image_data[addr + 1] - scaled_image_data[addr + img_width]; - double gx = DA + BC; // gradient x component - double gy = DA - BC; // gradient y component - double norm = std::sqrt((gx * gx + gy * gy) / 4); // gradient norm + int DA = scaled_image_data[addr + img_width + 1] - scaled_image_data[addr]; + int BC = scaled_image_data[addr + 1] - scaled_image_data[addr + img_width]; + int gx = DA + BC; // gradient x component + int gy = DA - BC; // gradient y component + double norm = std::sqrt((gx * gx + gy * gy) / 4.0); // gradient norm modgrad_data[addr] = norm; // store gradient From a12207c3ad16db85c9c1d6252434a001c6ad4542 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Sun, 18 Sep 2016 22:48:23 +0100 Subject: [PATCH 3/6] LSD: Avoid using pointers directly, image could be non continuous --- modules/imgproc/src/lsd.cpp | 76 +++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index ad344ac096..b28403f268 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -231,11 +231,8 @@ public: private: Mat image; Mat scaled_image; - uchar *scaled_image_data; Mat_ angles; // in rads - double *angles_data; Mat_ modgrad; - double *modgrad_data; Mat_ used; int img_width; @@ -383,7 +380,7 @@ private: * Is the point at place 'address' aligned to angle theta, up to precision 'prec'? * @return Whether the point is aligned. */ - bool isAligned(const int& address, const double& theta, const double& prec) const; + bool isAligned(int x, int y, const double& theta, const double& prec) const; }; ///////////////////////////////////////////////////////////////////////////////////////// @@ -473,8 +470,8 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, // Search for line segments for(size_t i = 0, list_size = list.size(); i < list_size; ++i) { - unsigned int adx = list[i].p.x + list[i].p.y * img_width; - if((used.ptr()[adx] == NOTUSED) && (angles_data[adx] != NOTDEF)) + const Point2i& point = list[i].p; + if((used.at(point) == NOTUSED) && (angles.at(point) != NOTDEF)) { int reg_size; double reg_angle; @@ -531,10 +528,6 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, angles = Mat_(scaled_image.size()); modgrad = Mat_(scaled_image.size()); - angles_data = angles.ptr(0); - modgrad_data = modgrad.ptr(0); - scaled_image_data = scaled_image.ptr(0); - img_width = scaled_image.cols; img_height = scaled_image.rows; @@ -543,30 +536,30 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, angles.col(img_width - 1).setTo(NOTDEF); // Computing gradient for remaining pixels - CV_Assert(scaled_image.isContinuous() && - modgrad.isContinuous() && - angles.isContinuous()); // Accessing image data linearly - double max_grad = -1; for(int y = 0; y < img_height - 1; ++y) { - for(int addr = y * img_width, addr_end = addr + img_width - 1; addr < addr_end; ++addr) + const uchar* scaled_image_row = scaled_image.ptr(y); + const uchar* next_scaled_image_row = scaled_image.ptr(y+1); + double* angles_row = angles.ptr(y); + double* modgrad_row = modgrad.ptr(y); + for(int x = 0; x < img_width-1; ++x) { - int DA = scaled_image_data[addr + img_width + 1] - scaled_image_data[addr]; - int BC = scaled_image_data[addr + 1] - scaled_image_data[addr + img_width]; + int DA = next_scaled_image_row[x + 1] - scaled_image_row[x]; + int BC = scaled_image_row[x + 1] - next_scaled_image_row[x]; int gx = DA + BC; // gradient x component int gy = DA - BC; // gradient y component double norm = std::sqrt((gx * gx + gy * gy) / 4.0); // gradient norm - modgrad_data[addr] = norm; // store gradient + modgrad_row[x] = norm; // store gradient if (norm <= threshold) // norm too small, gradient no defined { - angles_data[addr] = NOTDEF; + angles_row[x] = NOTDEF; } else { - angles_data[addr] = fastAtan2(float(gx), float(-gy)) * DEG_TO_RADS; // gradient angle computation + angles_row[x] = fastAtan2(float(gx), float(-gy)) * DEG_TO_RADS; // gradient angle computation if (norm > max_grad) { max_grad = norm; } } @@ -582,11 +575,11 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, for(int y = 0; y < img_height - 1; ++y) { - const double* norm = modgrad_data + y * img_width; - for(int x = 0; x < img_width - 1; ++x, ++norm) + const double* modgrad_row = modgrad.ptr(y); + for(int x = 0; x < img_width - 1; ++x) { // Store the point in the right bin according to its norm - int i = int((*norm) * bin_coef); + int i = int(modgrad_row[x] * bin_coef); if(!range_e[i]) { range_e[i] = range_s[i] = &list[count]; @@ -629,11 +622,10 @@ void LineSegmentDetectorImpl::region_grow(const Point2i& s, std::vector(s); + reg_angle = angles.at(s); reg[0].angle = reg_angle; - reg[0].modgrad = modgrad_data[addr]; + reg[0].modgrad = modgrad.at(s); float sumdx = float(std::cos(reg_angle)); float sumdy = float(std::sin(reg_angle)); @@ -647,20 +639,23 @@ void LineSegmentDetectorImpl::region_grow(const Point2i& s, std::vector(yy); + const double* angles_row = angles.ptr(yy); + const double* modgrad_row = modgrad.ptr(yy); + for(int xx = xx_min; xx <= xx_max; ++xx) { - if((used.ptr()[c_addr] != USED) && - (isAligned(c_addr, reg_angle, prec))) + uchar& is_used = used_row[xx]; + if(is_used != USED && + (isAligned(xx, yy, reg_angle, prec))) { + const double& angle = angles_row[xx]; // Add point - used.ptr()[c_addr] = USED; + is_used = USED; RegionPoint& region_point = reg[reg_size]; region_point.x = xx; region_point.y = yy; - region_point.used = &(used.ptr()[c_addr]); - region_point.modgrad = modgrad_data[c_addr]; - const double& angle = angles_data[c_addr]; + region_point.used = &is_used; + region_point.modgrad = modgrad_row[xx]; region_point.angle = angle; ++reg_size; @@ -1063,13 +1058,12 @@ double LineSegmentDetectorImpl::rect_nfa(const rect& rec) const { if (y < 0 || y >= img_height) continue; - int adx = y * img_width + int(left_x); - for(int x = int(left_x); x <= int(right_x); ++x, ++adx) + for(int x = int(left_x); x <= int(right_x); ++x) { if (x < 0 || x >= img_width) continue; ++total_pts; - if(isAligned(adx, rec.theta, rec.prec)) + if(isAligned(x, y, rec.theta, rec.prec)) { ++alg_pts; } @@ -1123,10 +1117,10 @@ double LineSegmentDetectorImpl::nfa(const int& n, const int& k, const double& p) return -log10(bin_tail) - LOG_NT; } -inline bool LineSegmentDetectorImpl::isAligned(const int& address, const double& theta, const double& prec) const +inline bool LineSegmentDetectorImpl::isAligned(int x, int y, const double& theta, const double& prec) const { - if(address < 0) { return false; } - const double& a = angles_data[address]; + if(x < 0 || y < 0 || x >= angles.cols || y >= angles.rows) { return false; } + const double& a = angles.at(y, x); if(a == NOTDEF) { return false; } // It is assumed that 'theta' and 'a' are in the range [-pi,pi] From ef6b69644673cb44adfe60f14fa08f170f6e0062 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Tue, 20 Sep 2016 09:36:09 +0100 Subject: [PATCH 4/6] LSD: Avoid pre allocating a big region, std::vector allocations is quite expensive --- modules/imgproc/src/lsd.cpp | 92 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index b28403f268..969d617caf 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -314,31 +314,29 @@ private: * * @param s Starting point for the region. * @param reg Return: Vector of points, that are part of the region - * @param reg_size Return: The size of the region. * @param reg_angle Return: The mean angle of the region. * @param prec The precision by which each region angle should be aligned to the mean. */ void region_grow(const Point2i& s, std::vector& reg, - int& reg_size, double& reg_angle, const double& prec); + double& reg_angle, const double& prec); /** * Finds the bounding rotated rectangle of a region. * * @param reg The region of points, from which the rectangle to be constructed from. - * @param reg_size The number of points in the region. * @param reg_angle The mean angle of the region. * @param prec The precision by which points were found. * @param p Probability of a point with angle within 'prec'. * @param rec Return: The generated rectangle. */ - void region2rect(const std::vector& reg, const int reg_size, const double reg_angle, + void region2rect(const std::vector& reg, const double reg_angle, const double prec, const double p, rect& rec) const; /** * Compute region's angle as the principal inertia axis of the region. * @return Regions angle. */ - double get_theta(const std::vector& reg, const int& reg_size, const double& x, + double get_theta(const std::vector& reg, const double& x, const double& y, const double& reg_angle, const double& prec) const; /** @@ -347,14 +345,14 @@ private: * estimated angle tolerance. If this fails to produce a rectangle with the right density of region points, * 'reduce_region_radius' is called to try to satisfy this condition. */ - bool refine(std::vector& reg, int& reg_size, double reg_angle, + bool refine(std::vector& reg, double reg_angle, const double prec, double p, rect& rec, const double& density_th); /** * Reduce the region size, by elimination the points far from the starting point, until that leads to * rectangle with the right density of region points or to discard the region if too small. */ - bool reduce_region_radius(std::vector& reg, int& reg_size, double reg_angle, + bool reduce_region_radius(std::vector& reg, double reg_angle, const double prec, double p, rect& rec, double density, const double& density_th); /** @@ -460,12 +458,12 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, } LOG_NT = 5 * (log10(double(img_width)) + log10(double(img_height))) / 2 + log10(11.0); - const int min_reg_size = int(-LOG_NT/log10(p)); // minimal number of points in region that can give a meaningful event + const size_t min_reg_size = size_t(-LOG_NT/log10(p)); // minimal number of points in region that can give a meaningful event // // Initialize region only when needed // Mat region = Mat::zeros(scaled_image.size(), CV_8UC1); used = Mat_::zeros(scaled_image.size()); // zeros = NOTUSED - std::vector reg(img_width * img_height); + std::vector reg; // Search for line segments for(size_t i = 0, list_size = list.size(); i < list_size; ++i) @@ -473,22 +471,21 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, const Point2i& point = list[i].p; if((used.at(point) == NOTUSED) && (angles.at(point) != NOTDEF)) { - int reg_size; double reg_angle; - region_grow(list[i].p, reg, reg_size, reg_angle, prec); + region_grow(list[i].p, reg, reg_angle, prec); // Ignore small regions - if(reg_size < min_reg_size) { continue; } + if(reg.size() < min_reg_size) { continue; } // Construct rectangular approximation for the region rect rec; - region2rect(reg, reg_size, reg_angle, prec, p, rec); + region2rect(reg, reg_angle, prec, p, rec); double log_nfa = -1; if(doRefine > LSD_REFINE_NONE) { // At least REFINE_STANDARD lvl. - if(!refine(reg, reg_size, reg_angle, prec, p, rec, DENSITY_TH)) { continue; } + if(!refine(reg, reg_angle, prec, p, rec, DENSITY_TH)) { continue; } if(doRefine >= LSD_REFINE_ADV) { @@ -616,23 +613,26 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, } void LineSegmentDetectorImpl::region_grow(const Point2i& s, std::vector& reg, - int& reg_size, double& reg_angle, const double& prec) + double& reg_angle, const double& prec) { + reg.clear(); + // Point to this region - reg_size = 1; - reg[0].x = s.x; - reg[0].y = s.y; - reg[0].used = &used.at(s); + RegionPoint seed; + seed.x = s.x; + seed.y = s.y; + seed.used = &used.at(s); reg_angle = angles.at(s); - reg[0].angle = reg_angle; - reg[0].modgrad = modgrad.at(s); + seed.angle = reg_angle; + seed.modgrad = modgrad.at(s); + reg.push_back(seed); float sumdx = float(std::cos(reg_angle)); float sumdy = float(std::sin(reg_angle)); - *reg[0].used = USED; + *seed.used = USED; //Try neighboring regions - for(int i = 0; i < reg_size; ++i) + for (size_t i = 0;i& reg, const int reg_size, +void LineSegmentDetectorImpl::region2rect(const std::vector& reg, const double reg_angle, const double prec, const double p, rect& rec) const { double x = 0, y = 0, sum = 0; - for(int i = 0; i < reg_size; ++i) + for(size_t i = 0; i < reg.size(); ++i) { const RegionPoint& pnt = reg[i]; const double& weight = pnt.modgrad; @@ -689,14 +689,14 @@ void LineSegmentDetectorImpl::region2rect(const std::vector& reg, c x /= sum; y /= sum; - double theta = get_theta(reg, reg_size, x, y, reg_angle, prec); + double theta = get_theta(reg, x, y, reg_angle, prec); // Find length and width double dx = cos(theta); double dy = sin(theta); double l_min = 0, l_max = 0, w_min = 0, w_max = 0; - for(int i = 0; i < reg_size; ++i) + for(size_t i = 0; i < reg.size(); ++i) { double regdx = double(reg[i].x) - x; double regdy = double(reg[i].y) - y; @@ -728,7 +728,7 @@ void LineSegmentDetectorImpl::region2rect(const std::vector& reg, c if(rec.width < 1.0) rec.width = 1.0; } -double LineSegmentDetectorImpl::get_theta(const std::vector& reg, const int& reg_size, const double& x, +double LineSegmentDetectorImpl::get_theta(const std::vector& reg, const double& x, const double& y, const double& reg_angle, const double& prec) const { double Ixx = 0.0; @@ -736,7 +736,7 @@ double LineSegmentDetectorImpl::get_theta(const std::vector& reg, c double Ixy = 0.0; // Compute inertia matrix - for(int i = 0; i < reg_size; ++i) + for(size_t i = 0; i < reg.size(); ++i) { const double& regx = reg[i].x; const double& regy = reg[i].y; @@ -766,10 +766,10 @@ double LineSegmentDetectorImpl::get_theta(const std::vector& reg, c return theta; } -bool LineSegmentDetectorImpl::refine(std::vector& reg, int& reg_size, double reg_angle, +bool LineSegmentDetectorImpl::refine(std::vector& reg, double reg_angle, const double prec, double p, rect& rec, const double& density_th) { - double density = double(reg_size) / (dist(rec.x1, rec.y1, rec.x2, rec.y2) * rec.width); + double density = double(reg.size()) / (dist(rec.x1, rec.y1, rec.x2, rec.y2) * rec.width); if (density >= density_th) { return true; } @@ -780,7 +780,7 @@ bool LineSegmentDetectorImpl::refine(std::vector& reg, int& reg_siz double sum = 0, s_sum = 0; int n = 0; - for (int i = 0; i < reg_size; ++i) + for (size_t i = 0; i < reg.size(); ++i) { *(reg[i].used) = NOTUSED; if (dist(xc, yc, reg[i].x, reg[i].y) < rec.width) @@ -797,16 +797,16 @@ bool LineSegmentDetectorImpl::refine(std::vector& reg, int& reg_siz double tau = 2.0 * sqrt((s_sum - 2.0 * mean_angle * sum) / double(n) + mean_angle * mean_angle); // Try new region - region_grow(Point(reg[0].x, reg[0].y), reg, reg_size, reg_angle, tau); + region_grow(Point(reg[0].x, reg[0].y), reg, reg_angle, tau); - if (reg_size < 2) { return false; } + if (reg.size() < 2) { return false; } - region2rect(reg, reg_size, reg_angle, prec, p, rec); - density = double(reg_size) / (dist(rec.x1, rec.y1, rec.x2, rec.y2) * rec.width); + region2rect(reg, reg_angle, prec, p, rec); + density = double(reg.size()) / (dist(rec.x1, rec.y1, rec.x2, rec.y2) * rec.width); if (density < density_th) { - return reduce_region_radius(reg, reg_size, reg_angle, prec, p, rec, density, density_th); + return reduce_region_radius(reg, reg_angle, prec, p, rec, density, density_th); } else { @@ -814,7 +814,7 @@ bool LineSegmentDetectorImpl::refine(std::vector& reg, int& reg_siz } } -bool LineSegmentDetectorImpl::reduce_region_radius(std::vector& reg, int& reg_size, double reg_angle, +bool LineSegmentDetectorImpl::reduce_region_radius(std::vector& reg, double reg_angle, const double prec, double p, rect& rec, double density, const double& density_th) { // Compute region's radius @@ -828,25 +828,25 @@ bool LineSegmentDetectorImpl::reduce_region_radius(std::vector& reg { radSq *= 0.75*0.75; // Reduce region's radius to 75% of its value // Remove points from the region and update 'used' map - for(int i = 0; i < reg_size; ++i) + for (size_t i = 0; i < reg.size(); ++i) { if(distSq(xc, yc, double(reg[i].x), double(reg[i].y)) > radSq) { // Remove point from the region *(reg[i].used) = NOTUSED; - std::swap(reg[i], reg[reg_size - 1]); - --reg_size; + std::swap(reg[i], reg[reg.size() - 1]); + reg.pop_back(); --i; // To avoid skipping one point } } - if(reg_size < 2) { return false; } + if(reg.size() < 2) { return false; } // Re-compute rectangle - region2rect(reg, reg_size ,reg_angle, prec, p, rec); + region2rect(reg ,reg_angle, prec, p, rec); // Re-compute region points density - density = double(reg_size) / + density = double(reg.size()) / (dist(rec.x1, rec.y1, rec.x2, rec.y2) * rec.width); } From de9c0d992674264963bf93b76cc345ca5f6c051f Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Tue, 20 Sep 2016 15:37:25 +0100 Subject: [PATCH 5/6] LSD: Avoid re allocating the histogram for multiple calls of LineSegmentDetector::detect in ll_angle This is useful when reusing the same instance of LineSegmentDetector for multiple images --- modules/imgproc/src/lsd.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 969d617caf..a467833405 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -267,6 +267,8 @@ private: struct coorlist* next; }; + std::vector list; + struct rect { double x1, y1, x2, y2; // first and second point of the line segment @@ -306,7 +308,7 @@ private: * @param list Return: Vector of coordinate points that are pseudo ordered by magnitude. * Pixels would be ordered by norm value, up to a precision given by max_grad/n_bins. */ - void ll_angle(const double& threshold, const unsigned int& n_bins, std::vector& list); + void ll_angle(const double& threshold, const unsigned int& n_bins); /** * Grow a region starting from point s with a defined precision, @@ -438,7 +440,6 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, const double p = ANG_TH / 180; const double rho = QUANT / sin(prec); // gradient magnitude threshold - std::vector list; if(SCALE != 1) { Mat gaussian_img; @@ -449,12 +450,12 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, GaussianBlur(image, gaussian_img, ksize, sigma); // Scale image to needed size resize(gaussian_img, scaled_image, Size(), SCALE, SCALE); - ll_angle(rho, N_BINS, list); + ll_angle(rho, N_BINS); } else { scaled_image = image; - ll_angle(rho, N_BINS, list); + ll_angle(rho, N_BINS); } LOG_NT = 5 * (log10(double(img_width)) + log10(double(img_height))) / 2 + log10(11.0); @@ -518,8 +519,7 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, } void LineSegmentDetectorImpl::ll_angle(const double& threshold, - const unsigned int& n_bins, - std::vector& list) + const unsigned int& n_bins) { //Initialize data angles = Mat_(scaled_image.size()); @@ -564,7 +564,7 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold, } // Compute histogram of gradient values - list = std::vector(img_width * img_height); + list.resize(img_width * img_height); std::vector range_s(n_bins); std::vector range_e(n_bins); unsigned int count = 0; From 8283ddb52faf8950f8fb7df7943881871915014d Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Wed, 21 Sep 2016 14:57:17 +0100 Subject: [PATCH 6/6] LSD: Use a fixed size array instead of using std::vector --- modules/imgproc/src/lsd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index a467833405..e504018c15 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -964,7 +964,7 @@ double LineSegmentDetectorImpl::rect_nfa(const rect& rec) const double dyhw = rec.dy * half_width; double dxhw = rec.dx * half_width; - std::vector ordered_x(4); + edge ordered_x[4]; edge* min_y = &ordered_x[0]; edge* max_y = &ordered_x[0]; // Will be used for loop range @@ -973,7 +973,7 @@ double LineSegmentDetectorImpl::rect_nfa(const rect& rec) const ordered_x[2].p.x = int(rec.x2 + dyhw); ordered_x[2].p.y = int(rec.y2 - dxhw); ordered_x[2].taken = false; ordered_x[3].p.x = int(rec.x1 + dyhw); ordered_x[3].p.y = int(rec.y1 - dxhw); ordered_x[3].taken = false; - std::sort(ordered_x.begin(), ordered_x.end(), AsmallerB_XoverY); + std::sort(ordered_x, ordered_x + 4, AsmallerB_XoverY); // Find min y. And mark as taken. find max y. for(unsigned int i = 1; i < 4; ++i)