From f49f6d52b45a09a133621c3e96b77b321746452f Mon Sep 17 00:00:00 2001 From: berak Date: Tue, 7 Aug 2018 15:14:22 +0200 Subject: [PATCH] photo: avoid resizing a const Mat in decolor() --- modules/photo/src/contrast_preserve.hpp | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/photo/src/contrast_preserve.hpp b/modules/photo/src/contrast_preserve.hpp index ec8274e883..65ca9c1d3c 100644 --- a/modules/photo/src/contrast_preserve.hpp +++ b/modules/photo/src/contrast_preserve.hpp @@ -204,14 +204,19 @@ void Decolor::add_to_vector_poly(vector < vector > &polyGrad, const vec idx1++; } -void Decolor::weak_order(const Mat &img, vector &alf) const +void Decolor::weak_order(const Mat &im, vector &alf) const { - const int h = img.size().height; - const int w = img.size().width; + Mat img; + const int h = im.size().height; + const int w = im.size().width; if((h + w) > 800) { const double sizefactor = double(800)/(h+w); - resize(img, img, Size(cvRound(h*sizefactor), cvRound(w*sizefactor))); + resize(im, img, Size(cvRound(h*sizefactor), cvRound(w*sizefactor))); + } + else + { + img = im; } Mat curIm = Mat(img.size(),CV_32FC1); @@ -246,16 +251,20 @@ void Decolor::weak_order(const Mat &img, vector &alf) const alf[i] -= tmp1[i] * tmp2[i] * tmp3[i]; } -void Decolor::grad_system(const Mat &img, vector < vector < double > > &polyGrad, +void Decolor::grad_system(const Mat &im, vector < vector < double > > &polyGrad, vector < double > &Cg, vector & comb) const { - int h = img.size().height; - int w = img.size().width; - + Mat img; + int h = im.size().height; + int w = im.size().width; if((h + w) > 800) { const double sizefactor = double(800)/(h+w); - resize(img, img, Size(cvRound(h*sizefactor), cvRound(w*sizefactor))); + resize(im, img, Size(cvRound(h*sizefactor), cvRound(w*sizefactor))); + } + else + { + img = im; } h = img.size().height;