From: Vadim Pisarevsky Date: Mon, 28 Jul 2014 12:48:53 +0000 (+0400) Subject: removed ERFilter (to be moved to opencv_contrib/modules/text) and lineMOD (to be... X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~251^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ad9827fc4ede1b9c42515569fcc5d8d1106a4ea;p=profile%2Fivi%2Fopencv.git removed ERFilter (to be moved to opencv_contrib/modules/text) and lineMOD (to be moved to opencv_contrib/modules/rgbd) --- diff --git a/modules/objdetect/doc/erfilter.rst b/modules/objdetect/doc/erfilter.rst deleted file mode 100644 index 85d6bcc..0000000 --- a/modules/objdetect/doc/erfilter.rst +++ /dev/null @@ -1,211 +0,0 @@ -Scene Text Detection -==================== - -.. highlight:: cpp - -Class-specific Extremal Regions for Scene Text Detection --------------------------------------------------------- - -The scene text detection algorithm described below has been initially proposed by Lukás Neumann & Jiri Matas [Neumann12]. The main idea behind Class-specific Extremal Regions is similar to the MSER in that suitable Extremal Regions (ERs) are selected from the whole component tree of the image. However, this technique differs from MSER in that selection of suitable ERs is done by a sequential classifier trained for character detection, i.e. dropping the stability requirement of MSERs and selecting class-specific (not necessarily stable) regions. - -The component tree of an image is constructed by thresholding by an increasing value step-by-step from 0 to 255 and then linking the obtained connected components from successive levels in a hierarchy by their inclusion relation: - -.. image:: pics/component_tree.png - :width: 100% - -The component tree may conatain a huge number of regions even for a very simple image as shown in the previous image. This number can easily reach the order of 1 x 10^6 regions for an average 1 Megapixel image. In order to efficiently select suitable regions among all the ERs the algorithm make use of a sequential classifier with two differentiated stages. - -In the first stage incrementally computable descriptors (area, perimeter, bounding box, and euler number) are computed (in O(1)) for each region r and used as features for a classifier which estimates the class-conditional probability p(r|character). Only the ERs which correspond to local maximum of the probability p(r|character) are selected (if their probability is above a global limit p_min and the difference between local maximum and local minimum is greater than a \delta_min value). - -In the second stage, the ERs that passed the first stage are classified into character and non-character classes using more informative but also more computationally expensive features. (Hole area ratio, convex hull ratio, and the number of outer boundary inflexion points). - -This ER filtering process is done in different single-channel projections of the input image in order to increase the character localization recall. - -After the ER filtering is done on each input channel, character candidates must be grouped in high-level text blocks (i.e. words, text lines, paragraphs, ...). The grouping algorithm used in this implementation has been proposed by Lluis Gomez and Dimosthenis Karatzas in [Gomez13] and basically consist in finding meaningful groups of regions using a perceptual organization based clustering analisys (see :ocv:func:`erGrouping`). - - -To see the text detector at work, have a look at the textdetection demo: https://github.com/Itseez/opencv/blob/master/samples/cpp/textdetection.cpp - - -.. [Neumann12] Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012. The paper is available online at http://cmp.felk.cvut.cz/~neumalu1/neumann-cvpr2012.pdf - -.. [Gomez13] Gomez L. and Karatzas D.: Multi-script Text Extraction from Natural Scenes, ICDAR 2013. The paper is available online at http://158.109.8.37/files/GoK2013.pdf - - -ERStat ------- -.. ocv:struct:: ERStat - -The ERStat structure represents a class-specific Extremal Region (ER). - -An ER is a 4-connected set of pixels with all its grey-level values smaller than the values in its outer boundary. A class-specific ER is selected (using a classifier) from all the ER's in the component tree of the image. :: - - struct CV_EXPORTS ERStat - { - public: - //! Constructor - explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0); - //! Destructor - ~ERStat() { } - - //! seed point and threshold (max grey-level value) - int pixel; - int level; - - //! incrementally computable features - int area; - int perimeter; - int euler; //!< euler number - Rect rect; //!< bounding box - double raw_moments[2]; //!< order 1 raw moments to derive the centroid - double central_moments[3]; //!< order 2 central moments to construct the covariance matrix - std::deque *crossings;//!< horizontal crossings - float med_crossings; //!< median of the crossings at three different height levels - - //! 2nd stage features - float hole_area_ratio; - float convex_hull_ratio; - float num_inflexion_points; - - //! probability that the ER belongs to the class we are looking for - double probability; - - //! pointers preserving the tree structure of the component tree - ERStat* parent; - ERStat* child; - ERStat* next; - ERStat* prev; - }; - -computeNMChannels ------------------ -Compute the different channels to be processed independently in the N&M algorithm [Neumann12]. - -.. ocv:function:: void computeNMChannels(InputArray _src, OutputArrayOfArrays _channels, int _mode = ERFILTER_NM_RGBLGrad) - - :param _src: Source image. Must be RGB ``CV_8UC3``. - :param _channels: Output vector where computed channels are stored. - :param _mode: Mode of operation. Currently the only available options are: **ERFILTER_NM_RGBLGrad** (used by default) and **ERFILTER_NM_IHSGrad**. - -In N&M algorithm, the combination of intensity (I), hue (H), saturation (S), and gradient magnitude channels (Grad) are used in order to obtain high localization recall. This implementation also provides an alternative combination of red (R), green (G), blue (B), lightness (L), and gradient magnitude (Grad). - - -ERFilter --------- -.. ocv:class:: ERFilter : public Algorithm - -Base class for 1st and 2nd stages of Neumann and Matas scene text detection algorithm [Neumann12]. :: - - class CV_EXPORTS ERFilter : public Algorithm - { - public: - - //! callback with the classifier is made a class. - //! By doing it we hide SVM, Boost etc. Developers can provide their own classifiers - class CV_EXPORTS Callback - { - public: - virtual ~Callback() { } - //! The classifier must return probability measure for the region. - virtual double eval(const ERStat& stat) = 0; - }; - - /*! - the key method. Takes image on input and returns the selected regions in a vector of ERStat - only distinctive ERs which correspond to characters are selected by a sequential classifier - */ - virtual void run( InputArray image, std::vector& regions ) = 0; - - (...) - - }; - - - -ERFilter::Callback ------------------- -Callback with the classifier is made a class. By doing it we hide SVM, Boost etc. Developers can provide their own classifiers to the ERFilter algorithm. - -.. ocv:class:: ERFilter::Callback - -ERFilter::Callback::eval ------------------------- -The classifier must return probability measure for the region. - -.. ocv:function:: double ERFilter::Callback::eval(const ERStat& stat) - - :param stat: The region to be classified - -ERFilter::run -------------- -The key method of ERFilter algorithm. Takes image on input and returns the selected regions in a vector of ERStat only distinctive ERs which correspond to characters are selected by a sequential classifier - -.. ocv:function:: void ERFilter::run( InputArray image, std::vector& regions ) - - :param image: Sinle channel image ``CV_8UC1`` - :param regions: Output for the 1st stage and Input/Output for the 2nd. The selected Extremal Regions are stored here. - -Extracts the component tree (if needed) and filter the extremal regions (ER's) by using a given classifier. - -createERFilterNM1 ------------------ -Create an Extremal Region Filter for the 1st stage classifier of N&M algorithm [Neumann12]. - -.. ocv:function:: Ptr createERFilterNM1( const Ptr& cb, int thresholdDelta = 1, float minArea = 0.00025, float maxArea = 0.13, float minProbability = 0.4, bool nonMaxSuppression = true, float minProbabilityDiff = 0.1 ) - - :param cb: Callback with the classifier. Default classifier can be implicitly load with function :ocv:func:`loadClassifierNM1`, e.g. from file in samples/cpp/trained_classifierNM1.xml - :param thresholdDelta: Threshold step in subsequent thresholds when extracting the component tree - :param minArea: The minimum area (% of image size) allowed for retreived ER's - :param minArea: The maximum area (% of image size) allowed for retreived ER's - :param minProbability: The minimum probability P(er|character) allowed for retreived ER's - :param nonMaxSuppression: Whenever non-maximum suppression is done over the branch probabilities - :param minProbability: The minimum probability difference between local maxima and local minima ERs - -The component tree of the image is extracted by a threshold increased step by step from 0 to 255, incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of horizontal crossings) are computed for each ER and used as features for a classifier which estimates the class-conditional probability P(er|character). The value of P(er|character) is tracked using the inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of the probability P(er|character) are selected (if the local maximum of the probability is above a global limit pmin and the difference between local maximum and local minimum is greater than minProbabilityDiff). - -createERFilterNM2 ------------------ -Create an Extremal Region Filter for the 2nd stage classifier of N&M algorithm [Neumann12]. - -.. ocv:function:: Ptr createERFilterNM2( const Ptr& cb, float minProbability = 0.3 ) - - :param cb: Callback with the classifier. Default classifier can be implicitly load with function :ocv:func:`loadClassifierNM2`, e.g. from file in samples/cpp/trained_classifierNM2.xml - :param minProbability: The minimum probability P(er|character) allowed for retreived ER's - -In the second stage, the ERs that passed the first stage are classified into character and non-character classes using more informative but also more computationally expensive features. The classifier uses all the features calculated in the first stage and the following additional features: hole area ratio, convex hull ratio, and number of outer inflexion points. - -loadClassifierNM1 ------------------ -Allow to implicitly load the default classifier when creating an ERFilter object. - -.. ocv:function:: Ptr loadClassifierNM1(const std::string& filename) - - :param filename: The XML or YAML file with the classifier model (e.g. trained_classifierNM1.xml) - -returns a pointer to ERFilter::Callback. - -loadClassifierNM2 ------------------ -Allow to implicitly load the default classifier when creating an ERFilter object. - -.. ocv:function:: Ptr loadClassifierNM2(const std::string& filename) - - :param filename: The XML or YAML file with the classifier model (e.g. trained_classifierNM2.xml) - -returns a pointer to ERFilter::Callback. - -erGrouping ----------- -Find groups of Extremal Regions that are organized as text blocks. - -.. ocv:function:: void erGrouping( InputArrayOfArrays src, std::vector > ®ions, const std::string& filename, float minProbablity, std::vector &groups) - - :param src: Vector of sinle channel images CV_8UC1 from wich the regions were extracted - :param regions: Vector of ER's retreived from the ERFilter algorithm from each channel - :param filename: The XML or YAML file with the classifier model (e.g. trained_classifier_erGrouping.xml) - :param minProbability: The minimum probability for accepting a group - :param groups: The output of the algorithm are stored in this parameter as list of rectangles. - -This function implements the grouping algorithm described in [Gomez13]. Notice that this implementation constrains the results to horizontally-aligned text and latin script (since ERFilter classifiers are trained only for latin script detection). - -The algorithm combines two different clustering techniques in a single parameter-free procedure to detect groups of regions organized as text. The maximally meaningful groups are fist detected in several feature spaces, where each feature space is a combination of proximity information (x,y coordinates) and a similarity measure (intensity, color, size, gradient magnitude, etc.), thus providing a set of hypotheses of text groups. Evidence Accumulation framework is used to combine all these hypotheses to get the final estimate. Each of the resulting groups are finally validated using a classifier in order to assess if they form a valid horizontally-aligned text block. diff --git a/modules/objdetect/doc/latent_svm.rst b/modules/objdetect/doc/latent_svm.rst deleted file mode 100644 index 4b4ff11..0000000 --- a/modules/objdetect/doc/latent_svm.rst +++ /dev/null @@ -1,262 +0,0 @@ -Latent SVM -=============================================================== - -Discriminatively Trained Part Based Models for Object Detection ---------------------------------------------------------------- - -The object detector described below has been initially proposed by -P.F. Felzenszwalb in [Felzenszwalb2010]_. It is based on a -Dalal-Triggs detector that uses a single filter on histogram of -oriented gradients (HOG) features to represent an object category. -This detector uses a sliding window approach, where a filter is -applied at all positions and scales of an image. The first -innovation is enriching the Dalal-Triggs model using a -star-structured part-based model defined by a "root" filter -(analogous to the Dalal-Triggs filter) plus a set of parts filters -and associated deformation models. The score of one of star models -at a particular position and scale within an image is the score of -the root filter at the given location plus the sum over parts of the -maximum, over placements of that part, of the part filter score on -its location minus a deformation cost easuring the deviation of the -part from its ideal location relative to the root. Both root and -part filter scores are defined by the dot product between a filter -(a set of weights) and a subwindow of a feature pyramid computed -from the input image. Another improvement is a representation of the -class of models by a mixture of star models. The score of a mixture -model at a particular position and scale is the maximum over -components, of the score of that component model at the given -location. - -In OpenCV there are C implementation of Latent SVM and C++ wrapper of it. -C version is the structure :ocv:struct:`CvObjectDetection` and a set of functions -working with this structure (see :ocv:func:`cvLoadLatentSvmDetector`, -:ocv:func:`cvReleaseLatentSvmDetector`, :ocv:func:`cvLatentSvmDetectObjects`). -C++ version is the class :ocv:class:`LatentSvmDetector` and has slightly different -functionality in contrast with C version - it supports loading and detection -of several models. - -There are two examples of Latent SVM usage: ``samples/c/latentsvmdetect.cpp`` -and ``samples/cpp/latentsvm_multidetect.cpp``. - -.. highlight:: c - - -CvLSVMFilterPosition --------------------- -.. ocv:struct:: CvLSVMFilterPosition - - Structure describes the position of the filter in the feature pyramid. - - .. ocv:member:: unsigned int l - - level in the feature pyramid - - .. ocv:member:: unsigned int x - - x-coordinate in level l - - .. ocv:member:: unsigned int y - - y-coordinate in level l - - -CvLSVMFilterObject ------------------- -.. ocv:struct:: CvLSVMFilterObject - - Description of the filter, which corresponds to the part of the object. - - .. ocv:member:: CvLSVMFilterPosition V - - ideal (penalty = 0) position of the partial filter - from the root filter position (V_i in the paper) - - .. ocv:member:: float fineFunction[4] - - vector describes penalty function (d_i in the paper) - pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2 - - .. ocv:member:: int sizeX - .. ocv:member:: int sizeY - - Rectangular map (sizeX x sizeY), - every cell stores feature vector (dimension = p) - - .. ocv:member:: int numFeatures - - number of features - - .. ocv:member:: float *H - - matrix of feature vectors to set and get - feature vectors (i,j) used formula H[(j * sizeX + i) * p + k], - where k - component of feature vector in cell (i, j) - -CvLatentSvmDetector -------------------- -.. ocv:struct:: CvLatentSvmDetector - - Structure contains internal representation of trained Latent SVM detector. - - .. ocv:member:: int num_filters - - total number of filters (root plus part) in model - - .. ocv:member:: int num_components - - number of components in model - - .. ocv:member:: int* num_part_filters - - array containing number of part filters for each component - - .. ocv:member:: CvLSVMFilterObject** filters - - root and part filters for all model components - - .. ocv:member:: float* b - - biases for all model components - - .. ocv:member:: float score_threshold - - confidence level threshold - - -CvObjectDetection ------------------ -.. ocv:struct:: CvObjectDetection - - Structure contains the bounding box and confidence level for detected object. - - .. ocv:member:: CvRect rect - - bounding box for a detected object - - .. ocv:member:: float score - - confidence level - - -cvLoadLatentSvmDetector ------------------------ -Loads trained detector from a file. - -.. ocv:function:: CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename) - - :param filename: Name of the file containing the description of a trained detector - - -cvReleaseLatentSvmDetector --------------------------- -Release memory allocated for CvLatentSvmDetector structure. - -.. ocv:function:: void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector) - - :param detector: CvLatentSvmDetector structure to be released - - -cvLatentSvmDetectObjects ------------------------- -Find rectangular regions in the given image that are likely to contain objects -and corresponding confidence levels. - -.. ocv:function:: CvSeq* cvLatentSvmDetectObjects( IplImage* image, CvLatentSvmDetector* detector, CvMemStorage* storage, float overlap_threshold=0.5f, int numThreads=-1 ) - - :param image: image - :param detector: LatentSVM detector in internal representation - :param storage: Memory storage to store the resultant sequence of the object candidate rectangles - :param overlap_threshold: Threshold for the non-maximum suppression algorithm - :param numThreads: Number of threads used in parallel version of the algorithm - -.. highlight:: cpp - -LatentSvmDetector ------------------ -.. ocv:class:: LatentSvmDetector - -This is a C++ wrapping class of Latent SVM. It contains internal representation of several -trained Latent SVM detectors (models) and a set of methods to load the detectors and detect objects -using them. - -LatentSvmDetector::ObjectDetection ----------------------------------- -.. ocv:struct:: LatentSvmDetector::ObjectDetection - - Structure contains the detection information. - - .. ocv:member:: Rect rect - - bounding box for a detected object - - .. ocv:member:: float score - - confidence level - - .. ocv:member:: int classID - - class (model or detector) ID that detect an object - - -LatentSvmDetector::LatentSvmDetector ------------------------------------- -Two types of constructors. - -.. ocv:function:: LatentSvmDetector::LatentSvmDetector() - -.. ocv:function:: LatentSvmDetector::LatentSvmDetector(const vector& filenames, const vector& classNames=vector()) - - - - :param filenames: A set of filenames storing the trained detectors (models). Each file contains one model. See examples of such files here /opencv_extra/testdata/cv/latentsvmdetector/models_VOC2007/. - - :param classNames: A set of trained models names. If it's empty then the name of each model will be constructed from the name of file containing the model. E.g. the model stored in "/home/user/cat.xml" will get the name "cat". - -LatentSvmDetector::~LatentSvmDetector -------------------------------------- -Destructor. - -.. ocv:function:: LatentSvmDetector::~LatentSvmDetector() - -LatentSvmDetector::~clear -------------------------- -Clear all trained models and their names stored in an class object. - -.. ocv:function:: void LatentSvmDetector::clear() - -LatentSvmDetector::load ------------------------ -Load the trained models from given ``.xml`` files and return ``true`` if at least one model was loaded. - -.. ocv:function:: bool LatentSvmDetector::load( const vector& filenames, const vector& classNames=vector() ) - - :param filenames: A set of filenames storing the trained detectors (models). Each file contains one model. See examples of such files here /opencv_extra/testdata/cv/latentsvmdetector/models_VOC2007/. - - :param classNames: A set of trained models names. If it's empty then the name of each model will be constructed from the name of file containing the model. E.g. the model stored in "/home/user/cat.xml" will get the name "cat". - -LatentSvmDetector::detect -------------------------- -Find rectangular regions in the given image that are likely to contain objects of loaded classes (models) -and corresponding confidence levels. - -.. ocv:function:: void LatentSvmDetector::detect( const Mat& image, vector& objectDetections, float overlapThreshold=0.5f, int numThreads=-1 ) - - :param image: An image. - :param objectDetections: The detections: rectangulars, scores and class IDs. - :param overlapThreshold: Threshold for the non-maximum suppression algorithm. - :param numThreads: Number of threads used in parallel version of the algorithm. - -LatentSvmDetector::getClassNames --------------------------------- -Return the class (model) names that were passed in constructor or method ``load`` or extracted from models filenames in those methods. - -.. ocv:function:: const vector& LatentSvmDetector::getClassNames() const - -LatentSvmDetector::getClassCount --------------------------------- -Return a count of loaded models (classes). - -.. ocv:function:: size_t LatentSvmDetector::getClassCount() const - - -.. [Felzenszwalb2010] Felzenszwalb, P. F. and Girshick, R. B. and McAllester, D. and Ramanan, D. *Object Detection with Discriminatively Trained Part Based Models*. PAMI, vol. 32, no. 9, pp. 1627-1645, September 2010 diff --git a/modules/objdetect/doc/objdetect.rst b/modules/objdetect/doc/objdetect.rst index 0cd8cf3..bbd5d0e 100644 --- a/modules/objdetect/doc/objdetect.rst +++ b/modules/objdetect/doc/objdetect.rst @@ -8,5 +8,4 @@ objdetect. Object Detection :maxdepth: 2 cascade_classification - latent_svm erfilter diff --git a/modules/objdetect/doc/pics/component_tree.png b/modules/objdetect/doc/pics/component_tree.png deleted file mode 100644 index 7391e2d..0000000 Binary files a/modules/objdetect/doc/pics/component_tree.png and /dev/null differ diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index 79e213e..4ccb810 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -315,8 +315,6 @@ public: } -#include "opencv2/objdetect/linemod.hpp" -#include "opencv2/objdetect/erfilter.hpp" #include "opencv2/objdetect/detection_based_tracker.hpp" #endif diff --git a/modules/objdetect/include/opencv2/objdetect/erfilter.hpp b/modules/objdetect/include/opencv2/objdetect/erfilter.hpp deleted file mode 100644 index d7e07d8..0000000 --- a/modules/objdetect/include/opencv2/objdetect/erfilter.hpp +++ /dev/null @@ -1,266 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#ifndef __OPENCV_OBJDETECT_ERFILTER_HPP__ -#define __OPENCV_OBJDETECT_ERFILTER_HPP__ - -#include "opencv2/core.hpp" -#include -#include -#include - -namespace cv -{ - -/*! - Extremal Region Stat structure - - The ERStat structure represents a class-specific Extremal Region (ER). - - An ER is a 4-connected set of pixels with all its grey-level values smaller than the values - in its outer boundary. A class-specific ER is selected (using a classifier) from all the ER's - in the component tree of the image. -*/ -struct CV_EXPORTS ERStat -{ -public: - //! Constructor - explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0); - //! Destructor - ~ERStat() { } - - //! seed point and the threshold (max grey-level value) - int pixel; - int level; - - //! incrementally computable features - int area; - int perimeter; - int euler; //!< euler number - Rect rect; - double raw_moments[2]; //!< order 1 raw moments to derive the centroid - double central_moments[3]; //!< order 2 central moments to construct the covariance matrix - std::deque *crossings;//!< horizontal crossings - float med_crossings; //!< median of the crossings at three different height levels - - //! 2nd stage features - float hole_area_ratio; - float convex_hull_ratio; - float num_inflexion_points; - - // TODO Other features can be added (average color, standard deviation, and such) - - - // TODO shall we include the pixel list whenever available (i.e. after 2nd stage) ? - std::vector *pixels; - - //! probability that the ER belongs to the class we are looking for - double probability; - - //! pointers preserving the tree structure of the component tree - ERStat* parent; - ERStat* child; - ERStat* next; - ERStat* prev; - - //! wenever the regions is a local maxima of the probability - bool local_maxima; - ERStat* max_probability_ancestor; - ERStat* min_probability_ancestor; -}; - -/*! - Base class for 1st and 2nd stages of Neumann and Matas scene text detection algorithms - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012 - - Extracts the component tree (if needed) and filter the extremal regions (ER's) by using a given classifier. -*/ -class CV_EXPORTS ERFilter : public Algorithm -{ -public: - - //! callback with the classifier is made a class. By doing it we hide SVM, Boost etc. - class CV_EXPORTS Callback - { - public: - virtual ~Callback() { } - //! The classifier must return probability measure for the region. - virtual double eval(const ERStat& stat) = 0; //const = 0; //TODO why cannot use const = 0 here? - }; - - /*! - the key method. Takes image on input and returns the selected regions in a vector of ERStat - only distinctive ERs which correspond to characters are selected by a sequential classifier - \param image is the input image - \param regions is output for the first stage, input/output for the second one. - */ - virtual void run( InputArray image, std::vector& regions ) = 0; - - - //! set/get methods to set the algorithm properties, - virtual void setCallback(const Ptr& cb) = 0; - virtual void setThresholdDelta(int thresholdDelta) = 0; - virtual void setMinArea(float minArea) = 0; - virtual void setMaxArea(float maxArea) = 0; - virtual void setMinProbability(float minProbability) = 0; - virtual void setMinProbabilityDiff(float minProbabilityDiff) = 0; - virtual void setNonMaxSuppression(bool nonMaxSuppression) = 0; - virtual int getNumRejected() = 0; -}; - - -/*! - Create an Extremal Region Filter for the 1st stage classifier of N&M algorithm - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012 - - The component tree of the image is extracted by a threshold increased step by step - from 0 to 255, incrementally computable descriptors (aspect_ratio, compactness, - number of holes, and number of horizontal crossings) are computed for each ER - and used as features for a classifier which estimates the class-conditional - probability P(er|character). The value of P(er|character) is tracked using the inclusion - relation of ER across all thresholds and only the ERs which correspond to local maximum - of the probability P(er|character) are selected (if the local maximum of the - probability is above a global limit pmin and the difference between local maximum and - local minimum is greater than minProbabilityDiff). - - \param cb Callback with the classifier. - default classifier can be implicitly load with function loadClassifierNM1() - from file in samples/cpp/trained_classifierNM1.xml - \param thresholdDelta Threshold step in subsequent thresholds when extracting the component tree - \param minArea The minimum area (% of image size) allowed for retreived ER's - \param minArea The maximum area (% of image size) allowed for retreived ER's - \param minProbability The minimum probability P(er|character) allowed for retreived ER's - \param nonMaxSuppression Whenever non-maximum suppression is done over the branch probabilities - \param minProbability The minimum probability difference between local maxima and local minima ERs -*/ -CV_EXPORTS Ptr createERFilterNM1(const Ptr& cb, - int thresholdDelta = 1, float minArea = 0.00025, - float maxArea = 0.13, float minProbability = 0.4, - bool nonMaxSuppression = true, - float minProbabilityDiff = 0.1); - -/*! - Create an Extremal Region Filter for the 2nd stage classifier of N&M algorithm - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012 - - In the second stage, the ERs that passed the first stage are classified into character - and non-character classes using more informative but also more computationally expensive - features. The classifier uses all the features calculated in the first stage and the following - additional features: hole area ratio, convex hull ratio, and number of outer inflexion points. - - \param cb Callback with the classifier - default classifier can be implicitly load with function loadClassifierNM2() - from file in samples/cpp/trained_classifierNM2.xml - \param minProbability The minimum probability P(er|character) allowed for retreived ER's -*/ -CV_EXPORTS Ptr createERFilterNM2(const Ptr& cb, - float minProbability = 0.3); - - -/*! - Allow to implicitly load the default classifier when creating an ERFilter object. - The function takes as parameter the XML or YAML file with the classifier model - (e.g. trained_classifierNM1.xml) returns a pointer to ERFilter::Callback. -*/ - -CV_EXPORTS Ptr loadClassifierNM1(const std::string& filename); - -/*! - Allow to implicitly load the default classifier when creating an ERFilter object. - The function takes as parameter the XML or YAML file with the classifier model - (e.g. trained_classifierNM1.xml) returns a pointer to ERFilter::Callback. -*/ - -CV_EXPORTS Ptr loadClassifierNM2(const std::string& filename); - - -// computeNMChannels operation modes -enum { ERFILTER_NM_RGBLGrad = 0, - ERFILTER_NM_IHSGrad = 1 - }; - -/*! - Compute the different channels to be processed independently in the N&M algorithm - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012 - - In N&M algorithm, the combination of intensity (I), hue (H), saturation (S), and gradient - magnitude channels (Grad) are used in order to obtain high localization recall. - This implementation also provides an alternative combination of red (R), green (G), blue (B), - lightness (L), and gradient magnitude (Grad). - - \param _src Source image. Must be RGB CV_8UC3. - \param _channels Output vector where computed channels are stored. - \param _mode Mode of operation. Currently the only available options are - ERFILTER_NM_RGBLGrad (by default) and ERFILTER_NM_IHSGrad. - -*/ -CV_EXPORTS void computeNMChannels(InputArray _src, OutputArrayOfArrays _channels, int _mode = ERFILTER_NM_RGBLGrad); - - -/*! - Find groups of Extremal Regions that are organized as text blocks. This function implements - the grouping algorithm described in: - Gomez L. and Karatzas D.: Multi-script Text Extraction from Natural Scenes, ICDAR 2013. - Notice that this implementation constrains the results to horizontally-aligned text and - latin script (since ERFilter classifiers are trained only for latin script detection). - - The algorithm combines two different clustering techniques in a single parameter-free procedure - to detect groups of regions organized as text. The maximally meaningful groups are fist detected - in several feature spaces, where each feature space is a combination of proximity information - (x,y coordinates) and a similarity measure (intensity, color, size, gradient magnitude, etc.), - thus providing a set of hypotheses of text groups. Evidence Accumulation framework is used to - combine all these hypotheses to get the final estimate. Each of the resulting groups are finally - validated using a classifier in order to assest if they form a valid horizontally-aligned text block. - - \param src Vector of sinle channel images CV_8UC1 from wich the regions were extracted. - \param regions Vector of ER's retreived from the ERFilter algorithm from each channel - \param filename The XML or YAML file with the classifier model (e.g. trained_classifier_erGrouping.xml) - \param minProbability The minimum probability for accepting a group - \param groups The output of the algorithm are stored in this parameter as list of rectangles. -*/ -CV_EXPORTS void erGrouping(InputArrayOfArrays src, std::vector > ®ions, - const std::string& filename, float minProbablity, - std::vector &groups); - -} -#endif // _OPENCV_ERFILTER_HPP_ diff --git a/modules/objdetect/include/opencv2/objdetect/linemod.hpp b/modules/objdetect/include/opencv2/objdetect/linemod.hpp deleted file mode 100644 index 46d8699..0000000 --- a/modules/objdetect/include/opencv2/objdetect/linemod.hpp +++ /dev/null @@ -1,455 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#ifndef __OPENCV_OBJDETECT_LINEMOD_HPP__ -#define __OPENCV_OBJDETECT_LINEMOD_HPP__ - -#include "opencv2/core.hpp" -#include - -/****************************************************************************************\ -* LINE-MOD * -\****************************************************************************************/ - -namespace cv { -namespace linemod { - -/// @todo Convert doxy comments to rst - -/** - * \brief Discriminant feature described by its location and label. - */ -struct CV_EXPORTS Feature -{ - int x; ///< x offset - int y; ///< y offset - int label; ///< Quantization - - Feature() : x(0), y(0), label(0) {} - Feature(int x, int y, int label); - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {} - -struct CV_EXPORTS Template -{ - int width; - int height; - int pyramid_level; - std::vector features; - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -/** - * \brief Represents a modality operating over an image pyramid. - */ -class QuantizedPyramid -{ -public: - // Virtual destructor - virtual ~QuantizedPyramid() {} - - /** - * \brief Compute quantized image at current pyramid level for online detection. - * - * \param[out] dst The destination 8-bit image. For each pixel at most one bit is set, - * representing its classification. - */ - virtual void quantize(Mat& dst) const =0; - - /** - * \brief Extract most discriminant features at current pyramid level to form a new template. - * - * \param[out] templ The new template. - */ - virtual bool extractTemplate(Template& templ) const =0; - - /** - * \brief Go to the next pyramid level. - * - * \todo Allow pyramid scale factor other than 2 - */ - virtual void pyrDown() =0; - -protected: - /// Candidate feature with a score - struct Candidate - { - Candidate(int x, int y, int label, float score); - - /// Sort candidates with high score to the front - bool operator<(const Candidate& rhs) const - { - return score > rhs.score; - } - - Feature f; - float score; - }; - - /** - * \brief Choose candidate features so that they are not bunched together. - * - * \param[in] candidates Candidate features sorted by score. - * \param[out] features Destination vector of selected features. - * \param[in] num_features Number of candidates to select. - * \param[in] distance Hint for desired distance between features. - */ - static void selectScatteredFeatures(const std::vector& candidates, - std::vector& features, - size_t num_features, float distance); -}; - -inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _score) : f(x, y, label), score(_score) {} - -/** - * \brief Interface for modalities that plug into the LINE template matching representation. - * - * \todo Max response, to allow optimization of summing (255/MAX) features as uint8 - */ -class CV_EXPORTS Modality -{ -public: - // Virtual destructor - virtual ~Modality() {} - - /** - * \brief Form a quantized image pyramid from a source image. - * - * \param[in] src The source image. Type depends on the modality. - * \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero - * in quantized image and cannot be extracted as features. - */ - Ptr process(const Mat& src, - const Mat& mask = Mat()) const - { - return processImpl(src, mask); - } - - virtual String name() const =0; - - virtual void read(const FileNode& fn) =0; - virtual void write(FileStorage& fs) const =0; - - /** - * \brief Create modality by name. - * - * The following modality types are supported: - * - "ColorGradient" - * - "DepthNormal" - */ - static Ptr create(const String& modality_type); - - /** - * \brief Load a modality from file. - */ - static Ptr create(const FileNode& fn); - -protected: - // Indirection is because process() has a default parameter. - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const =0; -}; - -/** - * \brief Modality that computes quantized gradient orientations from a color image. - */ -class CV_EXPORTS ColorGradient : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - ColorGradient(); - - /** - * \brief Constructor. - * - * \param weak_threshold When quantizing, discard gradients with magnitude less than this. - * \param num_features How many features a template must contain. - * \param strong_threshold Consider as candidate features only gradients whose norms are - * larger than this. - */ - ColorGradient(float weak_threshold, size_t num_features, float strong_threshold); - - virtual String name() const; - - virtual void read(const FileNode& fn); - virtual void write(FileStorage& fs) const; - - float weak_threshold; - size_t num_features; - float strong_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const; -}; - -/** - * \brief Modality that computes quantized surface normals from a dense depth map. - */ -class CV_EXPORTS DepthNormal : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - DepthNormal(); - - /** - * \brief Constructor. - * - * \param distance_threshold Ignore pixels beyond this distance. - * \param difference_threshold When computing normals, ignore contributions of pixels whose - * depth difference with the central pixel is above this threshold. - * \param num_features How many features a template must contain. - * \param extract_threshold Consider as candidate feature only if there are no differing - * orientations within a distance of extract_threshold. - */ - DepthNormal(int distance_threshold, int difference_threshold, size_t num_features, - int extract_threshold); - - virtual String name() const; - - virtual void read(const FileNode& fn); - virtual void write(FileStorage& fs) const; - - int distance_threshold; - int difference_threshold; - size_t num_features; - int extract_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const; -}; - -/** - * \brief Debug function to colormap a quantized image for viewing. - */ -void colormap(const Mat& quantized, Mat& dst); - -/** - * \brief Represents a successful template match. - */ -struct CV_EXPORTS Match -{ - Match() - { - } - - Match(int x, int y, float similarity, const String& class_id, int template_id); - - /// Sort matches with high similarity to the front - bool operator<(const Match& rhs) const - { - // Secondarily sort on template_id for the sake of duplicate removal - if (similarity != rhs.similarity) - return similarity > rhs.similarity; - else - return template_id < rhs.template_id; - } - - bool operator==(const Match& rhs) const - { - return x == rhs.x && y == rhs.y && similarity == rhs.similarity && class_id == rhs.class_id; - } - - int x; - int y; - float similarity; - String class_id; - int template_id; -}; - -inline -Match::Match(int _x, int _y, float _similarity, const String& _class_id, int _template_id) - : x(_x), y(_y), similarity(_similarity), class_id(_class_id), template_id(_template_id) -{} - -/** - * \brief Object detector using the LINE template matching algorithm with any set of - * modalities. - */ -class CV_EXPORTS Detector -{ -public: - /** - * \brief Empty constructor, initialize with read(). - */ - Detector(); - - /** - * \brief Constructor. - * - * \param modalities Modalities to use (color gradients, depth normals, ...). - * \param T_pyramid Value of the sampling step T at each pyramid level. The - * number of pyramid levels is T_pyramid.size(). - */ - Detector(const std::vector< Ptr >& modalities, const std::vector& T_pyramid); - - /** - * \brief Detect objects by template matching. - * - * Matches globally at the lowest pyramid level, then refines locally stepping up the pyramid. - * - * \param sources Source images, one for each modality. - * \param threshold Similarity threshold, a percentage between 0 and 100. - * \param[out] matches Template matches, sorted by similarity score. - * \param class_ids If non-empty, only search for the desired object classes. - * \param[out] quantized_images Optionally return vector of quantized images. - * \param masks The masks for consideration during matching. The masks should be CV_8UC1 - * where 255 represents a valid pixel. If non-empty, the vector must be - * the same size as sources. Each element must be - * empty or the same size as its corresponding source. - */ - void match(const std::vector& sources, float threshold, std::vector& matches, - const std::vector& class_ids = std::vector(), - OutputArrayOfArrays quantized_images = noArray(), - const std::vector& masks = std::vector()) const; - - /** - * \brief Add new object template. - * - * \param sources Source images, one for each modality. - * \param class_id Object class ID. - * \param object_mask Mask separating object from background. - * \param[out] bounding_box Optionally return bounding box of the extracted features. - * - * \return Template ID, or -1 if failed to extract a valid template. - */ - int addTemplate(const std::vector& sources, const String& class_id, - const Mat& object_mask, Rect* bounding_box = NULL); - - /** - * \brief Add a new object template computed by external means. - */ - int addSyntheticTemplate(const std::vector