* (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python2/facedetect.py
-CascadeClassifier::setImage
--------------------------------
-Sets an image for detection.
-
-.. ocv:function:: bool CascadeClassifier::setImage( Ptr<FeatureEvaluator>& feval, const Mat& image )
-
-.. ocv:cfunction:: void cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, const CvArr* sum, const CvArr* sqsum, const CvArr* tilted_sum, double scale )
-
- :param cascade: Haar classifier cascade (OpenCV 1.x API only). See :ocv:func:`CascadeClassifier::detectMultiScale` for more information.
-
- :param feval: Pointer to the feature evaluator used for computing features.
-
- :param image: Matrix of the type ``CV_8UC1`` containing an image where the features are computed.
-
-The function is automatically called by :ocv:func:`CascadeClassifier::detectMultiScale` at every image scale. But if you want to test various locations manually using :ocv:func:`CascadeClassifier::runAt`, you need to call the function before, so that the integral images are computed.
-
-.. note:: in the old API you need to supply integral images (that can be obtained using :ocv:cfunc:`Integral`) instead of the original image.
-
-
-CascadeClassifier::runAt
-----------------------------
-Runs the detector at the specified point.
-
-.. ocv:function:: int CascadeClassifier::runAt( Ptr<FeatureEvaluator>& feval, Point pt, double& weight )
-
-.. ocv:cfunction:: int cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, CvPoint pt, int start_stage=0 )
-
- :param cascade: Haar classifier cascade (OpenCV 1.x API only). See :ocv:func:`CascadeClassifier::detectMultiScale` for more information.
-
- :param feval: Feature evaluator used for computing features.
-
- :param pt: Upper left point of the window where the features are computed. Size of the window is equal to the size of training images.
-
-The function returns 1 if the cascade classifier detects an object in the given location.
-Otherwise, it returns negated index of the stage at which the candidate has been rejected.
-
-Use :ocv:func:`CascadeClassifier::setImage` to set the image for the detector to work with.
-
groupRectangles
-------------------
Groups the object candidate rectangles.
virtual Ptr<MaskGenerator> getMaskGenerator() = 0;
};
-class CV_EXPORTS_W CascadeClassifier : public BaseCascadeClassifier
+class CV_EXPORTS_W CascadeClassifier
{
public:
CV_WRAP CascadeClassifier();
CV_WRAP explicit CascadeClassifier(const String& filename);
- virtual ~CascadeClassifier();
- CV_WRAP virtual bool empty() const;
- CV_WRAP virtual bool load( const String& filename );
- CV_WRAP virtual void detectMultiScale( InputArray image,
- CV_OUT std::vector<Rect>& objects,
- double scaleFactor = 1.1,
- int minNeighbors = 3, int flags = 0,
- Size minSize = Size(),
- Size maxSize = Size() );
-
- CV_WRAP virtual void detectMultiScale( InputArray image,
- CV_OUT std::vector<Rect>& objects,
- CV_OUT std::vector<int>& numDetections,
- double scaleFactor=1.1,
- int minNeighbors=3, int flags=0,
- Size minSize=Size(),
- Size maxSize=Size() );
-
- CV_WRAP virtual void detectMultiScale( InputArray image,
+ ~CascadeClassifier();
+ CV_WRAP bool empty() const;
+ CV_WRAP bool load( const String& filename );
+ CV_WRAP bool read( const FileNode& node );
+ CV_WRAP void detectMultiScale( InputArray image,
+ CV_OUT std::vector<Rect>& objects,
+ double scaleFactor = 1.1,
+ int minNeighbors = 3, int flags = 0,
+ Size minSize = Size(),
+ Size maxSize = Size() );
+
+ CV_WRAP void detectMultiScale( InputArray image,
+ CV_OUT std::vector<Rect>& objects,
+ CV_OUT std::vector<int>& numDetections,
+ double scaleFactor=1.1,
+ int minNeighbors=3, int flags=0,
+ Size minSize=Size(),
+ Size maxSize=Size() );
+
+ CV_WRAP void detectMultiScale( InputArray image,
CV_OUT std::vector<Rect>& objects,
CV_OUT std::vector<int>& rejectLevels,
CV_OUT std::vector<double>& levelWeights,
Size maxSize = Size(),
bool outputRejectLevels = false );
- CV_WRAP virtual bool isOldFormatCascade() const;
- CV_WRAP virtual Size getOriginalWindowSize() const;
- CV_WRAP virtual int getFeatureType() const;
- virtual void* getOldCascade();
+ CV_WRAP bool isOldFormatCascade() const;
+ CV_WRAP Size getOriginalWindowSize() const;
+ CV_WRAP int getFeatureType() const;
+ void* getOldCascade();
- virtual void setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator);
- virtual Ptr<MaskGenerator> getMaskGenerator();
+ void setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator);
+ Ptr<BaseCascadeClassifier::MaskGenerator> getMaskGenerator();
protected:
Ptr<BaseCascadeClassifier> cc;
};
-CV_EXPORTS Ptr<CascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator();
+CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator();
//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
return maskGenerator;
}
-Ptr<CascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator()
+Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator()
{
#ifdef HAVE_TEGRA_OPTIMIZATION
return tegra::getCascadeClassifierMaskGenerator(*this);
#else
- return Ptr<CascadeClassifierImpl::MaskGenerator>();
+ return Ptr<BaseCascadeClassifier::MaskGenerator>();
#endif
}
return !empty();
}
+bool CascadeClassifier::read(const FileNode &root)
+{
+ Ptr<CascadeClassifierImpl> ccimpl;
+ bool ok = ccimpl->read_(root);
+ if( ok )
+ cc = ccimpl.staticCast<BaseCascadeClassifier>();
+ else
+ cc.release();
+ return ok;
+}
+
void CascadeClassifier::detectMultiScale( InputArray image,
CV_OUT std::vector<Rect>& objects,
double scaleFactor,
return cc->getOldCascade();
}
-void CascadeClassifier::setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator)
+void CascadeClassifier::setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator)
{
CV_Assert(!empty());
cc->setMaskGenerator(maskGenerator);