dpm.hpp 6.65 KB
Newer Older
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
1 2 3 4 5 6 7 8 9 10 11 12
/*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
//
jiaolong_x220's avatar
jiaolong_x220 committed
13
// Copyright (C) 2015, Itseez Inc, all rights reserved.
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// 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.
jiaolong_x220's avatar
jiaolong_x220 committed
32
// In no event shall the Itseez Inc or contributors be liable for any direct,
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
33 34 35 36 37 38 39
// 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.
//
jiaolong_x220's avatar
jiaolong_x220 committed
40 41
// Implementation authors:
// Jiaolong Xu - jiaolongxu@gmail.com
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
// Evgeniy Kozinov - evgeniy.kozinov@gmail.com
// Valentina Kustikova - valentina.kustikova@gmail.com
// Nikolai Zolotykh - Nikolai.Zolotykh@gmail.com
// Iosif Meyerov - meerov@vmk.unn.ru
// Alexey Polovinkin - polovinkin.alexey@gmail.com
//
//M*/

#ifndef __OPENCV_LATENTSVM_HPP__
#define __OPENCV_LATENTSVM_HPP__

#include "opencv2/core.hpp"

#include <map>
#include <vector>
#include <string>

jiaolong_x220's avatar
jiaolong_x220 committed
59
/** @defgroup dpm Deformable Part-based Models
60 61 62 63 64

Discriminatively Trained Part Based Models for Object Detection
---------------------------------------------------------------

The object detector described below has been initially proposed by P.F. Felzenszwalb in
65
@cite Felzenszwalb2010a . It is based on a Dalal-Triggs detector that uses a single filter on histogram
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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.

The detector was dramatically speeded-up with cascade algorithm proposed by P.F. Felzenszwalb in
81
@cite Felzenszwalb2010b . The algorithm prunes partial hypotheses using thresholds on their scores.The
82 83 84 85 86 87 88
basic idea of the algorithm is to use a hierarchy of models defined by an ordering of the original
model's parts. For a model with (n+1) parts, including the root, a sequence of (n+1) models is
obtained. The i-th model in this sequence is defined by the first i parts from the original model.
Using this hierarchy, low scoring hypotheses can be pruned after looking at the best configuration
of a subset of the parts. Hypotheses that score high under a weak model are evaluated further using
a richer model.

jiaolong_x220's avatar
jiaolong_x220 committed
89
In OpenCV there is an C++ implementation of DPM cascade detector.
90 91 92

*/

Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
93 94 95
namespace cv
{

jiaolong_x220's avatar
jiaolong_x220 committed
96
namespace dpm
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
97 98
{

99 100 101
//! @addtogroup dpm
//! @{

jiaolong_x220's avatar
jiaolong_x220 committed
102
/** @brief This is a C++ abstract class, it provides external user API to work with DPM.
103
 */
jiaolong_x220's avatar
jiaolong_x220 committed
104
class CV_EXPORTS_W DPMDetector
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
105 106 107 108 109 110 111 112 113 114 115 116 117
{
public:

    struct CV_EXPORTS_W ObjectDetection
    {
        ObjectDetection();
        ObjectDetection( const Rect& rect, float score, int classID=-1 );
        Rect rect;
        float score;
        int classID;
    };

    virtual bool isEmpty() const = 0;
118 119 120 121 122

    /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes
    (models) and corresponding confidence levels.
    @param image An image.
    @param objects The detections: rectangulars, scores and class IDs.
jiaolong_x220's avatar
jiaolong_x220 committed
123 124
    */
    virtual void detect(cv::Mat &image, CV_OUT std::vector<ObjectDetection> &objects) = 0;
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
125

126 127 128
    /** @brief Return the class (model) names that were passed in constructor or method load or extracted from
    models filenames in those methods.
     */
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
129
    virtual std::vector<std::string> const& getClassNames() const = 0;
130 131 132

    /** @brief Return a count of loaded models (classes).
     */
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
133 134
    virtual size_t getClassCount() const = 0;

jiaolong_x220's avatar
jiaolong_x220 committed
135
    /** @brief Load the trained models from given .xml files and return cv::Ptr\<DPMDetector\>.
136
    @param filenames A set of filenames storing the trained detectors (models). Each file contains one
jiaolong_x220's avatar
jiaolong_x220 committed
137
    model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`.
138 139 140 141
    @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".
     */
jiaolong_x220's avatar
jiaolong_x220 committed
142 143
    static cv::Ptr<DPMDetector> create(std::vector<std::string> const &filenames,
            std::vector<std::string> const &classNames = std::vector<std::string>());
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
144

jiaolong_x220's avatar
jiaolong_x220 committed
145
    virtual ~DPMDetector(){}
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
146 147
};

148 149
//! @}

jiaolong_x220's avatar
jiaolong_x220 committed
150
} // namespace dpm
Dinar Ahmatnurov's avatar
Dinar Ahmatnurov committed
151 152 153
} // namespace cv

#endif