ReadFramework
LayoutAnalysis.h
Go to the documentation of this file.
1 /*******************************************************************************************************
2  ReadFramework is the basis for modules developed at CVL/TU Wien for the EU project READ.
3 
4  Copyright (C) 2016 Markus Diem <diem@caa.tuwien.ac.at>
5  Copyright (C) 2016 Stefan Fiel <fiel@caa.tuwien.ac.at>
6  Copyright (C) 2016 Florian Kleber <kleber@caa.tuwien.ac.at>
7 
8  This file is part of ReadFramework.
9 
10  ReadFramework is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  ReadFramework is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23  The READ project has received funding from the European Union’s Horizon 2020
24  research and innovation programme under grant agreement No 674943
25 
26  related links:
27  [1] http://www.caa.tuwien.ac.at/cvl/
28  [2] https://transkribus.eu/Transkribus/
29  [3] https://github.com/TUWien/
30  [4] http://nomacs.org
31  *******************************************************************************************************/
32 
33 #pragma once
34 
35 #include "BaseModule.h"
36 #include "PixelSet.h"
37 #include "Image.h"
38 #include "ScaleFactory.h"
39 
40 #pragma warning(push, 0) // no warnings from includes
41 // Qt Includes
42 #pragma warning(pop)
43 
44 #ifndef DllCoreExport
45 #ifdef DLL_CORE_EXPORT
46 #define DllCoreExport Q_DECL_EXPORT
47 #else
48 #define DllCoreExport Q_DECL_IMPORT
49 #endif
50 #endif
51 
52 // Qt defines
53 
54 namespace rdf {
55 
56 // read defines
57 class Region;
58 class RootRegion;
59 class SeparatorRegion;
60 class Polygon;
61 class TextLine;
62 
64 
65 public:
67 
68  virtual QString toString() const override;
69 
70  void setRemoveWeakTextLines(bool remove);
71  bool removeWeakTextLines() const;
72 
73  void setMinSuperPixelsPerBlock(int minPx);
74  int minSuperixelsPerBlock() const;
75 
76  void setLocalBlockOrientation(bool lor);
77  bool localBlockOrientation() const;
78 
79  void setComputeSeparators(bool cs);
80  bool computeSeparators() const;
81 
82  void setClassiferPath(const QString& cp);
83  QString classifierPath() const;
84 
85 protected:
86 
87  void load(const QSettings& settings) override;
88  void save(QSettings& settings) const override;
89 
90  bool mRemoveWeakTextLines = true; // if true, unstable text lines are removed
91  int mMinSuperPixelsPerBlock = 15; // the minimum number of components that are required to run the text line segmentation
92  bool mLocalBlockOrientation = false; // local orientation is estimated per text block
93  bool mComputeSeparators = true; // if true, separators lines are computed
94  QString mClassifierPath = "";
95 };
96 
98 
99 public:
100  LayoutAnalysis(const cv::Mat& img);
101 
102  bool isEmpty() const override;
103  bool compute() override;
104  QSharedPointer<LayoutAnalysisConfig> config() const;
105 
106  cv::Mat draw(const cv::Mat& img, const QColor& col = QColor()) const;
107  QString toString() const override;
108 
109  void setRootRegion(const QSharedPointer<RootRegion>& region);
110 
111  TextBlockSet textBlockSet() const;
112  QVector<SeparatorRegion> stopLines() const;
113  PixelSet pixels() const;
114 
115  QSharedPointer<ScaleFactory> scaleFactory() const;
116 
117 private:
118  bool checkInput() const override;
119 
120  // input
121  cv::Mat mImg;
122  QSharedPointer<RootRegion> mRoot;
123 
124  // output
125  TextBlockSet mTextBlockSet;
126  QVector<Line> mStopLines;
127  QSharedPointer<ScaleFactory> mScaleFactory;
128 
129  TextBlockSet createTextBlocks() const;
130  QVector<Line> createStopLines() const;
131  bool computeLocalStats(PixelSet& pixels) const;
132 };
133 
134 
135 }
Definition: LayoutAnalysis.h:97
Definition: BaseModule.h:63
#define DllCoreExport
Definition: BaseImageElement.h:43
PixelSet stores and manipulates pixel collections.
Definition: PixelSet.h:172
config
Definition: DependencyCollector.py:271
Definition: LayoutAnalysis.h:63
DllCoreExport bool save(const QImage &img, const QString &savePath, int compression=-1)
Saves the specified QImage img.
Definition: Image.cpp:180
Stores all text blocks. This class is used to group super pixels with respect to layout constrains (e...
Definition: PixelSet.h:346
DllCoreExport QImage load(const QString &path, bool *ok=0)
Definition: Image.cpp:152
This is the base class for all modules. It provides all functions which are implemented by the module...
Definition: BaseModule.h:126
Definition: Algorithms.cpp:45