Read@CVL
Blobs.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 "Shapes.h"
36 
37 #pragma warning(push, 0) // no warnings from includes
38 // Qt Includes
39 #include <QPolygon>
40 #include <QVector>
41 #include <opencv2/core.hpp>
42 #include <opencv2/imgproc.hpp>
43 #pragma warning(pop)
44 
45 #ifndef DllCoreExport
46 #ifdef DLL_CORE_EXPORT
47 #define DllCoreExport Q_DECL_EXPORT
48 #else
49 #define DllCoreExport Q_DECL_IMPORT
50 #endif
51 #endif
52 
53 #pragma warning(disable: 4251)
54 // Qt defines
55 
56 namespace rdf {
57 
62 
63 public:
64 
65  Blob();
66 
67  Blob(const QVector<cv::Point>& outerC, const QVector<QVector<cv::Point> >& innerC);
68  bool isEmpty() const;
69 
70  //void read(const QString& pointList);
71  //QString write() const;
72  //int size() const;
73 
74  void setBlob(const QVector<cv::Point>& outerC, const QVector<QVector<cv::Point> >& innerC);
75  QVector<cv::Point> outerContour() const;
76  QVector<QVector<cv::Point> > innerContours() const;
77  QVector<cv::Vec4i> hierarchy() const;
78  float blobOrientation() const;
79  bool drawBlob(cv::Mat& imgSrc, cv::Scalar color = cv::Scalar(255, 255, 255), int maxLevel = 1) const;
80 
81 protected:
82 
83  QVector<cv::Point> mOuterContour;
84  QVector<QVector<cv::Point> > mInnerContours;
85 
86 private:
87  //QVector<cv::Vec4i> mHierarchy;
88 };
89 
90 
95 
96 public:
97 
98  Blobs();
99 
100 
101  bool isEmpty() const;
102  bool setImage(const cv::Mat& bWImg);
103  void deleteBlobs();
104  QVector<Blob> blobs() const;
105  void setBlobs(const QVector<Blob>& blobs);
106  cv::Size size() const;
107  bool compute();
108  //void read(const QString& pointList);
109  //QString write() const;
110 
111  //int size() const;
112  //bool drawBlob(cv::Mat imgSrc, cv::Scalar color = cv::Scalar(255, 255, 255)) const;
113 
114 private:
115  QVector<Blob> mBlobs;
116  cv::Mat mBwImg;
117  int mApproxMethod = CV_CHAIN_APPROX_SIMPLE;
118  cv::Size mSize;
119 
120  bool checkInput() const;
121 };
122 
123 
128 
129 public:
130 
131  static BlobManager& instance();
132  QVector<Blob> filterArea(int area, const Blobs& blobs) const;
133  QVector<Blob> filterMar(float maxAspectRatio, int minWidth, const Blobs& blobs) const;
134  QVector<Blob> filterAngle(double angle, double maxAngleDiff, const Blobs& blobs) const;
135  cv::Mat drawBlobs(const Blobs& blobs, cv::Scalar color = cv::Scalar(255, 255, 255)) const;
136  QVector<Line> lines(const Blobs& blobs) const;
137  Blob getBiggestBlob(const Blobs& blobs) const;
138 
139 private:
140  BlobManager();
141  BlobManager(const BlobManager&);
142 };
143 
144 }
Allows to manipulate the Blobs class (filter, etc.)
Definition: Blobs.h:127
Blobs class - holds a vector of Blobs and the corresponding image.
Definition: Blobs.h:94
#define DllCoreExport
Definition: BaseImageElement.h:43
QVector< cv::Point > mOuterContour
Definition: Blobs.h:83
QVector< QVector< cv::Point > > mInnerContours
Definition: Blobs.h:84
QVector< QSharedPointer< TextLineSet > > filterAngle(const QVector< QSharedPointer< TextLineSet > > &textLines, double maxAngle=4 *DK_DEG2RAD)
Definition: Algorithms.cpp:45
A class that defines a single blob within an image.
Definition: Blobs.h:61