Read@CVL
TextLineSegmentation.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 "Pixel.h"
37 #include "PixelSet.h"
38 #include "ScaleFactory.h"
39 
40 #pragma warning(push, 0) // no warnings from includes
41 
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 
59 
60 public:
61  SimpleTextLineConfig(QSharedPointer<ScaleFactory> scaleFactory = QSharedPointer<ScaleFactory>(new ScaleFactory()));
62 
63  virtual QString toString() const override;
64 
65  void setMaxEdgeThresh(double et); // <-- hehe E.T.
66  double maxEdgeTrhesh() const;
67 
68 protected:
69 
70  double mMaxEdgeThresh = 20; // maximum edge in px
71  QSharedPointer<ScaleFactory> mScaleFactory;
72 
73  void load(const QSettings& settings) override;
74  void save(QSettings& settings) const override;
75 };
76 
78 
79 public:
81 
82  bool isEmpty() const override;
83  bool compute() override;
84 
85  cv::Mat draw(const cv::Mat& img, const QColor& col = QColor()) const;
86  QString toString() const override;
87 
88  void addSeparatorLines(const QVector<Line>& lines);
89 
90  QVector<PixelSet> sets() const;
91  QSharedPointer<SimpleTextLineConfig> config() const;
92  QVector<QSharedPointer<TextLineSet> > textLineSets() const;
93 
94  // functions applied to the results
95  void scale(double s);
96 
97 private:
98  PixelSet mSet;
99  QVector<PixelSet> mTextLines;
100  QVector<Line> mStopLines;
101 
102  // debug - delete!
103  QVector<QSharedPointer<PixelEdge> > mEdges;
104 
105  bool checkInput() const override;
106 };
107 
108 
110 
111 public:
112  TextLineConfig();
113 
114  virtual QString toString() const override;
115 
116  void setMinLineLength(int length);
117  int minLineLength() const;
118 
119  void setMinPointDistance(double dist);
120  double minPointDistance() const;
121 
122  void setErrorMultiplier(double multiplier);
123  double errorMultiplier() const;
124 
125  QString debugPath() const;
126 
127 protected:
128 
129  int mMinLineLength = 15; // minimum text line length when clustering
130  double mMinPointDist = 80.0; // acceptable minimal distance of a point to a line
131  double mErrorMultiplier = 1.4; // maximal increase of error when merging two lines
132  QString mDebugPath = "C:/temp/cluster/"; // TODO: remove
133 
134  void load(const QSettings& settings) override;
135  void save(QSettings& settings) const override;
136 };
137 
139 
140 public:
141  TextLineSegmentation(const PixelSet& set = PixelSet());
142 
143  bool isEmpty() const override;
144  bool compute() override;
145  bool compute(const cv::Mat& img);
146  QSharedPointer<TextLineConfig> config() const;
147 
148  void addSeparatorLines(const QVector<Line>& lines);
149  QVector<QSharedPointer<TextLine> > textLines() const;
150  QVector<QSharedPointer<TextLineSet> > textLineSets() const;
151 
152  // functions applied to the results
153  void scale(double s);
154 
155  cv::Mat draw(const cv::Mat& img, const QColor& col = QColor()) const;
156  static cv::Mat draw(const cv::Mat& img, const QVector<QSharedPointer<TextLineSet> >& textLines, const QColor& col = QColor());
157  QString toString() const override;
158 
159 private:
160  PixelSet mSet;
161  //QVector<QSharedPointer<PixelEdge> > mRemovedEdges; // this is nice for debugging - but I would remove it in the end
162  QVector<QSharedPointer<TextLineSet> > mTextLines;
163  QVector<Line> mStopLines;
164 
165  bool checkInput() const override;
166 
167  QVector<QSharedPointer<TextLineSet> > clusterTextLines(const PixelGraph& graph, QVector<QSharedPointer<PixelEdge> >* removedEdges = 0) const;
168  QVector<QSharedPointer<TextLineSet> > clusterTextLinesDebug(const PixelGraph& graph, const cv::Mat& img) const;
169  int locate(const QSharedPointer<Pixel>& pixel, const QVector<QSharedPointer<TextLineSet> >& sets) const;
170  bool addPixel(QSharedPointer<TextLineSet>& set, const QSharedPointer<Pixel>& pixel, double heat) const;
171  bool mergeTextLines(const QSharedPointer<TextLineSet>& tln1, const QSharedPointer<TextLineSet>& tln2, double heat) const;
172  void filterDuplicates(PixelSet& set) const;
173 
174  // post processing
175  void mergeUnstableTextLines(QVector<QSharedPointer<TextLineSet> >& textLines) const;
176 };
177 
178 }
Definition: BaseModule.h:63
#define DllCoreExport
Definition: BaseImageElement.h:43
PixelSet stores and manipulates pixel collections.
Definition: PixelSet.h:172
Definition: TextLineSegmentation.h:58
Definition: TextLineSegmentation.h:138
Represents a pixel graph. This class comes in handy if you want to map pixel edges with pixels...
Definition: PixelSet.h:377
config
Definition: DependencyCollector.py:271
Definition: BaseModule.h:107
Definition: ScaleFactory.h:95
DllCoreExport bool save(const QImage &img, const QString &savePath, int compression=-1)
Saves the specified QImage img.
Definition: Image.cpp:180
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
Definition: TextLineSegmentation.h:109
QSharedPointer< ScaleFactory > mScaleFactory
Definition: TextLineSegmentation.h:71
Definition: TextLineSegmentation.h:77