From: <hug...@li...> - 2012-06-14 15:47:21
|
branch: gui_overhaul details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgroot/hugin/hugin/rev/35cde63105dc changeset: 5855:35cde63105dc user: tmodes date: Thu Jun 14 17:46:57 2012 +0200 description: cpfind: Reduce memory usage a little bit diffstat: src/hugin_cpfind/cpfind/PanoDetectorLogic.cpp | 2 +- src/hugin_cpfind/localfeatures/Image.cpp | 58 +++++--------------------- src/hugin_cpfind/localfeatures/Image.h | 34 ++++++--------- 3 files changed, 26 insertions(+), 68 deletions(-) diffs (197 lines): diff -r 243499e28f32 -r 35cde63105dc src/hugin_cpfind/cpfind/PanoDetectorLogic.cpp --- a/src/hugin_cpfind/cpfind/PanoDetectorLogic.cpp Thu Jun 14 17:44:27 2012 +0200 +++ b/src/hugin_cpfind/cpfind/PanoDetectorLogic.cpp Thu Jun 14 17:46:57 2012 +0200 @@ -383,7 +383,7 @@ // Build integral image TRACE_IMG("Build integral image..."); - ioImgInfo._ii.init(final_img.begin(), final_img.width(),final_img.height()); + ioImgInfo._ii.init(final_img); final_img.resize(0,0); // compute distance map diff -r 243499e28f32 -r 35cde63105dc src/hugin_cpfind/localfeatures/Image.cpp --- a/src/hugin_cpfind/localfeatures/Image.cpp Thu Jun 14 17:44:27 2012 +0200 +++ b/src/hugin_cpfind/localfeatures/Image.cpp Thu Jun 14 17:46:57 2012 +0200 @@ -26,53 +26,27 @@ using namespace lfeat; using namespace std; -Image::Image(double* iPixels, unsigned int iWidth, unsigned int iHeight, bool integral) +Image::Image(vigra::DImage &img) { - init(iPixels, iWidth, iHeight, integral); + init(img); } -void Image::init(double* iPixels, unsigned int iWidth, unsigned int iHeight, bool integral) +void Image::init(vigra::DImage &img) { - typedef double* double_ptr; // store values + _width = img.width(); + _height = img.height(); - if (! integral) - { - _width = iWidth; - _height = iHeight; - _pixels = new double_ptr[iHeight]; - _pixels[0] = iPixels; - for (unsigned int i=1; i < iHeight; i++) - { - _pixels[i] = _pixels[i-1] + iWidth; - } + // allocate the integral image data + _ii = AllocateImage(_width + 1, _height + 1); - // allocate the integral image data - _ii = AllocateImage(_width + 1, _height + 1); - _own_ii = true; - - // create the integral image - buildIntegralImage(); - } - else - { - _width = iWidth -1; - _height = iHeight -1; - _pixels = 0; - // just set the integral image - _ii = new double_ptr[iHeight]; - _ii[0] = iPixels; - for (unsigned int i=1; i < iHeight; i++) - { - _ii[i] = _ii[i-1] + iWidth; - } - _own_ii = false; - } + // create the integral image + buildIntegralImage(img); } void Image::clean() { - if (_ii && _own_ii) + if (_ii) { DeallocateImage(_ii, _height + 1); } @@ -81,20 +55,14 @@ delete[] _ii; } _ii = 0; - if (_pixels) - { - delete[] _pixels; - } - _pixels = 0; } - Image::~Image() { clean(); } -void Image::buildIntegralImage() +void Image::buildIntegralImage(vigra::DImage &img) { // to make easier the later computation, shift the image by 1 pix (x and y) // so the image has a size of +1 for width and height compared to orig image. @@ -115,7 +83,7 @@ for(unsigned int i = 1; i <= _height; ++i) for(unsigned int j = 1; j <= _width; ++j) { - _ii[i][j] = _pixels[i-1][j-1] + _ii[i-1][j] + _ii[i][j-1] - _ii[i-1][j-1]; + _ii[i][j] = img[i-1][j-1] + _ii[i-1][j] + _ii[i][j-1] - _ii[i-1][j-1]; } } @@ -145,6 +113,4 @@ // delete the lines holder delete[] iImagePtr; - } - diff -r 243499e28f32 -r 35cde63105dc src/hugin_cpfind/localfeatures/Image.h --- a/src/hugin_cpfind/localfeatures/Image.h Thu Jun 14 17:44:27 2012 +0200 +++ b/src/hugin_cpfind/localfeatures/Image.h Thu Jun 14 17:46:57 2012 +0200 @@ -22,6 +22,7 @@ #define __lfeat_image_h #include "KeyPoint.h" +#include "vigra/stdimage.hxx" namespace lfeat { @@ -32,12 +33,12 @@ class LFIMPEX Image { public: - Image() : _pixels(0), _width(0), _height(0), _ii(0), _own_ii(true) {}; + Image() : _width(0), _height(0), _ii(0) {}; // Constructor from a pixel array (C style) - Image(double* iPixels, unsigned int iWidth, unsigned int iHeight, bool integral=false); + Image(vigra::DImage &img); // setup the integral image - void init(double* iPixels, unsigned int iWidth, unsigned int iHeight, bool integral=false); + void init(vigra::DImage &img); // cleanup void clean(); @@ -46,43 +47,34 @@ ~Image(); // Accessors - inline double** getPixels() - { - return _pixels; - } - inline double** getIntegralImage() + inline double** getIntegralImage() { return _ii; } - inline unsigned int getWidth() + inline unsigned int getWidth() { return _width; } - inline unsigned int getHeight() + inline unsigned int getHeight() { return _height; } // allocate and deallocate integral image pixels - static double** AllocateImage(unsigned int iWidth, unsigned int iHeight); - static void DeallocateImage(double** iImagePtr, unsigned int iHeight); + static double** AllocateImage(unsigned int iWidth, unsigned int iHeight); + static void DeallocateImage(double** iImagePtr, unsigned int iHeight); private: // prepare the integral image - void buildIntegralImage(); - - // pixel data of the image - double** _pixels; + void buildIntegralImage(vigra::DImage &img); // image size - unsigned int _width; - unsigned int _height; + unsigned int _width; + unsigned int _height; // integral image - double** _ii; // Data of the integral image Like data[lines][rows] - double _own_ii; - + double**_ii; // Data of the integral image Like data[lines][rows] }; } |