
--- Test2/test2.h | 2 +- XmlParser/XmlParser.pro | 22 ++++- XmlParser/XmlParser.pro.user | 36 ++++---- XmlParser/configs.cpp | 134 +++++++++++++++++++++++++++++ XmlParser/configs.h | 39 +++++++++ XmlParser/demodir.h | 7 ++ XmlParser/dir.h | 7 ++ XmlParser/main.cpp | 11 ++- XmlParser/mainwindow.cpp | 52 +++++++++--- XmlParser/mainwindow.h | 11 ++- XmlParser/mainwindow.ui | 8 +- XmlParser/polygonitem.h | 3 +- XmlParser/preprocess.cpp | 11 +++ XmlParser/preprocess.h | 26 ++++++ XmlParser/process.cpp | 21 +++++ XmlParser/process.h | 29 ++++++ XmlParser/progressdialog.cpp | 22 +++++ XmlParser/progressdialog.h | 19 ++++ XmlParser/region.h | 12 +++- XmlParser/runner.cpp | 193 +++++++++++++++++++++++++++++++++++++++++- XmlParser/runner.h | 34 +++++++- XmlParser/scene.h | 8 +- XmlParser/toolbar.cpp | 22 ++++- XmlParser/toolbar.h | 14 +++- XmlParser/xml.cpp | 20 ++-- 25 files changed, 697 insertions(+), 66 deletions(-) create mode 100644 XmlParser/configs.cpp create mode 100644 XmlParser/configs.h create mode 100644 XmlParser/demodir.h create mode 100644 XmlParser/dir.h create mode 100644 XmlParser/preprocess.cpp create mode 100644 XmlParser/preprocess.h create mode 100644 XmlParser/process.cpp create mode 100644 XmlParser/process.h create mode 100644 XmlParser/progressdialog.cpp create mode 100644 XmlParser/progressdialog.h diff --git a/Test2/test2.h b/Test2/test2.h index 9007d2d..02c2534 100644 --- a/Test2/test2.h +++ b/Test2/test2.h @@ -11,7 +11,7 @@ namespace Ui { - class Test2; + class Test2 } class Test2 : public QMainWindow { diff --git a/XmlParser/XmlParser.pro b/XmlParser/XmlParser.pro index 812902d..e65b72a 100644 --- a/XmlParser/XmlParser.pro +++ b/XmlParser/XmlParser.pro @@ -4,7 +4,13 @@ QT += xml TARGET = XmlParser TEMPLATE = app -INCLUDEPATH += /lrde/home/stage/froger_a/olena/milena/ +INCLUDEPATH += /lrde/home/stage/froger_a/olena/milena/ \ + /lrde/home/stage/froger_a/olena/scribo/ +QMAKE_CXXFLAGS += -DNDEBUG \ + -DMLN_WO_GLOBAL_VARS +LIBS += -I/usr/include/graphicsImage \ + -lGraphicsMagick++ \ + -ltesseract_full SOURCES += main.cpp \ mainwindow.cpp \ xml.cpp \ @@ -12,7 +18,11 @@ SOURCES += main.cpp \ selection.cpp \ polygonitem.cpp \ runner.cpp \ - toolbar.cpp + toolbar.cpp \ + process.cpp \ + preprocess.cpp \ + configs.cpp \ + progressdialog.cpp HEADERS += mainwindow.h \ region.h \ xml.h \ @@ -20,5 +30,11 @@ HEADERS += mainwindow.h \ selection.h \ polygonitem.h \ runner.h \ - toolbar.h + toolbar.h \ + demodir.h \ + process.h \ + preprocess.h \ + configs.h \ + dir.h \ + progressdialog.h FORMS += mainwindow.ui diff --git a/XmlParser/XmlParser.pro.user b/XmlParser/XmlParser.pro.user index bd2e795..0b03fae 100644 --- a/XmlParser/XmlParser.pro.user +++ b/XmlParser/XmlParser.pro.user @@ -76,14 +76,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-1aju09G1Pe,guid=69ec02ba8a70eadde9e5182600601b23</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-jXUCLOmOZn,guid=4585eaa0c02f09d20a77bf8f006153a8</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-792wyb</value> - <value type="QString">GNOME_KEYRING_PID=10096</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-aTERin</value> + <value type="QString">GNOME_KEYRING_PID=8076</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -95,16 +95,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=10171</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-VVXGf10105/agent.10105</value> + <value type="QString">SSH_AGENT_PID=8151</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-wrZmtE8085/agent.8085</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=16777252</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm1TO0QW</value> + <value type="QString">WINDOWID=10485796</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm4ATXQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358346215.20665-174033780</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358426220.205793-1492047644</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -128,14 +128,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-1aju09G1Pe,guid=69ec02ba8a70eadde9e5182600601b23</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-jXUCLOmOZn,guid=4585eaa0c02f09d20a77bf8f006153a8</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-792wyb</value> - <value type="QString">GNOME_KEYRING_PID=10096</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-aTERin</value> + <value type="QString">GNOME_KEYRING_PID=8076</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -147,16 +147,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=10171</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-VVXGf10105/agent.10105</value> + <value type="QString">SSH_AGENT_PID=8151</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-wrZmtE8085/agent.8085</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=16777252</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm1TO0QW</value> + <value type="QString">WINDOWID=10485796</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm4ATXQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358346215.20665-174033780</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1358426220.205793-1492047644</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> diff --git a/XmlParser/configs.cpp b/XmlParser/configs.cpp new file mode 100644 index 0000000..59df3db --- /dev/null +++ b/XmlParser/configs.cpp @@ -0,0 +1,134 @@ +#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> +#include "configs.h" +#include "region.h" + +Configs::Configs() + : QSettings("Olena-Scribo", "viewer") +{ +} + +Configs * Configs::getInstance() +{ + static Configs * conf = new Configs(); + return conf; +} + +bool Configs::preprocessingSubsample() +{ + return value("preprocessing/subsample", false).toBool(); +} + +void Configs::setPreprocessingSubsample(bool b) +{ + setValue("preprocessing/subsample", b); +} + +bool Configs::preprocessingRemoveBg() +{ + return value("preprocessing/remove_bg", false).toBool(); +} + +void Configs::setPreprocessingRemoveBg(bool b) +{ + setValue("preprocessing/remove_bg", b); +} + +bool Configs::preprocessingDeskew() +{ + return value("preprocessing/deskew", false).toBool(); +} + +void Configs::setPreprocessingDeskew(bool b) +{ + setValue("preprocessing/deskew", b); +} + +bool Configs::preprocessingRemoveNoise() +{ + return value("preprocessing/remove_noise", true).toBool(); +} + +void Configs::setPreprocessingRemoveNoise(bool b) +{ + setValue("preprocessing/remove_noise", b); +} + +int Configs::preprocessingBinAlgo() +{ + return value("preprocessing/bin_algo", scribo::toolchain::internal::SauvolaMs).toInt(); +} + +void Configs::setPreprocessingBinAlgo(int algo) +{ + setValue("preprocessing/bin_algo", algo); +} + +int Configs::segmentationFindSeps() +{ + return value("segmentation/find_seps", Separator::Both).toInt(); +} + +void Configs::setSegmentationFindSeps(int seps) +{ + setValue("segmentation/find_seps", seps); +} + +bool Configs::ocrEnabled() +{ + return value("ocr/enabled", true).toBool(); +} + +void Configs::setOcrEnabled(bool b) +{ + setValue("ocr/enabled", b); +} + +QString Configs::ocrLanguage() +{ + return value("ocr/language", 0).toString(); +} + +void Configs::setOcrLanguage(const QString &lang) +{ + setValue("ocr/language", lang); +} + +bool Configs::generalSaveXmlEnabled() +{ + return value("general/save_xml/enabled", true).toBool(); +} + +void Configs::setGeneralSaveXmlEnabled(bool b) +{ + setValue("general/save_xml/enabled", b); +} + +bool Configs::generalSaveXmlSameDir() +{ + return value("general/save_xml/same_dir", true).toBool(); +} + +void Configs::setGeneralSaveXmlSameDir(bool b) +{ + setValue("general/save_xml/same_dir", b); +} + +bool Configs::generalSaveXmlCustomDir() +{ + return value("general/save_xml/custom_dir", false).toBool(); +} + +void Configs::setGeneralSaveXmlCustomDir(bool b) +{ + setValue("general/save_xml/custom_dir", b); +} + +QString Configs::generalSaveXmlCustomDirPath() +{ + return value("general/save_xml/custom_dir_path", QDir::tempPath()).toString(); +} + +void Configs::setGeneralSaveXmlCustomDirPath(const QString &path) +{ + setValue("general/save_xml/custom_dir_path", path); +} diff --git a/XmlParser/configs.h b/XmlParser/configs.h new file mode 100644 index 0000000..6677527 --- /dev/null +++ b/XmlParser/configs.h @@ -0,0 +1,39 @@ +#ifndef CONFIGS_H +#define CONFIGS_H + +#include <QSettings> +#include <QDir> + +class Configs : + public QSettings +{ + public: + Configs(); + static Configs * getInstance(); + bool preprocessingSubsample(); + void setPreprocessingSubsample(bool b); + bool preprocessingRemoveBg(); + void setPreprocessingRemoveBg(bool b); + bool preprocessingDeskew(); + void setPreprocessingDeskew(bool b); + bool preprocessingRemoveNoise(); + void setPreprocessingRemoveNoise(bool b); + int preprocessingBinAlgo(); + void setPreprocessingBinAlgo(int algo); + int segmentationFindSeps(); + void setSegmentationFindSeps(int seps); + bool ocrEnabled(); + void setOcrEnabled(bool b); + QString ocrLanguage(); + void setOcrLanguage(const QString& lang); + bool generalSaveXmlEnabled(); + void setGeneralSaveXmlEnabled(bool b); + bool generalSaveXmlSameDir(); + void setGeneralSaveXmlSameDir(bool b); + bool generalSaveXmlCustomDir(); + void setGeneralSaveXmlCustomDir(bool b); + QString generalSaveXmlCustomDirPath(); + void setGeneralSaveXmlCustomDirPath(const QString& path); +}; + +#endif // CONFIGS_H diff --git a/XmlParser/demodir.h b/XmlParser/demodir.h new file mode 100644 index 0000000..4182ace --- /dev/null +++ b/XmlParser/demodir.h @@ -0,0 +1,7 @@ +#ifndef DEMODIR_H +#define DEMODIR_H + +# define SCRIBO_PREFIX_BINDIR "/usr/local/bin" +# define SCRIBO_LOCAL_DEMODIR "/lrde/home/stage/froger_a/olena/_build/scribo/demo" + +#endif // DEMODIR_H diff --git a/XmlParser/dir.h b/XmlParser/dir.h new file mode 100644 index 0000000..cb951f1 --- /dev/null +++ b/XmlParser/dir.h @@ -0,0 +1,7 @@ +#ifndef DIR_H +#define DIR_H + +#define SCRIBO_PREFIX_BINDIR "/usr/local/bin" +#define SCRIBO_LOCAL_DEMODIR "/lrde/home/stage/froger_a/olena/_build/scribo/demo" + +#endif // DIR_H diff --git a/XmlParser/main.cpp b/XmlParser/main.cpp index 6e7efd9..53ec79f 100644 --- a/XmlParser/main.cpp +++ b/XmlParser/main.cpp @@ -1,8 +1,17 @@ +#undef MLN_WO_GLOBAL_VARS + +#include <mln/labeling/colorize.hh> +#include <mln/math/pi.hh> +#include <mln/io/magick/load.hh> +#include <mln/literal/colors.hh> +#include <mln/debug/filename.hh> +#include <scribo/make/debug_filename.hh> #include <QtGui/QApplication> #include "mainwindow.h" -int main(int argc, char *argv[]) +int main(int argc, char **argv) { + Magick::InitializeMagick(*argv); QApplication a(argc, argv); MainWindow w; w.show(); diff --git a/XmlParser/mainwindow.cpp b/XmlParser/mainwindow.cpp index 6ad5237..eb461fc 100644 --- a/XmlParser/mainwindow.cpp +++ b/XmlParser/mainwindow.cpp @@ -1,22 +1,29 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(ui->groupBox); - layout->addWidget(ui->textEdit); - setLayout(layout); + imagePath = QString::null; QVBoxLayout *gBLayout = new QVBoxLayout; gBLayout->addWidget(ui->graphicsView); ui->groupBox->setLayout(gBLayout); - Scene *scene = new Scene(ui->graphicsView); + scene = new Scene(ui->graphicsView); scene->setSceneRect(ui->graphicsView->geometry()); ui->graphicsView->setScene(scene); Xml::parseItems("/tmp/mp00082c_gui.xml", scene); + ToolBar *toolBar = new ToolBar(this); + toolBar->setGeometry(0, ui->menuBar->height(), ui->menuBar->width(), 30); + connect(toolBar->openAction(), SIGNAL(triggered()), this, SLOT(on_actionOpen_triggered())); + connect(toolBar->quitAction(), SIGNAL(triggered()), this, SLOT(close())); + connect(toolBar->segmentAction(), SIGNAL(triggered()), this, SLOT(onSegmentation())); + progressDialog = new ProgressDialog(this); + connect(&runner, SIGNAL(finished(QString*)), this, SLOT(onEndSegmentation(QString*))); + connect(&runner, SIGNAL(new_progress_max_value(int)), progressDialog, SLOT(setMaximum(int))); + connect(&runner, SIGNAL(new_progress_label(QString)), progressDialog, SLOT(setLabelText(QString))); + connect(&runner, SIGNAL(progress()), progressDialog, SLOT(run())); } MainWindow::~MainWindow() @@ -39,13 +46,32 @@ void MainWindow::changeEvent(QEvent *e) void MainWindow::on_actionOpen_triggered() { - QPixmap pixmap(QFileDialog::getOpenFileName(this)); - QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap); - pixmapItem->setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, true); - pixmapItem->setZValue(-1); - pixmapItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - ui->graphicsView->scene()->setSceneRect(pixmap.rect()); - ui->graphicsView->scene()->addItem(pixmapItem); + imagePath = QFileDialog::getOpenFileName(this); + if(imagePath != "") + { + QPixmap pixmap(imagePath); + QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap); + pixmapItem->setFlag(QGraphicsItem::ItemNegativeZStacksBehindParent, true); + pixmapItem->setZValue(-1); + pixmapItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + ui->graphicsView->scene()->setSceneRect(pixmap.rect()); + ui->graphicsView->scene()->addItem(pixmapItem); + } +} + +void MainWindow::onSegmentation() +{ + if(imagePath != "") + { + progressDialog->reset(); + runner.start_demat(imagePath); + } +} + +void MainWindow::onEndSegmentation(QString *filename) +{ + progressDialog->close(); + Xml::parseItems(*filename, scene); } /*void MainWindow::on_action(QString& string) diff --git a/XmlParser/mainwindow.h b/XmlParser/mainwindow.h index 47103a3..6deccc7 100644 --- a/XmlParser/mainwindow.h +++ b/XmlParser/mainwindow.h @@ -5,9 +5,13 @@ #include <QGraphicsView> #include <QVBoxLayout> #include <QFileDialog> +#include <QProgressDialog> #include "scene.h" +#include "toolbar.h" #include "xml.h" #include "polygonitem.h" +#include "runner.h" +#include "progressdialog.h" namespace Ui { @@ -28,11 +32,16 @@ class MainWindow : private: Ui::MainWindow *ui; + Scene * scene; + ProgressDialog *progressDialog; + QString imagePath; + Runner runner; private slots: void on_actionOpen_triggered(); + void onSegmentation(); + void onEndSegmentation(QString *filename); //void on_action(QString& string); }; #endif // MAINWINDOW_H - diff --git a/XmlParser/mainwindow.ui b/XmlParser/mainwindow.ui index 3340356..8e57fa3 100644 --- a/XmlParser/mainwindow.ui +++ b/XmlParser/mainwindow.ui @@ -20,8 +20,8 @@ <widget class="QTextEdit" name="textEdit"> <property name="geometry"> <rect> - <x>110</x> - <y>650</y> + <x>120</x> + <y>670</y> <width>811</width> <height>75</height> </rect> @@ -30,8 +30,8 @@ <widget class="QGroupBox" name="groupBox"> <property name="geometry"> <rect> - <x>40</x> - <y>10</y> + <x>30</x> + <y>50</y> <width>971</width> <height>591</height> </rect> diff --git a/XmlParser/polygonitem.h b/XmlParser/polygonitem.h index 70ad085..c46fcb4 100644 --- a/XmlParser/polygonitem.h +++ b/XmlParser/polygonitem.h @@ -5,7 +5,8 @@ #include <QPen> class PolygonItem : - public QObject, public QGraphicsPolygonItem + public QObject, + public QGraphicsPolygonItem { Q_OBJECT diff --git a/XmlParser/preprocess.cpp b/XmlParser/preprocess.cpp new file mode 100644 index 0000000..f012d88 --- /dev/null +++ b/XmlParser/preprocess.cpp @@ -0,0 +1,11 @@ +#include "preprocess.h" + +void Preprocess::on_progress() +{ + emit progress(); +} + +void Preprocess::on_new_progress_label(const char *label) +{ + emit newProgressLabel(QString(label)); +} diff --git a/XmlParser/preprocess.h b/XmlParser/preprocess.h new file mode 100644 index 0000000..0ca01d3 --- /dev/null +++ b/XmlParser/preprocess.h @@ -0,0 +1,26 @@ +#ifndef PREPROCESS_H +#define PREPROCESS_H + +#include <QObject> +#include <mln/core/image/image2d.hh> +#include <mln/value/rgb8.hh> +#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> + +using namespace scribo::toolchain::internal; + +class Preprocess : + public QObject, + public text_in_doc_preprocess_functor<mln::image2d<mln::value::rgb8> > +{ + Q_OBJECT + + public: + virtual void on_progress(); + virtual void on_new_progress_label(const char *label); + + signals: + void newProgressLabel(const QString& label); + void progress(); +}; + +#endif // PREPROCESS_H diff --git a/XmlParser/process.cpp b/XmlParser/process.cpp new file mode 100644 index 0000000..bd37480 --- /dev/null +++ b/XmlParser/process.cpp @@ -0,0 +1,21 @@ +#include "process.h" + +Process::Process(const char *doc_filename) + : superT(doc_filename) +{ +} + +void Process::on_progress() +{ + emit progress(); +} + +void Process::on_new_progress_label(const char *label) +{ + emit newProgressLabel(QString(label)); +} + +void Process::on_xml_saved() +{ + emit xmlSaved(QString(output_file.c_str())); +} diff --git a/XmlParser/process.h b/XmlParser/process.h new file mode 100644 index 0000000..2759d00 --- /dev/null +++ b/XmlParser/process.h @@ -0,0 +1,29 @@ +#ifndef PROCESS_H +#define PROCESS_H + +#include <QObject> +#include <mln/core/image/image2d.hh> +#include <scribo/toolchain/internal/content_in_doc_functor.hh> + +using namespace scribo::toolchain::internal; + +struct Process : + public QObject, + public content_in_doc_functor<mln::image2d<bool> > +{ + Q_OBJECT + typedef content_in_doc_functor<mln::image2d<bool> > superT; + + public : + explicit Process(const char *docFilename); + virtual void on_progress(); + virtual void on_new_progress_label(const char *label); + virtual void on_xml_saved(); + + signals: + void newProgressLabel(const QString& label); + void progress(); + void xmlSaved(const QString& filename); +}; + +#endif // PROCESS_H diff --git a/XmlParser/progressdialog.cpp b/XmlParser/progressdialog.cpp new file mode 100644 index 0000000..386aaa6 --- /dev/null +++ b/XmlParser/progressdialog.cpp @@ -0,0 +1,22 @@ +#include "progressdialog.h" + +ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags flags): + QProgressDialog(parent, flags) +{ + setModal(true); + setAutoClose(false); + setCancelButton(0); + hide(); +} + +void ProgressDialog::run() +{ + setValue(value()+1); +} + +void ProgressDialog::reset() +{ + setValue(0); + setLabelText(""); + show(); +} diff --git a/XmlParser/progressdialog.h b/XmlParser/progressdialog.h new file mode 100644 index 0000000..d1d1a20 --- /dev/null +++ b/XmlParser/progressdialog.h @@ -0,0 +1,19 @@ +#ifndef PROGRESSDIALOG_H +#define PROGRESSDIALOG_H + +#include <QProgressDialog> + +class ProgressDialog : + public QProgressDialog +{ + Q_OBJECT + + public: + explicit ProgressDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0); + void reset(); + + public slots: + void run(); +}; + +#endif // PROGRESSDIALOG_H diff --git a/XmlParser/region.h b/XmlParser/region.h index 21d67d8..0741177 100644 --- a/XmlParser/region.h +++ b/XmlParser/region.h @@ -15,7 +15,7 @@ namespace GraphicRegion enum Id { - Text = 0, + Text, Line, Baseline, Meanline, @@ -32,4 +32,14 @@ namespace GraphicRegion }; } +namespace Separator +{ + enum FindSeparator + { + Lines, + Whitespaces, + Both + }; +} + #endif // REGION_H diff --git a/XmlParser/runner.cpp b/XmlParser/runner.cpp index 3f91319..7ad62fa2 100644 --- a/XmlParser/runner.cpp +++ b/XmlParser/runner.cpp @@ -1,6 +1,195 @@ #include "runner.h" -Runner::Runner(QObject *parent): - QThread(parent) +using namespace mln; +using namespace scribo::toolchain::internal; + +static QString get_pathto(const QString& file, const QString localdirsuffix = QString()) +{ + QFile f(SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix + "/" + file); + if (f.exists()) + return SCRIBO_LOCAL_DEMODIR "/" + localdirsuffix; + f.setFileName(SCRIBO_PREFIX_BINDIR "/" + file); + if (f.exists()) + return SCRIBO_PREFIX_BINDIR; + + //qDebug() << "FATAL ERROR: Can't locate file: " + file; + + return ""; +} + +Runner::Runner(QObject *parent) + : QThread(parent) +{ + moveToThread(this); +} + +void Runner::run() +{ + switch(mode_) + { + default: + case Demat: + { + image2d<value::rgb8> ima; + io::magick::load(ima, args_.at(0).toUtf8().constData()); + image2d<bool> bin_ima = preprocess(ima); + emit finished(&process(ima, bin_ima)); + } + break; + + case Export: + export_as(); + break; + } + //qDebug() << "Done."; +} + +void Runner::stop() +{ + terminate(); +} + +// Demat related stuff +void Runner::start_demat(const QString& filename) +{ + args_.clear(); + args_ << filename; + mode_ = Demat; + QThread::start(); +} + + +image2d<bool> Runner::preprocess(const image2d<value::rgb8>& ima) +{ + emit new_step("Preprocessing"); + Preprocess f; + + // Load config. + Configs * const conf = Configs::getInstance(); + + connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); + connect(&f, SIGNAL(newProgressLabel(QString)), + this, SIGNAL(new_progress_label(const QString&))); + + f.enable_subsample = conf->preprocessingSubsample(); + f.enable_fg_extraction = conf->preprocessingRemoveBg(); + f.enable_deskew = conf->preprocessingDeskew(); + f.enable_denoising = conf->preprocessingRemoveNoise(); + + f.binarization_algo = static_cast<Binarization_Algo>(conf->preprocessingBinAlgo()); + + emit new_progress_max_value(f.nsteps()); + + // Perform preprocessing. + f(ima); + + //qDebug() << "Preprocess Done."; + return f.output; +} + + +void Runner::process(const image2d<value::rgb8>& original_ima, + const image2d<bool>& processed_ima) +{ + emit new_step("Page segmentation"); + + Process f(args_.at(0).toUtf8().constData()); + + connect(&f, SIGNAL(progress()), this, SIGNAL(progress())); + connect(&f, SIGNAL(newProgressLabel(QString)), + this, SIGNAL(new_progress_label(QString))); + connect(&f, SIGNAL(xmlSaved(QString)), + this, SIGNAL(xml_saved(const QString&))); + + // Load config. + Configs * const conf = Configs::getInstance(); + + Separator::FindSeparator find_seps = static_cast<Separator::FindSeparator>(conf->segmentationFindSeps()); + f.enable_line_seps = (find_seps == Separator::Lines + || find_seps == Separator::Both); + f.enable_whitespace_seps = (find_seps == Separator::Whitespaces + || find_seps == Separator::Both); + f.enable_ocr = conf->ocrEnabled(); + f.ocr_language = conf->ocrLanguage().toAscii().data(); + f.xml_format = scribo::io::xml::PageExtended; + + + f.save_doc_as_xml = true; + QFileInfo file(args_.at(0)); + QString output_dir = QDir::tempPath(); + if (conf->generalSaveXmlEnabled()) + { + if (conf->generalSaveXmlSameDir()) + output_dir = file.absolutePath(); + else if (conf->generalSaveXmlCustomDir()) + output_dir = conf->generalSaveXmlCustomDirPath(); + //else + //qDebug() << "runner::progress - Invalid xml saving option!"; + + QDir dir(output_dir); + if (!dir.exists() && !dir.mkpath(output_dir)) + output_dir = QDir::tempPath(); + } + f.output_file = (output_dir + "/" + file.baseName() + "_gui.xml").toUtf8().constData(); + emit new_progress_max_value(f.nsteps()); + + // Perform text detection. + f(original_ima, processed_ima); + return f.output_file; + //qDebug() << "Process Done."; +} + + + +// Export related stuff + +void Runner::start_export(const QString& imgfile, + const QString& xmlfile, const QString& outfile) +{ + args_.clear(); + args_ << imgfile << xmlfile << outfile; + mode_ = Export; + + QThread::start(); +} + + +void Runner::export_as() { + emit new_step("Exporting document..."); + emit new_progress_max_value(2); + + // Checking output format + QFileInfo f(args_.at(2)); + + QString pathto_xml2doc = get_pathto("scribo-xml2doc", "xml2doc"); + + if (pathto_xml2doc.isEmpty()) + { + QMessageBox::critical(0, "Fatal error", "Cannot export! Cannot find scribo-xml2doc program!"); + return; + } + + emit progress(); + + int rvalue = 0; + if (f.suffix() == "pdf") + { + emit new_step("Exporting as PDF..."); + rvalue = system(QString("%1/scribo-xml2doc --pdf %2 %3 %4") + .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) + .arg(args_.at(2)).toAscii().constData()); + } + else if (f.suffix() == "html" || f.suffix() == "htm") + { + emit new_step("Exporting as HTML..."); + rvalue = system(QString("%1/scribo-xml2doc --html %2 %3 %4") + .arg(pathto_xml2doc).arg(args_.at(1)).arg(args_.at(0)) + .arg(args_.at(2)).toAscii().constData()); + } + else + QMessageBox::critical(0, "Fatal error", "Cannot export! Invalid output format!"); + + if (rvalue != 0) + QMessageBox::critical(0, "Fatal error", "Cannot export! Return value is not 0!"); } diff --git a/XmlParser/runner.h b/XmlParser/runner.h index 2f303f0..0e506b7 100644 --- a/XmlParser/runner.h +++ b/XmlParser/runner.h @@ -3,9 +3,18 @@ #include <QThread> #include <QStringList> +#include <QMessageBox> +#include <QFile> #include <mln/core/image/image2d.hh> #include <mln/value/rgb8.hh> #include <mln/io/magick/load.hh> +#include "dir.h" +#include "region.h" +#include "process.h" +#include "preprocess.h" +#include "configs.h" + +using namespace mln; enum RunMode { @@ -16,10 +25,33 @@ enum RunMode class Runner : public QThread { - //Q_OBJECT + Q_OBJECT public: explicit Runner(QObject *parent = 0); + void start_demat(const QString& filename); + void start_export(const QString& imgfile, const QString& xmlfile, const QString& outfile); + + private: + image2d<bool> preprocess(const image2d<value::rgb8>& ima); + QString process(const image2d<value::rgb8>& original_ima, const image2d<bool>& processed_ima); + void export_as(); + virtual void run(); + template <typename V> unsigned find_best_scale(const mln::image2d<V>& ima); + + QStringList args_; + RunMode mode_; + + public slots: + void stop(); + + signals: + void new_step(const QString& step_name); + void new_progress_max_value(int i); + void new_progress_label(const QString& msg); + void xml_saved(const QString& filename); + void progress(); + void finished(QString *filename = 0); }; #endif // RUNNER_H diff --git a/XmlParser/scene.h b/XmlParser/scene.h index efeac73..47e0cf2 100644 --- a/XmlParser/scene.h +++ b/XmlParser/scene.h @@ -21,10 +21,6 @@ class Scene : void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - signals: - void repaintItems(const QRectF& rect, bool clic); - void sendString(QString& string); - private: void init(); QString debug(QRect &rect); @@ -33,6 +29,10 @@ class Scene : QPointF pressPos; bool isPressing; bool clic; + + signals: + void repaintItems(const QRectF& rect, bool clic); + void sendString(QString& string); }; #endif // SCENE_H diff --git a/XmlParser/toolbar.cpp b/XmlParser/toolbar.cpp index 4b098a5..746f5ee 100644 --- a/XmlParser/toolbar.cpp +++ b/XmlParser/toolbar.cpp @@ -3,12 +3,26 @@ ToolBar::ToolBar(QWidget *parent): QToolBar("ToolBar", parent) { - init(); + setAutoFillBackground(true); + setFloatable(false); + setMovable(false); + open = addAction(tr("Open")); + segment = addAction(tr("Segment")); + addSeparator(); + quit = addAction(tr("Quit")); } -void ToolBar::init() +QAction * ToolBar::openAction() const { - addAction(tr("Open")); - addAction(tr("Segment")); + return open; +} +QAction * ToolBar::segmentAction() const +{ + return segment; +} + +QAction * ToolBar::quitAction() const +{ + return quit; } diff --git a/XmlParser/toolbar.h b/XmlParser/toolbar.h index 91aa338..25609af 100644 --- a/XmlParser/toolbar.h +++ b/XmlParser/toolbar.h @@ -2,16 +2,26 @@ #define TOOLBAR_H #include <QToolBar> +#include <QAction> +#include "mainwindow.h" class ToolBar : public QToolBar { public: - explicit ToolBar(QWidget *parent = 0); - explicit ToolBar(const QString& title, QWidget *parent = 0); + explicit ToolBar(QWidget *parent); + QAction * openAction() const; + QAction * segmentAction() const; + QAction * quitAction() const; private: void init(); + + QAction *open; + QAction *segment; + QAction *quit; + + }; #endif // TOOLBAR_H diff --git a/XmlParser/xml.cpp b/XmlParser/xml.cpp index 40bf193..4b20005 100644 --- a/XmlParser/xml.cpp +++ b/XmlParser/xml.cpp @@ -97,59 +97,59 @@ void Xml::parseItems(const QString &filename, Scene *scene) xmlFile.close(); QVector<QGraphicsItem *> items; QDomElement element = xml.documentElement().firstChild().nextSiblingElement("Page").firstChild().toElement(); - graphicsTextRegion(element, scene); // TextRegion + LineRegion + Baseline + Meanline + graphicsTextRegion(element, scene); GraphicRegion::Data verticalData; verticalData.color = QColor::fromRgb(0, 0, 255, 80); verticalData.name = "VerticalSeparatorRegion"; verticalData.region = (int)GraphicRegion::VerticalSeparator; verticalData.zValue = 2; - graphicsRegion(element.nextSiblingElement(verticalData.name), verticalData, scene); // VerticalRegion + graphicsRegion(element.nextSiblingElement(verticalData.name), verticalData, scene); GraphicRegion::Data horizontalData; horizontalData.color = QColor::fromRgb(0, 0, 255, 80); horizontalData.name = "HorizontalSeparatorRegion"; horizontalData.region = (int)GraphicRegion::HorizontalSeparator; horizontalData.zValue = 2; - graphicsRegion(element.nextSiblingElement(horizontalData.name), horizontalData, scene); // HorizontalRegion + graphicsRegion(element.nextSiblingElement(horizontalData.name), horizontalData, scene); GraphicRegion::Data spaceData; spaceData.color = QColor::fromRgb(0, 0, 128, 80); spaceData.name = "WhitespaceSeparatorRegion"; spaceData.region = (int)GraphicRegion::WhiteSpaceSeparator; spaceData.zValue = 2; - graphicsRegion(element.nextSiblingElement(spaceData.name), spaceData, scene); // WhitespaceRegion + graphicsRegion(element.nextSiblingElement(spaceData.name), spaceData, scene); GraphicRegion::Data imageData; imageData.color = QColor::fromRgb(255, 120, 0, 80); imageData.name = "ImageRegion"; imageData.region = (int)GraphicRegion::Image; imageData.zValue = 1; - graphicsRegion(element.nextSiblingElement(imageData.name), imageData, scene); // ImageRegion + graphicsRegion(element.nextSiblingElement(imageData.name), imageData, scene); GraphicRegion::Data noiseData; noiseData.color = QColor::fromRgb(43, 39, 128, 80); noiseData.name = "NoiseRegion"; noiseData.region = (int)GraphicRegion::Noise; noiseData.zValue = 2; - graphicsRegion(element.nextSiblingElement(noiseData.name), noiseData, scene); // NoiseRegion + graphicsRegion(element.nextSiblingElement(noiseData.name), noiseData, scene); GraphicRegion::Data tableData; tableData.color = QColor::fromRgb(220, 246, 0, 80); tableData.name = "TableRegion"; tableData.region = (int)GraphicRegion::Table; tableData.zValue = 2; - graphicsRegion(element.nextSiblingElement(tableData.name), tableData, scene); // TableRegion + graphicsRegion(element.nextSiblingElement(tableData.name), tableData, scene); GraphicRegion::Data mathsData; mathsData.color = QColor::fromRgb(170, 0, 255, 80); mathsData.name = "MathsRegion"; mathsData.region = (int)GraphicRegion::Maths; mathsData.zValue = 3; - graphicsRegion(element.nextSiblingElement(mathsData.name), mathsData, scene); // MathsRegion + graphicsRegion(element.nextSiblingElement(mathsData.name), mathsData, scene); GraphicRegion::Data graphicData; graphicData.color = QColor::fromRgb(255, 0, 144, 80); graphicData.name = "GraphicRegion"; graphicData.region = (int)GraphicRegion::Graphic; graphicData.zValue = 2; - graphicsRegion(element.nextSiblingElement(graphicData.name), graphicData, scene); // GraphicRegion + graphicsRegion(element.nextSiblingElement(graphicData.name), graphicData, scene); GraphicRegion::Data chartData; chartData.color = QColor::fromRgb(0, 204, 255, 80); chartData.name = "ChartRegion"; chartData.region = (int)GraphicRegion::Chart; chartData.zValue = 2; - graphicsRegion(element.nextSiblingElement(chartData.name), chartData, scene); // ChartRegion + graphicsRegion(element.nextSiblingElement(chartData.name), chartData, scene); } -- 1.7.2.5