Commit 9f724b07 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.
parent 6adbc43e
2010-03-19 Guillaume Lazzara <z@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@lrde.epita.fr>
Add a new demo in Scribo.
......
......@@ -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
......
......@@ -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();
......
......@@ -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
......
......@@ -48,6 +48,8 @@ namespace scribo
virtual int nextId() const;
private slots:
void showCustomButton_slot(int id);
private:
enum { Page_Load,
......
......@@ -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);
......
......@@ -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&)));
......
#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
// 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.
#ifndef SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
# define SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
# include <QtGui>
# include <src/result_widget.hh>
# include <src/runner.hh>
namespace scribo
{
namespace demo
{
class result_page : public QWizardPage
{
Q_OBJECT;
public:
result_page(QWidget *parent = 0);
virtual void cleanupPage();
virtual void initializePage();
private: // attributes
result_widget* widget_;
};
} // end of namespace scribo::demo
} // end of namespace scribo
#endif // ! SCRIBO_DEMO_SHARED_SRC_RESULT_PAGE_HH
#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
// 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.
#ifndef SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
# define SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
# include <QtGui>
namespace scribo
{
namespace demo
{
class result_widget : public QWidget
{
Q_OBJECT;
public:
result_widget(QWidget *parent = 0);
void reset();
void load(const QString& filename);
private:
QTextEdit *text_;
};
} // end of namespace scribo::demo
} // end of namespace scribo
#endif // ! SCRIBO_DEMO_SHARED_SRC_RESULT_WIDGET_HH
......@@ -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";
}
......
......@@ -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>
......
......@@ -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 \
......
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