CascadeClassifier-对象检测

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>

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

代码贴上来


人脸识别
测试代码
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 拘束着思 便是给自家的门上安上了锁 隔着眼睛 隔着窗户 我们相互眺望 渴望打开心房 可那锁啊 只能从门外打开 我预...
    森林初青阅读 1,852评论 3 3
  • 自习归寝 少无忧,夜穷游。无月清风临渠沟,蜡尽眼倦不觉晚,执手倚肩数星宿。 烦弃笔,解心舟。似水落花逐波流,昔年素...
    南柯梦阅读 2,490评论 0 0
  • 那天我买回了咪蒙的《初次爱你,请多关照》,四十个关于爱情的故事,我花了八个小时零二十分钟看完,期间,泪湿了...
    沙公主阅读 4,434评论 1 0