ReadFramework
ScaleFactory.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 "Image.h"
37 #include "Shapes.h"
38 
39 #pragma warning(push, 0) // no warnings from includes
40 // Qt Includes
41 #pragma warning(pop)
42 
43 #ifndef DllCoreExport
44 #ifdef DLL_CORE_EXPORT
45 #define DllCoreExport Q_DECL_EXPORT
46 #else
47 #define DllCoreExport Q_DECL_IMPORT
48 #endif
49 #endif
50 
51 // Qt defines
52 
53 namespace rdf {
54 
55 // read defines
56 class BaseElement;
57 
63 
64 public:
66  scale_max_side = 0, // scales w.r.t to the max side usefull if you have free images
67  scale_height, // [default] choose this if you now that you have pages & double pages
68 
69  scale_end
70  };
71 
73 
74  virtual QString toString() const override;
75 
76  void setMaxImageSide(int maxSide);
77  int maxImageSide() const;
78 
79  void setScaleMode(const ScaleFactoryConfig::ScaleSideMode& mode);
80  ScaleFactoryConfig::ScaleSideMode scaleMode() const;
81 
82  int dpi() const;
83 
84 protected:
85 
86  void load(const QSettings& settings) override;
87  void save(QSettings& settings) const override;
88 
89  // 1000px == 100dpi @ A4
90  int mMaxImageSide = 1000; // maximum image side in px (larger images are downscaled accordingly)
91  int mDpi = 300; // estimated dpi (even better if we truely know it : )
92  ScaleFactoryConfig::ScaleSideMode mScaleMode = ScaleFactoryConfig::scale_height; // scaling mode (see ScaleSideMode)
93 };
94 
96 
97 public:
98  ScaleFactory(const Vector2D& imgSize = Vector2D());
99 
100  double scaleFactor();
101  double scaleFactorDpi();
102  cv::Mat scaled(cv::Mat& img);
103  void scale(BaseElement& el);
104  void scaleInv(BaseElement& el);
105  Vector2D imgSize();
106 
107  QSharedPointer<ScaleFactoryConfig> config() const;
108  void setConfig(QSharedPointer<ScaleFactoryConfig> c);
109 
110 private:
111  Vector2D mImgSize;
112  double mScaleFactor = 1.0;
113  QSharedPointer<ScaleFactoryConfig> mConfig;
114 
115  double scaleFactor(const Vector2D& size, int maxImageSize, const ScaleFactoryConfig::ScaleSideMode& mode) const;
116 };
117 
118 
119 }
Definition: BaseModule.h:63
Class that configures the ScaleFactory
Definition: ScaleFactory.h:62
Definition: ScaleFactory.h:67
#define DllCoreExport
Definition: BaseImageElement.h:43
ScaleSideMode
Definition: ScaleFactory.h:65
Definition: Shapes.h:135
config
Definition: DependencyCollector.py:271
Definition: BaseImageElement.h:53
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
Definition: Algorithms.cpp:45