OpenCV 4.5.3(日本語機械翻訳)
erfilter.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
27 //
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43
44 #ifndef __OPENCV_TEXT_ERFILTER_HPP__
45 #define __OPENCV_TEXT_ERFILTER_HPP__
46
47 #include "opencv2/core.hpp"
48 #include <vector>
49 #include <deque>
50 #include <string>
51
52 namespace cv
53{
54 namespace text
55{
56
59
66 struct CV_EXPORTS ERStat
67{
68 public:
70 explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0);
72 ~ERStat() { }
73
75 int pixel;
76 int level;
77
79 int area;
80 int perimeter;
81 int euler;
82 Rect rect;
83 double raw_moments[2];
84 double central_moments[3];
87
90 float convex_hull_ratio;
91 float num_inflexion_points;
92
93 // TODO Other features can be added (average color, standard deviation, and such)
94
95
96 // TODO shall we include the pixel list whenever available (i.e. after 2nd stage) ?
97 std::vector<int> *pixels;
98
101
104 ERStat* child;
105 ERStat* next;
106 ERStat* prev;
107
110 ERStat* max_probability_ancestor;
111 ERStat* min_probability_ancestor;
112};
113
118 class CV_EXPORTS_W ERFilter : public Algorithm
119{
120 public:
121
127 class CV_EXPORTS_W Callback
128 {
129 public:
130 virtual ~Callback() { }
135 virtual double eval(const ERStat& stat) = 0; //const = 0; //TODO why cannot use const = 0 here?
136 };
137
151 virtual void run( InputArray image, std::vector<ERStat>& regions ) = 0;
152
153
155 virtual void setCallback(const Ptr<ERFilter::Callback>& cb) = 0;
156 virtual void setThresholdDelta(int thresholdDelta) = 0;
157 virtual void setMinArea(float minArea) = 0;
158 virtual void setMaxArea(float maxArea) = 0;
159 virtual void setMinProbability(float minProbability) = 0;
160 virtual void setMinProbabilityDiff(float minProbabilityDiff) = 0;
161 virtual void setNonMaxSuppression(bool nonMaxSuppression) = 0;
162 virtual int getNumRejected() const = 0;
163};
164
165
166
188 int thresholdDelta = 1, float minArea = (float)0.00025,
189 float maxArea = (float)0.13, float minProbability = (float)0.4,
190 bool nonMaxSuppression = true,
191 float minProbabilityDiff = (float)0.1);
192
205 float minProbability = (float)0.3);
206
212 CV_EXPORTS_W Ptr<ERFilter> createERFilterNM1(const String& filename,
213 int thresholdDelta = 1, float minArea = (float)0.00025,
214 float maxArea = (float)0.13, float minProbability = (float)0.4,
215 bool nonMaxSuppression = true,
216 float minProbabilityDiff = (float)0.1);
217
223 CV_EXPORTS_W Ptr<ERFilter> createERFilterNM2(const String& filename,
224 float minProbability = (float)0.3);
225
232 CV_EXPORTS_W Ptr<ERFilter::Callback> loadClassifierNM1(const String& filename);
233
240 CV_EXPORTS_W Ptr<ERFilter::Callback> loadClassifierNM2(const String& filename);
241
242
244 enum { ERFILTER_NM_RGBLGrad,
245 ERFILTER_NM_IHSGrad
246 };
247
262 CV_EXPORTS_W void computeNMChannels(InputArray _src, CV_OUT OutputArrayOfArrays _channels, int _mode = ERFILTER_NM_RGBLGrad);
263
264
265
268
291 };
292
316 CV_EXPORTS void erGrouping(InputArray img, InputArrayOfArrays channels,
317 std::vector<std::vector<ERStat> > &regions,
318 std::vector<std::vector<Vec2i> > &groups,
319 std::vector<Rect> &groups_rects,
320 int method = ERGROUPING_ORIENTATION_HORIZ,
321 const std::string& filename = std::string(),
322 float minProbablity = 0.5);
323
324CV_EXPORTS_W void erGrouping(InputArray image, InputArray channel,
325 std::vector<std::vector<Point> > regions,
326 CV_OUT std::vector<Rect> &groups_rects,
327 int method = ERGROUPING_ORIENTATION_HORIZ,
328 const String& filename = String(),
329 float minProbablity = (float)0.5);
330
347 CV_EXPORTS void MSERsToERStats(InputArray image, std::vector<std::vector<Point> > &contours,
348 std::vector<std::vector<ERStat> > &regions);
349
350 // Utility funtion for scripting
351CV_EXPORTS_W void detectRegions(InputArray image, const Ptr<ERFilter>& er_filter1, const Ptr<ERFilter>& er_filter2, CV_OUT std::vector< std::vector<Point> >& regions);
352
353
366 CV_EXPORTS_W void detectRegions(InputArray image, const Ptr<ERFilter>& er_filter1, const Ptr<ERFilter>& er_filter2, CV_OUT std::vector<Rect> &groups_rects,
367 int method = ERGROUPING_ORIENTATION_HORIZ,
368 const String& filename = String(),
369 float minProbability = (float)0.5);
370
372
373}
374}
375 #endif // _OPENCV_TEXT_ERFILTER_HPP_
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
Template class for 2D rectangles
Definition: core/types.hpp:421
Callback with the classifier is made a class.
Definition: erfilter.hpp:128
virtual double eval(const ERStat &stat)=0
The classifier must return probability measure for the region.
Base class for 1st and 2nd stages of Neumann and Matas scene text detection algorithm ....
Definition: erfilter.hpp:119
virtual void run(InputArray image, std::vector< ERStat > &regions)=0
The key method of ERFilter algorithm.
virtual void setCallback(const Ptr< ERFilter::Callback > &cb)=0
set/get methods to set the algorithm properties,
CV_EXPORTS_W Ptr< ERFilter::Callback > loadClassifierNM2(const String &filename)
Allow to implicitly load the default classifier when creating an ERFilter object.
CV_EXPORTS void MSERsToERStats(InputArray image, std::vector< std::vector< Point > > &contours, std::vector< std::vector< ERStat > > &regions)
Converts MSER contours (vector<Point>) to ERStat regions.
CV_EXPORTS_W void computeNMChannels(InputArray _src, CV_OUT OutputArrayOfArrays _channels, int _mode=ERFILTER_NM_RGBLGrad)
Compute the different channels to be processed independently in the N&M algorithm .
CV_EXPORTS_W void detectRegions(InputArray image, const Ptr< ERFilter > &er_filter1, const Ptr< ERFilter > &er_filter2, CV_OUT std::vector< Rect > &groups_rects, int method=ERGROUPING_ORIENTATION_HORIZ, const String &filename=String(), float minProbability=(float) 0.5)
Extracts text regions from image.
CV_EXPORTS_W Ptr< ERFilter > createERFilterNM1(const String &filename, int thresholdDelta=1, float minArea=(float) 0.00025, float maxArea=(float) 0.13, float minProbability=(float) 0.4, bool nonMaxSuppression=true, float minProbabilityDiff=(float) 0.1)
Reads an Extremal Region Filter for the 1st stage classifier of N&M algorithm from the provided path ...
CV_EXPORTS void erGrouping(InputArray img, InputArrayOfArrays channels, std::vector< std::vector< ERStat > > &regions, std::vector< std::vector< Vec2i > > &groups, std::vector< Rect > &groups_rects, int method=ERGROUPING_ORIENTATION_HORIZ, const std::string &filename=std::string(), float minProbablity=0.5)
Find groups of Extremal Regions that are organized as text blocks.
CV_EXPORTS_W Ptr< ERFilter > createERFilterNM2(const String &filename, float minProbability=(float) 0.3)
Reads an Extremal Region Filter for the 2nd stage classifier of N&M algorithm from the provided path ...
erGrouping_Modes
text::erGrouping operation modes
Definition: erfilter.hpp:267
CV_EXPORTS_W Ptr< ERFilter::Callback > loadClassifierNM1(const String &filename)
Allow to implicitly load the default classifier when creating an ERFilter object.
@ ERGROUPING_ORIENTATION_HORIZ
Definition: erfilter.hpp:279
@ ERGROUPING_ORIENTATION_ANY
Definition: erfilter.hpp:290
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74
The ERStat structure represents a class-specific Extremal Region (ER).
Definition: erfilter.hpp:67
float hole_area_ratio
2nd stage features
Definition: erfilter.hpp:89
bool local_maxima
whenever the regions is a local maxima of the probability
Definition: erfilter.hpp:109
int area
incrementally computable features
Definition: erfilter.hpp:79
ERStat(int level=256, int pixel=0, int x=0, int y=0)
Constructor
Ptr< std::deque< int > > crossings
horizontal crossings
Definition: erfilter.hpp:85
float med_crossings
median of the crossings at three different height levels
Definition: erfilter.hpp:86
double probability
probability that the ER belongs to the class we are looking for
Definition: erfilter.hpp:100
ERStat * parent
pointers preserving the tree structure of the component tree
Definition: erfilter.hpp:103
int euler
Euler's number
Definition: erfilter.hpp:81
int pixel
seed point and the threshold (max grey-level value)
Definition: erfilter.hpp:75
~ERStat()
Destructor
Definition: erfilter.hpp:72