您的位置:首页 > 运维架构

【opencv 官方教程】翻译6 Background Subtraction 和级联分类器

2016-12-26 15:29 441 查看

本底扣除Background Subtraction

How to Use Background Subtraction Methods
Compatibility: > OpenCV 2.4.6
Author: Domenico Daniele Bloisi
We will learn how to extract foreground masks from both videos and sequences of images and to show them.

基本原理:


发现背景图片和特定图片之间的差异,从中获取相对的前景目标

步骤:

准备三个Mat,分别存储currentframe、两个foreground masks(具体原因请访问官方网站查看完整说明,我觉得他们是错版了)

准备俩cv::BackgroundSubtractor objects用以生成foreground masks.

分析用户选择的是图像还是视频,接下来以视频为例

等到视频放到最后或者按q、esc

每帧都被用来计算上一时刻的foreground mask和作为下一时刻的background。

给当前帧打上标记(编号和高亮白框)

显示当前帧和mask的结果

对于图像的处理和视频类似

效果:



级联分类器

Cascade Classifier
Compatibility: > OpenCV 2.0
Author: Ana Huamán
Here we learn how to use objdetect to find objects in our images or videos

Cascade Classifier Training
This tutorial describes opencv_traincascade application and its parameters.

对于级联分类器的简介

In this tutorial you will learn how to:

Use the
cv::CascadeClassifier class to detect objects in a video stream. Particularly, we will use the functions: 检测视频流中的物体
cv::CascadeClassifier::load to load a .xml classifier file. It can be either a Haar or a LBP classifer   装载一个xml分类文件
cv::CascadeClassifier::detectMultiScale to perform the detection.                     展示分类

//-- 1. Load the cascades
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error
loading face cascade\n"); return -1; };
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error
loading eyes cascade\n"); return -1; };
//-- 2. Read the video stream
capture.open( -1 );
if ( ! capture.isOpened() ) { printf("--(!)Error
opening video capture\n"); return -1; }
//-- 3. Apply the classifier to the frame
detectAndDisplay( frame );
//-- Detect faces
//-- In each face, detect eyes

级联分类器训练

简介

 boosted cascade of weak classifiers包含两部分:训练阶段和侦测阶段(侦测采用HAAR或者LBP模式)。接下来是关于boosted cascade的训练的说明。

目前的指导内容包含收集训练数据、准备训练数据、执行模式训练。

准备训练数据:

必须手动(如果你有一个足够智能的AI那也不一定了)准备正面和反面的样例 (通过opencv_createsamples application)

反面样例要求是无关或者你不想要被检测出的

正面样例要求给出所关注目标的样子,略

级联训练:

用准备的数据指定方式进行训练,结果会被存到cascade.xml里面

可视化级联分类:

把训练过程可视化是很有用的,opencv_visualisation这个应用提供了这样的功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenCV