Commit 6adbc43e authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add a new demo in Scribo.

	* demo/demat/demat.pro,
	* demo/demat/demat.qrc,
	* demo/demat/src/doc_type.hh,
	* demo/demat/src/main.cc,
	* demo/demat/src/main_window.cc,
	* demo/demat/src/main_window.hh,
	* demo/demat/src/mln_widgets.cc,
	* demo/demat/src/preprocessing_task.hh,
	* demo/demat/src/process_args.hh,
	* demo/demat/src/runner.cc,
	* demo/demat/src/runner.hh,
	* demo/demat/ui/main_window.ui: New.

	* demo/shared/src/crop_item.cc,
	* demo/shared/src/crop_item.hh,
	* demo/shared/src/image_viewer.cc,
	* demo/shared/src/image_viewer.hh,
	* demo/shared/ui/image_viewer.ui: Update according the needs of
	this new demo.
parent 4a195987
2010-03-19 Guillaume Lazzara <z@lrde.epita.fr>
Add a new demo in Scribo.
* demo/demat/demat.pro,
* demo/demat/demat.qrc,
* demo/demat/src/doc_type.hh,
* demo/demat/src/main.cc,
* demo/demat/src/main_window.cc,
* demo/demat/src/main_window.hh,
* demo/demat/src/mln_widgets.cc,
* demo/demat/src/preprocessing_task.hh,
* demo/demat/src/process_args.hh,
* demo/demat/src/runner.cc,
* demo/demat/src/runner.hh,
* demo/demat/ui/main_window.ui: New.
* demo/shared/src/crop_item.cc,
* demo/shared/src/crop_item.hh,
* demo/shared/src/image_viewer.cc,
* demo/shared/src/image_viewer.hh,
* demo/shared/ui/image_viewer.ui: Update according the needs of
this new demo.
2010-03-19 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes in Scribo.
......
# -*- c++ -*-
######################################################################
# Automatically generated by qmake (2.01a) Tue Feb 9 12:02:10 2010
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += . src
INCLUDEPATH += . ../ ../shared $(OLN)/milena $(OLN)
QMAKE_CXXFLAGS += -g
LIBS += `Magick++-config --ldflags --libs`
DEFINES += NDEBUG MLN_INCLUDE_ONLY
# Input
HEADERS += \
../shared/src/image_viewer.hh \
../shared/src/internal/interactive_scene.hh \
../shared/src/crop_item.hh \
../shared/src/browse_widget.hh \
src/runner.hh \
src/main_window.hh
SOURCES += \
../shared/src/crop_item.cc \
../shared/src/internal/interactive_scene.cc \
../shared/src/browse_widget.cc \
src/mln_widgets.cc
FORMS += \
../shared/ui/image_viewer.ui \
ui/main_window.ui
RESOURCES += ../shared/shared.qrc demat.qrc
<RCC>
<qresource prefix="images" >
</qresource>
</RCC>
// 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_DOC_TYPE_HH
# define SCRIBO_DEMO_SHARED_SRC_DOC_TYPE_HH
namespace scribo
{
namespace demo
{
enum Doc_Type
{
Text_Doc,
Picture,
Mixed_Doc,
Invalid_Doc
};
} // end of namespace scribo::demo
} // end of namespace scribo
#endif // !SCRIBO_DEMO_SHARED_SRC_DOC_TYPE_HH
#include <QtGui>
#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::demat::main_window win;
win.show();
return app.exec();
}
// 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 <src/main_window.hh>
#include <src/doc_type.hh>
#include <src/preprocessing_task.hh>
#include <src/process_args.hh>
#include <mln/data/convert.hh>
#include <mln/convert/to_qimage_nocopy.hh>
#include <mln/core/routine/duplicate.hh>
#include <mln/make/box2d.hh>
#include <mln/data/paste.hh>
#include <mln/io/magick/load.hh>
namespace scribo
{
namespace demo
{
namespace demat
{
// FIXME: move it as attribute.
static mln::image2d<mln::value::rgb8> input_;
main_window::main_window()
{
setupUi(this);
text_->hide();
connect(action_Open, SIGNAL(activated()),
this, SLOT(open_file_slot()));
connect(run_btn, SIGNAL(clicked()), this, SLOT(run()));
// Connections to/from task runner.
connect(&runner_, SIGNAL(new_progress_label(const QString&)),
this, SLOT(update_progress_label_slot(const QString&)));
connect(&runner_, SIGNAL(progress(unsigned)),
this, SLOT(progress_slot(unsigned)));
connect(&runner_, SIGNAL(finished()),
this, SLOT(process_finished_slot()));
// Connections for dock windows.
connect(advanced_dock_, SIGNAL(visibilityChanged(bool)),
actionAdvanced_options, SLOT(setChecked(bool)));
connect(options_dock_, SIGNAL(visibilityChanged(bool)),
actionOptions, SLOT(setChecked(bool)));
connect(actionAdvanced_options, SIGNAL(triggered(bool)),
advanced_dock_, SLOT(setVisible(bool)));
connect(actionOptions, SIGNAL(triggered(bool)),
options_dock_, SLOT(setVisible(bool)));
progress_ = new QProgressDialog();
progress_->setLabelText("Processing...");
progress_->setCancelButton(0);
progress_->setAutoClose(true);
// Setup crop tool.
viewer_->set_selection_enabled(true);
connect(viewer_, SIGNAL(ready_for_crop()), this, SLOT(crop_slot()));
}
void main_window::open_file_slot()
{
QFileDialog dialog;
QStringList filters;
filters << tr("Image (*.ppm *.pbm *.pgm *.png *.jpg)");
dialog.setNameFilters(filters);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setLabelText(QFileDialog::LookIn,
tr("Choose an existing file"));
if (dialog.exec() && current_image_ != dialog.selectedFiles().at(0))
{
current_image_ = dialog.selectedFiles().at(0);
load();
}
}
void main_window::load()
{
text_->hide();
mln::io::magick::load(input_, current_image_.toStdString());
input_dsp_ = QPixmap::fromImage(mln::convert::to_qimage_nocopy(input_));
viewer_->draw_image(input_dsp_);
}
void main_window::run()
{
preprocessing_task_set_t tasks = get_tasks();
prepare_progress_bar(tasks.size());
process_args args; // Nothing for now.
runner_.start(current_image_, input_, Text_Doc, tasks, args);
}
preprocessing_task_set_t main_window::get_tasks()
{
preprocessing_task_set_t tasks;
if (removeBg->isChecked())
tasks.insert(RemoveBg);
if (unskew->isChecked())
tasks.insert(Unskew);
if (removeNoise->isChecked())
tasks.insert(RemoveNoise);
if (improveContrast->isChecked())
tasks.insert(ImproveContrast);
if (reduceSize->isChecked())
tasks.insert(ReduceSize);
if (binarizationCBox->currentIndex() == 0)
tasks.insert(BinarizationSimple);
else if (binarizationCBox->currentIndex() == 1)
tasks.insert(BinarizationSauvola);
else if (binarizationCBox->currentIndex() == 2)
tasks.insert(BinarizationSauvolaMs);
return tasks;
}
void main_window::prepare_progress_bar(unsigned max)
{
progress_->show();
progress_->setValue(0);
progress_->setMaximum(max + 3);
}
void main_window::progress_slot(unsigned i)
{
progress_->setValue(progress_->value() + i);
}
void main_window::update_progress_label_slot(const QString& msg)
{
progress_->setLabelText(msg);
}
void main_window::process_finished_slot()
{
text_->clear();
QFile file("/tmp/out.txt");
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);
}
text_->show();
}
void main_window::crop_slot()
{
mln::box2d b = input_.domain();
QRectF selection = viewer_->selection();
mln::box2d sbox = mln::make::box2d(selection.topLeft().y(),
selection.topLeft().x(),
selection.bottomRight().y(),
selection.bottomRight().x());
sbox.crop_wrt(b);
if (sbox.is_valid())
{
// Update underlying data.
mln::image2d<mln::value::rgb8> output(sbox);
mln::data::fill(output, input_);
input_ = output;
// Update display
viewer_->draw_image(input_);
}
viewer_->enable_crop_tool(false); // Disable crop tool
}
} // end of namespace scribo::demo::demat
} // 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_DEMAT_SRC_MAIN_WINDOW_HH
# define SCRIBO_DEMO_DEMAT_SRC_MAIN_WINDOW_HH
# include <QtGui/QMainWindow>
# include <ui_main_window.h>
# include <src/doc_type.hh>
# include <src/preprocessing_task.hh>
# include <src/runner.hh>
# include <mln/core/image/image2d.hh>
# include <mln/core/image/dmorph/image_if.hh>
# include <mln/pw/all.hh>
# include <mln/value/rgb8.hh>
namespace scribo
{
namespace demo
{
namespace demat
{
class main_window : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT;
public:
main_window();
private slots:
void run();
void open_file_slot();
void progress_slot(unsigned i);
void update_progress_label_slot(const QString&);
void process_finished_slot();
void crop_slot();
private: // members
void load();
void prepare_progress_bar(unsigned max);
Doc_Type get_doc_type();
preprocessing_task_set_t get_tasks();
private: // attributes
QPixmap input_dsp_;
QString current_image_;
QProgressDialog* progress_;
runner runner_;
};
} // end of namespace scribo::demo::demat
} // end of namespace scribo::demo
} // end of namespace scribo
#endif // ! SCRIBO_DEMO_DEMAT_SRC_MAIN_WINDOW_HH
#undef MLN_INCLUDE_ONLY
// Windows
#include <src/main_window.cc>
// Widgets
#include <shared/src/image_viewer.cc>
// Misc
#include <src/main.cc>
#include <src/runner.cc>
// 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_PREPROCESSING_TASK_HH
# define SCRIBO_DEMO_SHARED_SRC_PREPROCESSING_TASK_HH
# include <QSet>
namespace scribo
{
namespace demo
{
enum Preprocessing_Task
{
RemoveBg = 0,
Unskew,
RemoveNoise,
ImproveContrast,
ReduceSize,
BinarizationSimple,
BinarizationSauvola,
BinarizationSauvolaMs,
PREPROCESSING_TASK_COUNT // Invalid task.
};
} // end of namespace scribo::demo
} // end of namespace scribo
typedef QSet<scribo::demo::Preprocessing_Task> preprocessing_task_set_t;
Q_DECLARE_METATYPE(preprocessing_task_set_t);
#endif // !SCRIBO_DEMO_SHARED_SRC_PREPROCESSING_TASK_HH
// 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_PROCESS_ARGS_HH
# define SCRIBO_DEMO_SHARED_SRC_PROCESS_ARGS_HH
namespace scribo
{
namespace demo
{
struct process_args
{
unsigned scale;
};
} // end of namespace scribo::demo
} // end of namespace scribo
#endif // !SCRIBO_DEMO_SHARED_SRC_PROCESS_ARGS_HH
#include <src/runner.hh>
#include <shared/src/to_mln_image.hh>
#include <src/preprocessing_task.hh>
#include <src/doc_type.hh>
#include <mln/convert/to_qimage.hh>
#include <mln/convert/to_qimage_nocopy.hh>
#include <mln/fun/v2v/rgb_to_int_u.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/rgb8.hh>
#include <mln/data/convert.hh>
#include <mln/data/paste_without_localization.hh>