From: Francisco Facioni Date: Sun, 18 Sep 2016 21:32:33 +0000 (+0100) Subject: LSD: Optimization, avoid converting the image to double X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1527^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5a0b226f27fcbe949a269e897d8b41265d08ed1;p=platform%2Fupstream%2Fopencv.git LSD: Optimization, avoid converting the image to double --- diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 87afdc2..ad344ac 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