物联网

CascadeClassifier-对象检测

2017-04-04  本文已影响2136人  我的名字好长好长灬

CascadeClassifier 前言

Cascade classifier class for object detection.

这里说的也很明白,对象检测。

一 CascadeClassifier 初始化

1.使用 § load() 方法初始化 

 Loads a classifier from a file.

文档说的很明白,使用一个文件名来初始化。

Parameters:filename Name of the file from which the classifier is loaded. The file may contain an old HAAR classifier trained by the haartraining application or a new cascade classifier trained by the traincascade application.

2.使用 § read() 方法初始化

Reads a classifier from a FileStorage node.

说是加载一个类型为 FileStorage 的东东?

The file may contain a new cascade classifier (trained traincascade application) only.

FileStorage 这个不就是一个文件管理类么。😅。说到最后还不是加载一个 HAAR 的。那就先从这个文件去入手。

<stageType> 级别,目前只支持将BOOST分类器作为参数 - 级联参数

<featureType> 特征类型 HAAR -类Haar特征、LBP -局部纹理模式特征

<height> 高度  要求创建训练样本尺寸与opencv-createsaples 尺寸一致

<width> 宽度   w - h 这两个是训练样本尺寸(单位为像素)

<stageParams> 级别 参数

<featureParams> 特征 参数

<stages> 模版

           <maxWeakCount>每一级弱分类器最大数目。每一级临界值。

            <stageThreshold>弱分类器临界值

<features> 特征

那么 初始化究竟做了些什么?

1.初始化分类器的特征类型、最小检测窗口size等参数。

2.建立级联分类树;

3.提取xml中的特征值。

读到数据了,那就开始吧。

二 CascadeClassifier 初始化

§ detectMultiScale() 有三个重载函数

void cv::CascadeClassifier::detectMultiScale ( InputArray image,std::vector< Rect > & objects,double scaleFactor = 1.1,int minNeighbors = 3,int flags = 0,Size minSize = Size(),Size maxSize = Size())

void cv::CascadeClassifier::detectMultiScale ( InputArray image,std::vector< Rect > & objects,std::vector< int > & numDetections,double scaleFactor = 1.1,int minNeighbors = 3,int flags = 0,Size minSize = Size(),Size maxSize = Size())

void cv::CascadeClassifier::detectMultiScale ( InputArray image,std::vector< Rect > & objects,std::vector< int > & rejectLevels,std::vector< double > & levelWeights,double scaleFactor = 1.1,int minNeighbors = 3,int flags = 0,Size minSize = Size(),Size maxSize = Size(),bool outputRejectLevels = false)

但是机器上打出来是这样的:

重载函数

又一点点不一样,就按照机器打出来的说吧。

Parameters

image: Matrix of the type CV_8U containing an image where objects are detected.

objects: Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.

numDetections: Vector of detection numbers for the corresponding objects. An object's number of detections is the number of neighboring positively classified rectangles that were joined together to form the object.

对于这个rejectleves、levelweights 文档给出的解释是:

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. if outputRejectLevels is true returns rejectLevels and levelWeights 

参数解释

1.image参数:InputArray .

This is the proxy class for passing read-only input arrays into OpenCV functions.

It is defined as:typedef const _InputArray& InputArray;

where _InputArray is a class that can be constructed from Mat, Mat_<T>, Matx<T,m,n>, std::vector<T>, std::vector<std::vector<T>> or std::vector<Mat>. It can also be constructed from a matrix expression.

InputArray + Mat + CV_8U ?就是需要一个单通道图片阵列么。

2.objects参数:std::vector <cv::Rect> objects.

用来存放检测到的信息。

传进来的是矩阵,传出来的就是一个符合条件的矩阵。

3.numDetections参数:std::vector<int>.

下图阐述了我的的想法,经过测试,参数传1.1或者1.2还是比较靠谱的.

传1.1:400张测试图片识别率为85.3%。

传1.2:400张测试图片识别率为78.7%。

传1.05: 400张测试图片识别率为94.0%。这是为什么,我还没有搞明白😅。

numDetections

4.rejectleves、levelweights参数:std::vector<int>,std::vector<double>

这个传出的是分类器信息?最后一个函数不知道什么鬼。说要两个参数,但是就是崩溃。

代码贴上来

人脸识别 测试代码
上一篇下一篇

猜你喜欢

热点阅读