* demo/wizard/src/crop_widget.cc,
* demo/wizard/src/main.cc,
* demo/wizard/src/main_window.cc,
* demo/wizard/src/main_window.hh,
* demo/wizard/src/preprocessing_widget.cc,
* demo/wizard/src/process_page.cc,
* demo/wizard/src/result_page.cc,
* demo/wizard/src/result_page.hh,
* demo/wizard/src/result_widget.cc,
* demo/wizard/src/result_widget.hh,
* demo/wizard/src/runner.cc,
* demo/wizard/ui/preprocessing_widget.ui,
* demo/wizard/wizard.pro: Add support for text recognition and
display results.
---
scribo/ChangeLog | 19 +++++++
scribo/demo/wizard/src/crop_widget.cc | 2 +-
scribo/demo/wizard/src/main.cc | 13 +++++
scribo/demo/wizard/src/main_window.cc | 23 ++++++--
scribo/demo/wizard/src/main_window.hh | 2 +
scribo/demo/wizard/src/preprocessing_widget.cc | 10 +++-
scribo/demo/wizard/src/process_page.cc | 5 --
scribo/demo/wizard/src/result_page.cc | 43 +++++++++++++++
.../wizard/src/{crop_page.hh => result_page.hh} | 18 +++---
scribo/demo/wizard/src/result_widget.cc | 43 +++++++++++++++
.../wizard/src/{crop_page.hh => result_widget.hh} | 18 +++----
scribo/demo/wizard/src/runner.cc | 55 +++++++++++++-------
scribo/demo/wizard/ui/preprocessing_widget.ui | 4 +-
scribo/demo/wizard/wizard.pro | 48 +++++++++--------
14 files changed, 228 insertions(+), 75 deletions(-)
create mode 100644 scribo/demo/wizard/src/result_page.cc
copy scribo/demo/wizard/src/{crop_page.hh => result_page.hh} (81%)
create mode 100644 scribo/demo/wizard/src/result_widget.cc
copy scribo/demo/wizard/src/{crop_page.hh => result_widget.hh} (79%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 68ec602..bc1c87a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,24 @@
2010-03-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve dematerialization wizard.
+
+ * demo/wizard/src/crop_widget.cc,
+ * demo/wizard/src/main.cc,
+ * demo/wizard/src/main_window.cc,
+ * demo/wizard/src/main_window.hh,
+ * demo/wizard/src/preprocessing_widget.cc,
+ * demo/wizard/src/process_page.cc,
+ * demo/wizard/src/result_page.cc,
+ * demo/wizard/src/result_page.hh,
+ * demo/wizard/src/result_widget.cc,
+ * demo/wizard/src/result_widget.hh,
+ * demo/wizard/src/runner.cc,
+ * demo/wizard/ui/preprocessing_widget.ui,
+ * demo/wizard/wizard.pro: Add support for text recognition and
+ display results.
+
+2010-03-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add a new demo in Scribo.
* demo/demat/demat.pro,
diff --git a/scribo/demo/wizard/src/crop_widget.cc
b/scribo/demo/wizard/src/crop_widget.cc
index 37a9e80..8067fda 100644
--- a/scribo/demo/wizard/src/crop_widget.cc
+++ b/scribo/demo/wizard/src/crop_widget.cc
@@ -29,7 +29,7 @@ namespace scribo
QPixmap crop_widget::image() const
{
- return viewer_->image().copy(crop_area().toRect());
+ return
viewer_->image().copy(crop_area().toRect().intersected(viewer_->image().rect()));
}
} // end of namespace scribo::demo
diff --git a/scribo/demo/wizard/src/main.cc b/scribo/demo/wizard/src/main.cc
index 12f024a..5b771e2 100644
--- a/scribo/demo/wizard/src/main.cc
+++ b/scribo/demo/wizard/src/main.cc
@@ -2,12 +2,25 @@
#include <src/main_window.hh>
#include <src/preprocessing_task.hh>
+namespace scribo { namespace demo {extern QString basedir_; } }
+
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
qRegisterMetaType<preprocessing_task_set_t>("preprocessing_task_set_t");
+
+ if (argc == 2)
+ {
+ scribo::demo::basedir_ = argv[1];
+ }
+ else
+ {
+ qDebug() << "Usage: " << argv[0] << "
<path_to_scribo/src>";
+ return 1;
+ }
+
scribo::demo::wizard::main_window win;
win.show();
diff --git a/scribo/demo/wizard/src/main_window.cc
b/scribo/demo/wizard/src/main_window.cc
index 35aa8c7..7f44ec5 100644
--- a/scribo/demo/wizard/src/main_window.cc
+++ b/scribo/demo/wizard/src/main_window.cc
@@ -31,6 +31,7 @@
#include <src/preprocessing_page.hh>
#include <src/process_page.hh>
#include <src/rotate_page.hh>
+#include <src/result_page.hh>
namespace scribo
{
@@ -44,15 +45,15 @@ namespace scribo
main_window::main_window()
{
- setOptions(QWizard::NoBackButtonOnStartPage
- | QWizard::DisabledBackButtonOnLastPage
- | QWizard::NoCancelButton);
-
QPixmap bg_pixmap(":/images/images/dematerialization.png");
setPixmap(QWizard::WatermarkPixmap, bg_pixmap);
setPixmap(QWizard::BackgroundPixmap, bg_pixmap);
+ connect(this, SIGNAL(currentIdChanged(int)),
+ this, SLOT(showCustomButton_slot(int)));
+
+
// Page_Load
load_page* page_load = new load_page(this);
addPage(page_load);
@@ -78,7 +79,7 @@ namespace scribo
addPage(new process_page(this));
// Page_Result
- addPage(new QWizardPage(this));
+ addPage(new result_page(this));
}
@@ -122,6 +123,18 @@ namespace scribo
}
+ void main_window::showCustomButton_slot(int id)
+ {
+ if (id == Page_Result)
+ setOptions(options() | QWizard::HaveCustomButton1);
+ else
+ {
+ setOptions(QWizard::NoBackButtonOnStartPage
+// | QWizard::DisabledBackButtonOnLastPage
+ | QWizard::NoCancelButton);
+ }
+ }
+
} // end of namespace scribo::demo::wizard
} // end of namespace scribo::demo
diff --git a/scribo/demo/wizard/src/main_window.hh
b/scribo/demo/wizard/src/main_window.hh
index af4c113..44e6d92 100644
--- a/scribo/demo/wizard/src/main_window.hh
+++ b/scribo/demo/wizard/src/main_window.hh
@@ -48,6 +48,8 @@ namespace scribo
virtual int nextId() const;
+ private slots:
+ void showCustomButton_slot(int id);
private:
enum { Page_Load,
diff --git a/scribo/demo/wizard/src/preprocessing_widget.cc
b/scribo/demo/wizard/src/preprocessing_widget.cc
index 7a2c9fa..7c66719 100644
--- a/scribo/demo/wizard/src/preprocessing_widget.cc
+++ b/scribo/demo/wizard/src/preprocessing_widget.cc
@@ -35,8 +35,11 @@ namespace scribo
{
qDebug() << "setup text doc";
- removeBg->setChecked(true);
- unskew->setChecked(true);
+ // Disabled
+ removeBg->setChecked(false);
+ unskew->setChecked(false);
+
+ // Enabled
removeNoise->setChecked(true);
improveContrast->setChecked(true);
}
@@ -44,6 +47,9 @@ namespace scribo
void preprocessing_widget::clear_checked()
{
+ // Enabled
+
+ // Disabled
removeBg->setChecked(false);
unskew->setChecked(false);
removeNoise->setChecked(false);
diff --git a/scribo/demo/wizard/src/process_page.cc
b/scribo/demo/wizard/src/process_page.cc
index bbba0e3..bff087a 100644
--- a/scribo/demo/wizard/src/process_page.cc
+++ b/scribo/demo/wizard/src/process_page.cc
@@ -21,11 +21,6 @@ namespace scribo
setSubTitle("Processing...");
setTitle("Please wait while computing results.");
-
- void progress(unsigned i);
-
- void progress(unsigned i);
-
connect(&runner_, SIGNAL(new_intermediate_result(const QImage&)),
widget_, SLOT(update_pixmap(const QImage&)));
diff --git a/scribo/demo/wizard/src/result_page.cc
b/scribo/demo/wizard/src/result_page.cc
new file mode 100644
index 0000000..1bb08d8
--- /dev/null
+++ b/scribo/demo/wizard/src/result_page.cc
@@ -0,0 +1,43 @@
+#include <src/result_page.hh>
+#include <src/result_widget.hh>
+
+
+namespace scribo
+{
+
+ namespace demo
+ {
+
+
+ result_page::result_page(QWidget *parent)
+ : QWizardPage(parent)
+ {
+ widget_ = new result_widget(this);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(widget_);
+ setLayout(layout);
+
+ setTitle("Result");
+ setSubTitle("Copy and paste the recognized text.");
+
+ connect(parent, SIGNAL(customButtonClicked(int)),
+ parent, SLOT(restart()));
+ }
+
+
+ void result_page::cleanupPage()
+ {
+ widget_->reset();
+ }
+
+
+ void result_page::initializePage()
+ {
+ setButtonText(QWizard::CustomButton1, "restart");
+ widget_->load("/tmp/out.txt");
+ }
+
+
+ } // end of namespace scribo::demo
+
+} // end of namespace scribo
diff --git a/scribo/demo/wizard/src/crop_page.hh b/scribo/demo/wizard/src/result_page.hh
similarity index 81%
copy from scribo/demo/wizard/src/crop_page.hh
copy to scribo/demo/wizard/src/result_page.hh
index 9891a7e..c6f02b9 100644
--- a/scribo/demo/wizard/src/crop_page.hh
+++ b/scribo/demo/wizard/src/result_page.hh
@@ -23,11 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
-# define SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
+#ifndef SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
+# define SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
# include <QtGui>
-# include <src/crop_widget.hh>
+# include <src/result_widget.hh>
+# include <src/runner.hh>
namespace scribo
{
@@ -36,19 +37,18 @@ namespace scribo
{
- class crop_page : public QWizardPage
+ class result_page : public QWizardPage
{
Q_OBJECT;
public:
- crop_page(QWidget *parent = 0);
+ result_page(QWidget *parent = 0);
virtual void cleanupPage();
virtual void initializePage();
- virtual bool validatePage();
- private:
- crop_widget *widget_;
+ private: // attributes
+ result_widget* widget_;
};
@@ -57,4 +57,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
+#endif // ! SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
diff --git a/scribo/demo/wizard/src/result_widget.cc
b/scribo/demo/wizard/src/result_widget.cc
new file mode 100644
index 0000000..889ba4b
--- /dev/null
+++ b/scribo/demo/wizard/src/result_widget.cc
@@ -0,0 +1,43 @@
+#include <src/result_widget.hh>
+
+namespace scribo
+{
+
+ namespace demo
+ {
+
+
+ result_widget::result_widget(QWidget *parent)
+ : QWidget(parent)
+ {
+ text_ = new QTextEdit(this);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(text_);
+ setLayout(layout);
+ }
+
+ void result_widget::load(const QString& filename)
+ {
+ QFile file(filename);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+
+ QTextStream in(&file);
+ in.setCodec("UTF-8");
+ while (!in.atEnd())
+ {
+ QString line = in.readLine();
+ text_->append(line);
+ }
+
+ }
+
+ void result_widget::reset()
+ {
+ text_->clear();
+ }
+
+
+ } // end of namespace scribo::demo
+
+} // end of namespace scribo
diff --git a/scribo/demo/wizard/src/crop_page.hh
b/scribo/demo/wizard/src/result_widget.hh
similarity index 79%
copy from scribo/demo/wizard/src/crop_page.hh
copy to scribo/demo/wizard/src/result_widget.hh
index 9891a7e..4472238 100644
--- a/scribo/demo/wizard/src/crop_page.hh
+++ b/scribo/demo/wizard/src/result_widget.hh
@@ -23,11 +23,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
-# define SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
+#ifndef SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
+# define SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
# include <QtGui>
-# include <src/crop_widget.hh>
namespace scribo
{
@@ -36,19 +35,18 @@ namespace scribo
{
- class crop_page : public QWizardPage
+ class result_widget : public QWidget
{
Q_OBJECT;
public:
- crop_page(QWidget *parent = 0);
+ result_widget(QWidget *parent = 0);
+ void reset();
- virtual void cleanupPage();
- virtual void initializePage();
- virtual bool validatePage();
+ void load(const QString& filename);
private:
- crop_widget *widget_;
+ QTextEdit *text_;
};
@@ -57,4 +55,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_DEMO_SHARED_SRC_CROP_PAGE_HH
+#endif // ! SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
diff --git a/scribo/demo/wizard/src/runner.cc b/scribo/demo/wizard/src/runner.cc
index 162f1cb..dd9ad9c 100644
--- a/scribo/demo/wizard/src/runner.cc
+++ b/scribo/demo/wizard/src/runner.cc
@@ -27,7 +27,7 @@ namespace scribo
namespace demo
{
- QString basedir_ = "/home/lazzara/build/scribo/src";
+ QString basedir_ = "";
runner::runner(QObject *parent)
: QThread(parent)
@@ -53,6 +53,8 @@ namespace scribo
// Notification of the number of tasks.
emit new_progress_max_value(tasks_.size() + 2);
+ qDebug() << "progress steps : " << tasks_.size() + 2;
+
image2d<value::qt::rgb32> ima = load();
preprocess(ima);
@@ -131,10 +133,10 @@ namespace scribo
std::cout << "Improve contrast homogeneity" << std::endl;
emit new_progress_label("Improve contrast homogeneity");
- intensity_ima = preprocessing::homogeneous_contrast(intensity_ima, 75);
+ intensity_ima = arith::revert(preprocessing::homogeneous_contrast(intensity_ima, 75));
image2d<value::qt::rgb32>
- tmp_color32 = data::convert(value::qt::rgb32(), out_bool);
+ tmp_color32 = data::convert(value::qt::rgb32(), intensity_ima);
emit new_intermediate_result(convert::to_qimage(tmp_color32));
emit progress(1);
}
@@ -149,14 +151,13 @@ namespace scribo
{
// FIXME: sauvola should not negate the image.
std::cout << "Binarization Sauvola" << std::endl;
- out_bool = logical::not_(binarization::sauvola(intensity_ima));
+ out_bool = binarization::sauvola(intensity_ima);
}
else if (tasks_.contains(BinarizationSauvolaMs))
{
// FIXME: sauvola should not negate the image.
std::cout << "Binarization Sauvola_ms" << std::endl;
- out_bool = logical::not_(binarization::sauvola_ms(intensity_ima,
- 51, 2, 67));
+ out_bool = binarization::sauvola_ms(intensity_ima, 51, 2, 67);
}
else if (tasks_.contains(BinarizationSimple))
{
@@ -175,22 +176,24 @@ namespace scribo
emit progress(1);
+ // FIXME: remove!
+ logical::not_inplace(out_bool);
+
//========
// Denoise
//========
- if (tasks_.contains(RemoveNoise))
- {
- std::cout << "Remove noise" << std::endl;
- emit new_progress_label("Remove noise");
+// if (tasks_.contains(RemoveNoise))
+// {
+// std::cout << "Remove noise" << std::endl;
+// emit new_progress_label("Remove noise");
- out_bool = preprocessing::denoise(out_bool, c8(), 2, 2);
-
- image2d<value::qt::rgb32>
- tmp_color32 = data::convert(value::qt::rgb32(), out_bool);
- emit new_intermediate_result(convert::to_qimage(tmp_color32));
- emit progress(1);
- }
+// out_bool = preprocessing::denoise(out_bool, c8(), 2, 2);
+// image2d<value::qt::rgb32>
+// tmp_color32 = data::convert(value::qt::rgb32(), out_bool);
+// emit new_intermediate_result(convert::to_qimage(tmp_color32));
+// emit progress(1);
+// }
//=======
// Unskew
@@ -226,8 +229,21 @@ namespace scribo
switch(doc_type_)
{
case Text_Doc:
+ emit new_progress_label("Finding text in document...");
qDebug() << "Running text_in_article_pbm";
- args << "/tmp/tmp.pbm" << "/tmp/out.ppm";
+ args << "/tmp/tmp.pbm" << "/tmp/out.txt";
+
+ // Denoise.
+ if (! tasks_.contains(RemoveNoise))
+ args << "0";
+ else
+ {
+ args << "1";
+ emit progress(1); // Consider denoising as done even though it is performed later.
+ }
+
+ args << "/tmp/";
+
if (process_.execute(basedir_ + "/text_in_article_pbm", args))
{
qDebug() << "Error while running text_in_article_pbm.";
@@ -236,6 +252,7 @@ namespace scribo
break;
case Picture:
+ emit new_progress_label("Finding text in picture...");
qDebug() << "Running text_in_photo_pbm_fast";
args << "/tmp/tmp.pbm" << "/tmp/out.ppm" <<
"1" << "1" << "1";
if (process_.execute(basedir_ + "/text_in_photo_pbm_fast", args))
@@ -263,7 +280,7 @@ namespace scribo
process_.waitForFinished(-1);
emit progress(1);
- emit new_intermediate_result(QImage("/tmp/out.ppm"));
+ emit new_intermediate_result(QImage("/tmp/_09_step2_bboxes.ppm"));
qDebug() << "Done";
}
diff --git a/scribo/demo/wizard/ui/preprocessing_widget.ui
b/scribo/demo/wizard/ui/preprocessing_widget.ui
index 17225a8..6b9c178 100644
--- a/scribo/demo/wizard/ui/preprocessing_widget.ui
+++ b/scribo/demo/wizard/ui/preprocessing_widget.ui
@@ -70,7 +70,7 @@
<item>
<widget class="QCheckBox" name="removeNoise" >
<property name="enabled" >
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="text" >
<string>Remove noise</string>
@@ -83,7 +83,7 @@
<item>
<widget class="QCheckBox" name="improveContrast" >
<property name="enabled" >
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="text" >
<string>Improve brightness/contrast</string>
diff --git a/scribo/demo/wizard/wizard.pro b/scribo/demo/wizard/wizard.pro
index c7ab290..9dd5296 100644
--- a/scribo/demo/wizard/wizard.pro
+++ b/scribo/demo/wizard/wizard.pro
@@ -11,27 +11,29 @@ INCLUDEPATH += . ../ ../shared $(OLN)/milena $(OLN)
DEFINES += NDEBUG MLN_INCLUDE_ONLY
# Input
-HEADERS += \
- ../shared/src/image_viewer.hh \
- ../shared/src/internal/interactive_scene.hh \
- ../shared/src/crop_item.hh \
+ HEADERS += \
+ ../shared/src/image_viewer.hh \
+ ../shared/src/internal/interactive_scene.hh \
+ ../shared/src/crop_item.hh \
../shared/src/browse_widget.hh \
- src/load_page.hh \
- src/load_widget.hh \
- src/doc_type_widget.hh \
- src/doc_type_page.hh \
- src/crop_widget.hh \
- src/crop_page.hh \
- src/rotate_widget.hh \
- src/rotate_page.hh \
- src/preprocessing_widget.hh \
- src/preprocessing_page.hh \
- src/process_page.hh \
- src/process_widget.hh \
- src/runner.hh \
- src/preprocessing_task.hh \
- src/doc_type.hh \
- src/main_window.hh
+ src/load_page.hh \
+ src/load_widget.hh \
+ src/doc_type_widget.hh \
+ src/doc_type_page.hh \
+ src/crop_widget.hh \
+ src/crop_page.hh \
+ src/rotate_widget.hh \
+ src/rotate_page.hh \
+ src/preprocessing_widget.hh \
+ src/preprocessing_page.hh \
+ src/process_page.hh \
+ src/process_widget.hh \
+ src/runner.hh \
+ src/preprocessing_task.hh \
+ src/doc_type.hh \
+ src/main_window.hh \
+ src/result_page.hh \
+ src/result_widget.hh
SOURCES += \
@@ -40,7 +42,7 @@ SOURCES += \
../shared/src/browse_widget.cc \
src/main.cc \
src/main_window.cc \
- src/doc_type_widget.cc \
+ src/doc_type_widget.cc \
src/doc_type_page.cc \
src/load_page.cc \
src/load_widget.cc \
@@ -52,7 +54,9 @@ SOURCES += \
src/preprocessing_page.cc \
src/process_page.cc \
src/process_widget.cc \
- src/mln_widgets.cc
+ src/mln_widgets.cc \
+ src/result_page.cc \
+ src/result_widget.cc
FORMS += \
../shared/ui/browse_widget.ui \
--
1.5.6.5