Commit 738511d2 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Improve image cropping in xml_transform.

	* arthur/xml_transform/image_crop.cc,
	* arthur/xml_transform/image_crop.hh: Load the input image only
	once.

	* arthur/xml_transform/main.cc: Undef MLN_WO_GLOBAL_VARS macro.

	* arthur/xml_transform/xml_transform.pro: Enable
	MLN_WO_GLOBAL_VARS macro.
parent 24d74ffb
2010-11-18 Guillaume Lazzara <z@lrde.epita.fr>
Improve image cropping in xml_transform.
* arthur/xml_transform/image_crop.cc,
* arthur/xml_transform/image_crop.hh: Load the input image only
once.
* arthur/xml_transform/main.cc: Undef MLN_WO_GLOBAL_VARS macro.
* arthur/xml_transform/xml_transform.pro: Enable
MLN_WO_GLOBAL_VARS macro.
2010-09-02 Guillaume Lazzara <z@lrde.epita.fr> 2010-09-02 Guillaume Lazzara <z@lrde.epita.fr>
* arthur/xml_transform/xml_transform.pro: Define NDEBUG at compile * arthur/xml_transform/xml_transform.pro: Define NDEBUG at compile
......
...@@ -23,11 +23,7 @@ ...@@ -23,11 +23,7 @@
// exception does not however invalidate any other reasons why the // exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License. // executable file might be covered by the GNU General Public License.
# include "image_crop.hh" #include <limits.h>
# include "loader.hh"
# include "common.hh"
# include <limits.h>
#include <scribo/preprocessing/crop.hh> #include <scribo/preprocessing/crop.hh>
#include <mln/value/rgb8.hh> #include <mln/value/rgb8.hh>
...@@ -37,12 +33,18 @@ ...@@ -37,12 +33,18 @@
#include <mln/io/magick/load.hh> #include <mln/io/magick/load.hh>
#include <mln/io/ppm/all.hh> #include <mln/io/ppm/all.hh>
#include "image_crop.hh"
#include "loader.hh"
#include "common.hh"
ImageCrop::ImageCrop(const QString& xml, const QString& img, ImageCrop::ImageCrop(const QString& xml, const QString& img,
const QString& output) const QString& output)
: xml_(xml), : xml_(xml),
image_(img), image_(img),
output_dir_(output) output_dir_(output)
{ {
mln::io::magick::load(ima_, image_.toStdString());
} }
ImageCrop::~ImageCrop() ImageCrop::~ImageCrop()
...@@ -53,12 +55,7 @@ ImageCrop::~ImageCrop() ...@@ -53,12 +55,7 @@ ImageCrop::~ImageCrop()
/* Save image to PNG format in output_dir/img. */ /* Save image to PNG format in output_dir/img. */
void ImageCrop::save_image(const QString& out) void ImageCrop::save_image(const QString& out)
{ {
using namespace mln; mln::io::magick::save(ima_, out.toStdString());
image2d<value::rgb8> ima;
io::magick::load(ima, image_.toStdString());
io::magick::save(ima, out.toStdString());
} }
/* Return the image in base 64. */ /* Return the image in base 64. */
...@@ -315,9 +312,7 @@ bool ImageCrop::crop_regions(bool temp) ...@@ -315,9 +312,7 @@ bool ImageCrop::crop_regions(bool temp)
using namespace mln; using namespace mln;
box2d box = make::box2d(y_min, x_min, y_max, x_max); box2d box = make::box2d(y_min, x_min, y_max, x_max);
image2d<value::rgb8> ima; image2d<value::rgb8> crop = scribo::preprocessing::crop(ima_, box);
io::magick::load(ima, image_.toStdString());
ima = scribo::preprocessing::crop(ima, box);
if (temp) if (temp)
{ {
...@@ -325,10 +320,10 @@ bool ImageCrop::crop_regions(bool temp) ...@@ -325,10 +320,10 @@ bool ImageCrop::crop_regions(bool temp)
tmp.open(); tmp.open();
region_map_[id] = tmp.fileName(); region_map_[id] = tmp.fileName();
tmp.setAutoRemove(false); tmp.setAutoRemove(false);
io::magick::save(ima, tmp.fileName().toStdString()); io::magick::save(crop, tmp.fileName().toStdString());
} }
else else
io::magick::save(ima, QString(output_dir_ + id + ".png").toStdString()); io::magick::save(crop, QString(output_dir_ + id + ".png").toStdString());
} }
region = region.nextSibling(); region = region.nextSibling();
} }
......
...@@ -23,12 +23,16 @@ ...@@ -23,12 +23,16 @@
// exception does not however invalidate any other reasons why the // exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License. // executable file might be covered by the GNU General Public License.
#ifndef IMAGE_CROP_HH #ifndef IMAGE_CROP_HH
# define IMAGE_CROP_HH # define IMAGE_CROP_HH
#include <QDomDocument> # include <QDomDocument>
# include <QtCore> # include <QtCore>
# include <mln/value/rgb8.hh>
# include <mln/core/image/image2d.hh>
class DomModel; class DomModel;
class ImageCrop : public QObject class ImageCrop : public QObject
...@@ -36,17 +40,6 @@ class ImageCrop : public QObject ...@@ -36,17 +40,6 @@ class ImageCrop : public QObject
Q_OBJECT Q_OBJECT
public: public:
<<<<<<< HEAD
ImageCrop(QString, QString, QString);
~ImageCrop();
void save_image(QString);
bool crop_regions(bool temp = false);
QString img_to_base64();
bool img_from_base64(QString, QString);
void to_base64(QString, bool);
=======
ImageCrop(const QString&, const QString&, const QString&); ImageCrop(const QString&, const QString&, const QString&);
~ImageCrop(); ~ImageCrop();
...@@ -56,7 +49,6 @@ class ImageCrop : public QObject ...@@ -56,7 +49,6 @@ class ImageCrop : public QObject
QString img_to_base64(); QString img_to_base64();
bool img_from_base64(const QString&, const QString&); bool img_from_base64(const QString&, const QString&);
void to_base64(const QString&, bool); void to_base64(const QString&, bool);
>>>>>>> 6f0918c... Add missing const references to function arguments.
void from_base64(); void from_base64();
...@@ -65,6 +57,7 @@ private: ...@@ -65,6 +57,7 @@ private:
QString image_; QString image_;
QString output_dir_; QString output_dir_;
QMap<QString, QString> region_map_; QMap<QString, QString> region_map_;
mln::image2d<mln::value::rgb8> ima_;
}; };
#endif /* !IMAGE_CROP_HH */ #endif /* !IMAGE_CROP_HH */
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#include <Magick++.h> #include <Magick++.h>
#undef MLN_WO_GLOBAL_VARS
#include <mln/core/image/image2d.hh>
#include "xml_transform.hh" #include "xml_transform.hh"
int main(int argc, char **argv) int main(int argc, char **argv)
......
...@@ -6,12 +6,12 @@ TEMPLATE = app ...@@ -6,12 +6,12 @@ TEMPLATE = app
TARGET = TARGET =
DEPENDPATH += . DEPENDPATH += .
INCLUDEPATH += . INCLUDEPATH += .
QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/milena -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/ QMAKE_CXXFLAGS += -I../../../../milena -I../../../../scribo
DEFINES += NDEBUG DEFINES += NDEBUG MLN_WO_GLOBAL_VARS
QT += xml QT += xml
LIBS += `Magick++-config --libs` LIBS += `Magick++-config --libs`
# Input
HEADERS += common.hh image_crop.hh loader.hh xml_transform.hh HEADERS += common.hh image_crop.hh loader.hh xml_transform.hh
SOURCES += common.cc image_crop.cc loader.cc main.cc xml_transform.cc SOURCES += common.cc image_crop.cc loader.cc main.cc xml_transform.cc
PWD +=
QMAKE_POST_LINK += cp -r $$PWD/templates $$OUT_PWD
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment