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
pull/7311/head
Francisco Facioni 8 years ago
parent ef6b696446
commit de9c0d9926
  1. 14
      modules/imgproc/src/lsd.cpp

@ -267,6 +267,8 @@ private:
struct coorlist* next; struct coorlist* next;
}; };
std::vector<coorlist> list;
struct rect struct rect
{ {
double x1, y1, x2, y2; // first and second point of the line segment 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. * @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. * 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<coorlist>& list); void ll_angle(const double& threshold, const unsigned int& n_bins);
/** /**
* Grow a region starting from point s with a defined precision, * Grow a region starting from point s with a defined precision,
@ -438,7 +440,6 @@ void LineSegmentDetectorImpl::flsd(std::vector<Vec4f>& lines,
const double p = ANG_TH / 180; const double p = ANG_TH / 180;
const double rho = QUANT / sin(prec); // gradient magnitude threshold const double rho = QUANT / sin(prec); // gradient magnitude threshold
std::vector<coorlist> list;
if(SCALE != 1) if(SCALE != 1)
{ {
Mat gaussian_img; Mat gaussian_img;
@ -449,12 +450,12 @@ void LineSegmentDetectorImpl::flsd(std::vector<Vec4f>& lines,
GaussianBlur(image, gaussian_img, ksize, sigma); GaussianBlur(image, gaussian_img, ksize, sigma);
// Scale image to needed size // Scale image to needed size
resize(gaussian_img, scaled_image, Size(), SCALE, SCALE); resize(gaussian_img, scaled_image, Size(), SCALE, SCALE);
ll_angle(rho, N_BINS, list); ll_angle(rho, N_BINS);
} }
else else
{ {
scaled_image = image; 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); LOG_NT = 5 * (log10(double(img_width)) + log10(double(img_height))) / 2 + log10(11.0);
@ -518,8 +519,7 @@ void LineSegmentDetectorImpl::flsd(std::vector<Vec4f>& lines,
} }
void LineSegmentDetectorImpl::ll_angle(const double& threshold, void LineSegmentDetectorImpl::ll_angle(const double& threshold,
const unsigned int& n_bins, const unsigned int& n_bins)
std::vector<coorlist>& list)
{ {
//Initialize data //Initialize data
angles = Mat_<double>(scaled_image.size()); angles = Mat_<double>(scaled_image.size());
@ -564,7 +564,7 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold,
} }
// Compute histogram of gradient values // Compute histogram of gradient values
list = std::vector<coorlist>(img_width * img_height); list.resize(img_width * img_height);
std::vector<coorlist*> range_s(n_bins); std::vector<coorlist*> range_s(n_bins);
std::vector<coorlist*> range_e(n_bins); std::vector<coorlist*> range_e(n_bins);
unsigned int count = 0; unsigned int count = 0;

Loading…
Cancel
Save