* arthur/xml_to_html/domitem.cc,
* arthur/xml_to_html/domitem.hh.,
* arthur/xml_to_html/dommodel.cc,
* arthur/xml_to_html/dommodel.hh: XML parsing.
* arthur/xml_to_html/patterns/css.css,
* arthur/xml_to_html/patterns/xsl.xsl: HTML patterns.
* arthur/xml_to_html/xml_to_html.cc,
* arthur/xml_to_html/xml_to_html.hh: Image cropingd XML merging.
* arthur/xml_to_html/README
* arthur/xml_to_html/xml_to_html.pro
* arthur/xml_to_html/main.cc
---
scribo/sandbox/ChangeLog | 19 ++
scribo/sandbox/arthur/xml_to_html/README | 25 ++
.../arthur/xml_to_html}/domitem.cc | 0
.../arthur/xml_to_html}/domitem.hh | 0
.../arthur/xml_to_html}/dommodel.cc | 0
.../arthur/xml_to_html}/dommodel.hh | 0
scribo/sandbox/arthur/xml_to_html/main.cc | 58 ++++
scribo/sandbox/arthur/xml_to_html/patterns/css.css | 28 ++
scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl | 229 +++++++++++++++
scribo/sandbox/arthur/xml_to_html/xml_to_html.cc | 292 ++++++++++++++++++++
.../arthur/xml_to_html/xml_to_html.hh} | 40 +--
scribo/sandbox/arthur/xml_to_html/xml_to_html.pro | 16 +
12 files changed, 683 insertions(+), 24 deletions(-)
create mode 100644 scribo/sandbox/arthur/xml_to_html/README
copy scribo/{demo/viewer => sandbox/arthur/xml_to_html}/domitem.cc (100%)
copy scribo/{demo/viewer => sandbox/arthur/xml_to_html}/domitem.hh (100%)
copy scribo/{demo/viewer => sandbox/arthur/xml_to_html}/dommodel.cc (100%)
copy scribo/{demo/viewer => sandbox/arthur/xml_to_html}/dommodel.hh (100%)
create mode 100644 scribo/sandbox/arthur/xml_to_html/main.cc
create mode 100644 scribo/sandbox/arthur/xml_to_html/patterns/css.css
create mode 100644 scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
create mode 100644 scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
copy scribo/{demo/viewer/step_widget.hh => sandbox/arthur/xml_to_html/xml_to_html.hh}
(73%)
create mode 100644 scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index f428dce..d3f537b 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,3 +1,22 @@
+2010-07-05 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
+
+ ICDAR XML to HTML.
+
+ * arthur/xml_to_html/domitem.cc,
+ * arthur/xml_to_html/domitem.hh.,
+ * arthur/xml_to_html/dommodel.cc,
+ * arthur/xml_to_html/dommodel.hh: XML parsing.
+
+ * arthur/xml_to_html/patterns/css.css,
+ * arthur/xml_to_html/patterns/xsl.xsl: HTML patterns.
+
+ * arthur/xml_to_html/xml_to_html.cc,
+ * arthur/xml_to_html/xml_to_html.hh: Image croping and XML merging.
+
+ * arthur/xml_to_html/README
+ * arthur/xml_to_html/xml_to_html.pro
+ * arthur/xml_to_html/main.cc
+
2010-06-25 Guillaume Lazzara <z(a)lrde.epita.fr>
Add algorithms to retrieve white spaces.
diff --git a/scribo/sandbox/arthur/xml_to_html/README
b/scribo/sandbox/arthur/xml_to_html/README
new file mode 100644
index 0000000..f16f472
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/README
@@ -0,0 +1,25 @@
+xml_to_html
+
+Produce HTML view from ICDAR (or LRDE extended) XML.
+
+*Compilation:
+
+ Just change the paths to olena and milena in xml_to_html.pro
+
+*Usage:
+
+ -m, --merge: Merge an XML with an other XML
+ args: <xml_file_1> <xml_file_2> [xml_output]
+
+Useful to merge LRDE XML extended mode files with ICDAR XML files to combine both images
and recognized text.
+
+
+ -c, --create-html: Crop images (if exist) from the ppm file using the XML file and
produce an html output.
+ args: <xml_file> [ppm_file] [output dir]
+
+If no PPM file is given, the program will only produce an HTML output without images.
+If a PPM file is given, the program will crop image_region, separator_region,
graphic_regions, chart_region and table_region to output_dir/img/id.png
+
+*Result:
+
+To view the result run your internet browser on output_dir/output.xml (Does not work with
Chrome on local, use a LAMPP server to fix this ;-) ).
\ No newline at end of file
diff --git a/scribo/demo/viewer/domitem.cc b/scribo/sandbox/arthur/xml_to_html/domitem.cc
similarity index 100%
copy from scribo/demo/viewer/domitem.cc
copy to scribo/sandbox/arthur/xml_to_html/domitem.cc
diff --git a/scribo/demo/viewer/domitem.hh b/scribo/sandbox/arthur/xml_to_html/domitem.hh
similarity index 100%
copy from scribo/demo/viewer/domitem.hh
copy to scribo/sandbox/arthur/xml_to_html/domitem.hh
diff --git a/scribo/demo/viewer/dommodel.cc
b/scribo/sandbox/arthur/xml_to_html/dommodel.cc
similarity index 100%
copy from scribo/demo/viewer/dommodel.cc
copy to scribo/sandbox/arthur/xml_to_html/dommodel.cc
diff --git a/scribo/demo/viewer/dommodel.hh
b/scribo/sandbox/arthur/xml_to_html/dommodel.hh
similarity index 100%
copy from scribo/demo/viewer/dommodel.hh
copy to scribo/sandbox/arthur/xml_to_html/dommodel.hh
diff --git a/scribo/sandbox/arthur/xml_to_html/main.cc
b/scribo/sandbox/arthur/xml_to_html/main.cc
new file mode 100644
index 0000000..9ec705a
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/main.cc
@@ -0,0 +1,58 @@
+#include <iostream>
+#include "xml_to_html.hh"
+
+int main(int argc, char **argv)
+{
+
+ std::string man;
+ man = "xml_to_html: ...usage\n -m, --merge: Merge an XML with an other XML\n
\targs: <xml_file_1> <xml_file_2> [xml_output]\n\n -c, --create-html: Crop
images (if exist) from the ppm file using the XML file and produce an html output.\n
\targs: <xml_file> [ppm_file] [output dir]\n";
+
+ if (argc > 2)
+ {
+ new QApplication::QApplication(argc, argv, false);
+ ImageCrop crop;
+
+ std::string merge = "--merge";
+ std::string m = "-m";
+ std::string scrop = "--create-html";
+ std::string c = "-c";
+
+ if (argc == 3 && (scrop.compare(argv[1]) == 0 || c.compare(argv[1]) == 0))
+ {
+ bool b = false;
+ b = crop.load_xml(argv[2], QString::Null());
+
+ if (b)
+ crop.find_image_regions();
+ }
+ else if (argc > 3)
+ {
+ if (merge.compare(argv[1]) == 0 || m.compare(argv[1]) == 0)
+ {
+ if (argc > 4)
+ crop.merge(argv[2], argv[3], argv[4]);
+ else
+ crop.merge(argv[2], argv[3]);
+ }
+ else if (scrop.compare(argv[1]) == 0 || c.compare(argv[1]) == 0)
+ {
+ bool b = false;
+ if (argc > 4)
+ b = crop.load_xml(argv[2], argv[3], argv[4]);
+ else
+ b = crop.load_xml(argv[2], argv[3]);
+
+ if (b)
+ crop.find_image_regions();
+ }
+ else
+ std::cout << man;
+ }
+ else
+ std::cout << man;
+ }
+ else
+ std::cout << man;
+
+ return 0;
+}
diff --git a/scribo/sandbox/arthur/xml_to_html/patterns/css.css
b/scribo/sandbox/arthur/xml_to_html/patterns/css.css
new file mode 100644
index 0000000..7171754
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/patterns/css.css
@@ -0,0 +1,28 @@
+.line
+{
+ position:absolute;
+ background-color:white;
+ z-index:7;
+ display:inline;
+ white-space:pre;
+ letter-spacing:-2px;
+ padding:0px;
+ margin:0px;
+ filter:alpha(opacity=100);
+ font-family:"Times New Roman", Times, serif;
+}
+.para
+{
+ position:absolute;
+ z-index:6;
+}
+.region
+{
+ position:absolute;
+ z-index:5;
+}
+.image
+{
+ position:absolute;
+ border:0;
+}
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
b/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
new file mode 100644
index 0000000..aa5a078
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
@@ -0,0 +1,229 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:template match="/"> <!-- "/" means the whole document
(root) -->
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
+ <title>Fooooooo !</title>
+ <link rel="stylesheet" type="text/css" href="css.css"
/>
+ </head>
+ <body>
+
+ <div class="image" style="top:0px;left:0px;">
+ <img src="../../ppm/mp00076.png" />
+ </div>
+
+ <!-- BEGIN IMAGE REGION -->
+ <xsl:for-each select="pcGts/page/graphic_region|
+ pcGts/page/image_region|
+ pcGts/page/chart_region|
+ pcGts/page/table_region|
+ pcGts/page/separator_region|
+ pcGts/page/text_region|
+ pcGts/page/text_region/paragraph|
+ pcGts/page/text_region/paragraph/line">
+
+ <!-- y1 -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- x2 -->
+ <xsl:variable name="x2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="descending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- y2 -->
+ <xsl:variable name="y2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="descending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- x1 -->
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- TEXT LINE-->
+ <xsl:if test="name() = 'line'">
+
+ <xsl:variable name="x_height">
+ <xsl:value-of select="../../@x_height" />
+ </xsl:variable>
+
+ <xsl:variable name="a_height">
+ <xsl:value-of select="../../@a_height" />
+ </xsl:variable>
+
+ <xsl:variable name="colour">
+ <xsl:choose>
+ <xsl:when test="../../@txt_colour != ''">
+ <xsl:value-of select="../../@txt_colour" />
+ </xsl:when>
+ <xsl:otherwise>
+ Black
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="d_height_tmp">
+ <xsl:value-of select="../../@d_height" />
+ </xsl:variable>
+
+ <xsl:variable name="d_height">
+ <xsl:choose>
+ <xsl:when test="$d_height_tmp < 0">
+ <xsl:value-of select="-$d_height_tmp" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d_height_tmp" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="a">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) < $d_height">
+ <xsl:value-of select="$x_height + $d_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$a_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="d">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) > $d_height">
+ <xsl:value-of select="-($a_height - $x_height)" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="d_f">
+ <xsl:choose>
+ <xsl:when test="$d < 0">
+ <xsl:value-of select="-$d" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="line"
onmouseover="this.style.opacity=0.2;this.filters.alpha.opacity=20"
+ onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100">
+ <xsl:attribute name="style">
+ opacity:1;
+ height:auto;
+ font-size:<xsl:value-of select="$a+$d_f" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1 " />px;
+ top:<xsl:value-of select="$y1 " />px;
+ color:<xsl:value-of select="$colour" />;
+ </xsl:attribute>
+ <xsl:value-of select="@text"/>
+ </div>
+ </xsl:if>
+ <!-- ENF OF TEXT LINE -->
+
+ <!-- TEXT REGION -->
+ <xsl:if test="name() = 'text_region'">
+ <div class="region">
+ <xsl:attribute name="style">
+ height:<xsl:value-of select="$y2 - $y1" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ top:<xsl:value-of select="$y1" />px;
+ </xsl:attribute>
+ </div>
+ </xsl:if>
+ <!-- ENF OF TEXT REGION -->
+
+ <!-- PARAGRAPH -->
+ <xsl:if test="name() = 'paragraph'">
+ <div class="para">
+ <xsl:attribute name="style">
+ height:<xsl:value-of select="$y2 - $y1" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ top:<xsl:value-of select="$y1" />px;
+ </xsl:attribute>
+ </div>
+ </xsl:if>
+ <!-- ENF OF PARAGRAPH -->
+
+ <!-- NON-TEXT REGIONS -->
+ <xsl:if test="name() = 'image_region' or name() =
'separator_region' or name() = 'graphic_region' or name() =
'chart_region' or name() = 'table_region'">
+
+ <!-- id -->
+ <xsl:variable name="id">
+ <xsl:value-of select="@id" />
+ </xsl:variable>
+
+ <!-- depth -->
+ <xsl:variable name="depth">
+ <xsl:choose>
+ <xsl:when test="name() = 'separator_region'">
+ 1
+ </xsl:when>
+ <xsl:otherwise>
+ 4
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="image">
+ <xsl:attribute name="style">
+ top:<xsl:value-of select="$y1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ width:<xsl:value-of select="$x2 - $x1"/>px;
+ height:<xsl:value-of select="$y2 - $y1"/>px;
+ z-index:<xsl:value-of select="$depth"/>;
+ </xsl:attribute>
+ <img>
+ <xsl:attribute name="alt">
+ <xsl:value-of select="name()" />
+ </xsl:attribute>
+ <xsl:attribute name="width">
+ <xsl:value-of select="$x2 - $x1" />
+ </xsl:attribute>
+ <xsl:attribute name="height">
+ <xsl:value-of select="$y2 - $y1" />
+ </xsl:attribute>
+ <xsl:attribute name="src">
+ img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ </img>
+ </div>
+
+ </xsl:if>
+ <!-- END NON-TEXT REGIONS -->
+ </xsl:for-each>
+ </body>
+ </html>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
b/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
new file mode 100644
index 0000000..8267466
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
@@ -0,0 +1,292 @@
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+# include "xml_to_html.hh"
+# include "dommodel.hh"
+# include <limits.h>
+
+#include <scribo/preprocessing/crop.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/core/alias/box2d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/io/magick/save.hh>
+#include <mln/io/ppm/all.hh>
+
+ImageCrop::ImageCrop():
+ regions_(false)
+{
+}
+
+ImageCrop::~ImageCrop()
+{
+}
+
+void ImageCrop::merge(QString in, QString other, QString output)
+{
+ if (in.endsWith(".xml") && other.endsWith(".xml")
&& output.endsWith(".xml"))
+ {
+ QFile f_in(in);
+ QFile f_other(other);
+ QFile f_output(output);
+
+ qDebug() << "Merging to " << output <<
"...";
+
+ f_in.open(QIODevice::ReadOnly);
+ f_other.open(QIODevice::ReadOnly);
+ f_output.open(QIODevice::ReadWrite);
+
+ QTextStream stream_in(&f_in);
+ QTextStream stream_other(&f_other);
+ QTextStream output_stream(&f_output);
+
+ QString line = stream_in.readLine();
+ output_stream << line;
+ line = stream_in.readLine();
+
+ while (!line.contains("</page>"))
+ {
+ output_stream << "\n" << line;
+ line = stream_in.readLine();
+ }
+
+ line = stream_other.readLine();
+
+ while (!line.contains("<page"))
+ line = stream_other.readLine();
+
+ line = stream_other.readLine();
+
+ while (!line.contains("</pcGts>"))
+ {
+ output_stream << "\n" << line;
+ line = stream_other.readLine();
+ }
+
+ output_stream << "\n" << line;
+
+ f_in.close();
+ f_other.close();
+ f_output.close();
+ }
+ else
+ std::cout << "merge : error, only xml files are needed." <<
std::endl;
+}
+
+bool ImageCrop::load_xml(QString xml_file, QString image_file, QString path)
+{
+ if (xml_file.endsWith(".xml") &&
(image_file.endsWith(".ppm") || image_file == QString::Null()) )
+ {
+ image_file_ = image_file;
+ regions_ = (image_file != QString::Null());
+
+ path_ = path;
+ if (!path_.endsWith("/"))
+ path_.append("/");
+
+ QDir dir(path_);
+
+ if (!dir.mkpath("img"))
+ {
+ path_ = "output/";
+ dir.mkpath(path_);
+ dir.setPath(path_);
+ dir.mkpath("img");
+ }
+
+ if (QFile::exists(xml_file))
+ {
+ QFile file(xml_file);
+ QFile output(path_ + "output.xml");
+ QFile xsl("patterns/xsl.xsl");
+ QFile css("patterns/css.css");
+ xsl.copy(path_ + "xsl.xsl");
+ css.copy(path_ + "css.css");
+
+ if (QFile::exists(path_ + "output.xml"))
+ output.remove();
+
+ output.open(QIODevice::ReadWrite);
+ file.open(QIODevice::ReadOnly);
+
+ QTextStream stream_in(&file);
+ QTextStream stream_out(&output);
+ stream_in.setCodec("UTF-8");
+ stream_out.setCodec("UTF-8");
+
+ QString line = stream_in.readLine();
+ stream_out << line;
+ stream_out << "\n<?xml-stylesheet type=\"text/xsl\"
href=\"xsl.xsl\" ?>";
+
+ // /!\ attributes of ICDAR PcGts removed.
+ line = stream_in.readLine();
+ stream_out << "\n<pcGts>";
+
+ line = stream_in.readLine();
+
+ while (!line.contains("</pcGts>"))
+ {
+ stream_out << "\n" << line;
+ line = stream_in.readLine();
+ }
+
+ stream_out << "\n" << line;
+
+ output.close();
+ file.close();
+
+ qDebug() << "Output saved to " + path_;
+
+ if (file.open(QIODevice::ReadOnly))
+ {
+ QDomDocument document;
+ if (document.setContent(&file))
+ {
+ layout_ = new DomModel(document, this);
+ }
+ else
+ qDebug() << "Error while loading the XML file, please choose
another.";
+
+ file.close();
+ }
+ }
+ return true;
+ }
+ else
+ {
+ std::cout << "Wrong files format !" << std::endl;
+ return false;
+ }
+}
+
+void ImageCrop::find_image_regions()
+{
+ if (layout_ && regions_)
+ {
+ QModelIndex pgGts = layout_->index(1, 0);
+ QModelIndex page = layout_->index(1, 0, pgGts);
+ QModelIndex region;
+ QModelIndex attributes;
+ QModelIndex coords;
+ QModelIndex point;
+ bool regions_found = false;
+ for (int i = 0; true; ++i)
+ {
+ region = layout_->index(i, 0, page);
+ attributes = layout_->index(i, 1, page);
+ QString name = layout_->data(region, Qt::DisplayRole).toString();
+ coords = layout_->index(0, 0, region);
+
+ bool is_image_region = name == QString("image_region")
+ || name == QString("graphic_region")
+ || name == QString("separator_region")
+ || name == QString("chart_region")
+ || name == QString("table_region") ;
+
+ if (!region.isValid() || !coords.isValid())
+ break;
+
+ if (is_image_region)
+ {
+
+ regions_found = true;
+ QMap<QString, QVariant> data =
+ layout_->data(attributes, Qt::UserRole).toMap();
+
+ QString id;
+ QMap<QString, QVariant>::iterator it = data.find("id");
+
+ if (it == data.end() || it.key() != "id")
+ qDebug() << "No image region.";
+
+ while (it != data.end() && it.key() == "id")
+ {
+ qDebug() << name;
+ id = it.value().toString();
+ qDebug() << it.key() + " = " + it.value().toString();
+ ++it;
+ }
+
+ int x_max = 0;
+ int y_max = 0;
+ int x_min = INT_MAX;
+ int y_min = INT_MAX;
+
+ // QVector<QMap<QString, QVariant> > vect;
+ for (int j = 0; true; ++j)
+ {
+ // Navigate to the coordinate list
+ point = layout_->index(j, 1, coords);
+ if (!point.isValid())
+ break;
+
+ QMap<QString, QVariant> data =
+ layout_->data(point, Qt::UserRole).toMap();
+ int x = data["x"].toInt();
+ int y = data["y"].toInt();
+
+ // vect << data;
+
+ if (x < x_min)
+ x_min = x;
+ if (x > x_max)
+ x_max = x;
+
+ if (y < y_min)
+ y_min = y;
+ if (y > y_max)
+ y_max = y;
+
+ }
+
+ using namespace mln;
+
+ box2d box = make::box2d(y_min, x_min, y_max, x_max);
+
+ image2d<value::rgb8> ima;
+ io::ppm::load(ima, image_file_.toStdString());
+ ima = scribo::preprocessing::crop(ima, box);
+
+ // image2d<bool> mask = make::box2d(y_min, x_min, y_max, x_max);
+ // data::fill(mask, true);
+
+ /*for (int a = 1; a < vect.size(); ++a)
+ {
+ int x = vect[a]["x"].toInt();
+ int y = vect[a]["y"].toInt();
+
+ data::fill((mask | make::box2d(y, x, y, x)).rw(), false);
+ }*/
+
+
+ // io::pbm::save(mask, "output/img/mask_" + id.toStdString());
+ io::magick::save(ima, path_.toStdString() + "img/" + id.toStdString() +
".png");
+
+ }
+ }
+
+ if (!regions_found)
+ qDebug() << "No regions found.";
+ }
+}
diff --git a/scribo/demo/viewer/step_widget.hh
b/scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
similarity index 73%
copy from scribo/demo/viewer/step_widget.hh
copy to scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
index 829f814..27a271e 100644
--- a/scribo/demo/viewer/step_widget.hh
+++ b/scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
@@ -23,35 +23,27 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-
-#ifndef STEP_WIDGET_HH_
-# define STEP_WIDGET_HH_
+#ifndef IMAGE_CROP_HH
+# define IMAGE_CROP_HH
# include <QtGui>
-typedef QMap<QString, QString> StepQMap;
+class DomModel;
-class StepWidget
- : public QWidget
+class ImageCrop : public QObject
{
Q_OBJECT
-
-public:
- StepWidget();
- ~StepWidget();
- void add_element(const QString& element);
-
-signals:
- void load_image(QString);
- void load_xml(QString);
-
-public slots:
- void fill_steps(QString file);
- void activate(QListWidgetItem* item);
-
-private:
- QListWidget* view_;
- StepQMap map_;
+ public:
+ ImageCrop();
+ ~ImageCrop();
+ void merge(QString in, QString other, QString output = "output.xml");
+ bool load_xml(QString xml_file, QString image_file = "", QString path =
"output");
+ void find_image_regions();
+ private:
+ DomModel* layout_;
+ QString image_file_;
+ QString path_;
+ bool regions_;
};
-#endif /* !STEP_WIDGET_HH_ */
+#endif /* !IMAGE_CROP_HH */
diff --git a/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
b/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
new file mode 100644
index 0000000..b43b527
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
@@ -0,0 +1,16 @@
+######################################################################
+# Automatically generated by qmake (2.01a) lun. juil. 5 16:53:31 2010
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/olena/milena
-I/amd/beyrouth/home/lrde/stage/crepin/olena/
+QT += xml
+LIBS += `Magick++-config --libs`
+
+
+# Input
+HEADERS += domitem.hh dommodel.hh xml_to_html.hh
+SOURCES += domitem.cc dommodel.cc main.cc xml_to_html.cc
--
1.5.6.5