class cv::cuda::CascadeClassifier

Overview

Cascade classifier class used for object detection. Supports HAAR and LBP cascades. : More…

#include <cudaobjdetect.hpp>

class CascadeClassifier: public cv::Algorithm
{
public:
    // methods

    static
    Ptr<CascadeClassifier>
    create(const String& filename);

    static
    Ptr<CascadeClassifier>
    create(const FileStorage& file);

    virtual
    void
    convert(
        OutputArray gpu_objects,
        std::vector<Rect>& objects
        ) = 0;

    virtual
    void
    detectMultiScale(
        InputArray image,
        OutputArray objects,
        Stream& stream = Stream::Null()
        ) = 0;

    virtual
    Size
    getClassifierSize() const = 0;

    virtual
    bool
    getFindLargestObject() = 0;

    virtual
    int
    getMaxNumObjects() const = 0;

    virtual
    Size
    getMaxObjectSize() const = 0;

    virtual
    int
    getMinNeighbors() const = 0;

    virtual
    Size
    getMinObjectSize() const = 0;

    virtual
    double
    getScaleFactor() const = 0;

    virtual
    void
    setFindLargestObject(bool findLargestObject) = 0;

    virtual
    void
    setMaxNumObjects(int maxNumObjects) = 0;

    virtual
    void
    setMaxObjectSize(Size maxObjectSize) = 0;

    virtual
    void
    setMinNeighbors(int minNeighbors) = 0;

    virtual
    void
    setMinObjectSize(Size minSize) = 0;

    virtual
    void
    setScaleFactor(double scaleFactor) = 0;
};

Inherited Members

public:
    // methods

    virtual
    void
    clear();

    virtual
    bool
    empty() const;

    virtual
    String
    getDefaultName() const;

    virtual
    void
    read(const FileNode& fn);

    virtual
    void
    save(const String& filename) const;

    virtual
    void
    write(FileStorage& fs) const;

    template <typename _Tp>
    static
    Ptr<_Tp>
    load(
        const String& filename,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    loadFromString(
        const String& strModel,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    read(const FileNode& fn);

protected:
    // methods

    void
    writeFormat(FileStorage& fs) const;

Detailed Documentation

Cascade classifier class used for object detection. Supports HAAR and LBP cascades. :

  • A cascade classifier example can be found at opencv_source_code/samples/gpu/cascadeclassifier.cpp
    • A Nvidea API specific cascade classifier example can be found at opencv_source_code/samples/gpu/cascadeclassifier_nvidia_api.cpp

Methods

static
Ptr<CascadeClassifier>
create(const String& filename)

Loads the classifier from a file. Cascade type is detected automatically by constructor parameter.

Parameters:

filename Name of the file from which the classifier is loaded. Only the old haar classifier (trained by the haar training application) and NVIDIA’s nvbin are supported for HAAR and only new type of OpenCV XML cascade supported for LBP. The working haar models can be found at opencv_folder/data/haarcascades_cuda/
static
Ptr<CascadeClassifier>
create(const FileStorage& file)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual
void
convert(
    OutputArray gpu_objects,
    std::vector<Rect>& objects
    ) = 0

Converts objects array from internal representation to standard vector.

Parameters:

gpu_objects Objects array in internal representation.
objects Resulting array.
virtual
void
detectMultiScale(
    InputArray image,
    OutputArray objects,
    Stream& stream = Stream::Null()
    ) = 0

Detects objects of different sizes in the input image.

To get final array of detected objects use CascadeClassifier::convert method.

Ptr<cuda::CascadeClassifier> cascade_gpu = cuda::CascadeClassifier::create(...);

Mat image_cpu = imread(...)
GpuMat image_gpu(image_cpu);

GpuMat objbuf;
cascade_gpu->detectMultiScale(image_gpu, objbuf);

std::vector<Rect> faces;
cascade_gpu->convert(objbuf, faces);

for(int i = 0; i < detections_num; ++i)
   cv::rectangle(image_cpu, faces[i], Scalar(255));

imshow("Faces", image_cpu);

Parameters:

image Matrix of type CV_8U containing an image where objects should be detected.
objects Buffer to store detected objects (rectangles).
stream CUDA stream.

See also:

CascadeClassifier::detectMultiScale

virtual
void
setMaxObjectSize(Size maxObjectSize) = 0

Maximum possible object size. Objects larger than that are ignored. Used for second signature and supported only for LBP cascades.

virtual
void
setMinNeighbors(int minNeighbors) = 0

Parameter specifying how many neighbors each candidate rectangle should have to retain it.

virtual
void
setMinObjectSize(Size minSize) = 0

Minimum possible object size. Objects smaller than that are ignored.

virtual
void
setScaleFactor(double scaleFactor) = 0

Parameter specifying how much the image size is reduced at each image scale.