OpenCV Tutorial 11 - Chapter 13
来源:互联网 发布:电脑按java干什么 编辑:程序博客网 时间:2024/05/08 08:08
( 由于收到附件大小的限制,此篇的图片无法上传,请大家见谅,可登陆原网站查看:http://dasl.mem.drexel.edu/~noahKuntz/openCVTut11.html)
Author: Noah Kuntz (2009)
Contact: nk752@drexel.edu
Keywords: OpenCV, computer vision, machine learning, haar classifier, face detection
My Vision Tutorials Index
This tutorial assumes the reader:
(1) Has a basic knowledge of Visual C++
(2) Has some familiarity with computer vision concepts
(3) Has read the previous tutorials in this series
The rest of the tutorial is presented as follows:
- Step 1: Face Detection with the Haar Classifier
- Final Words
Important Note!
More information on the topics of these tutorials can be found in this book:Learning OpenCV: Computer Vision with the OpenCV Library
Step 1: Face Detection with the Haar Classifier(人脸检测和Haar分类器)
Face Detection(人脸检测)
Machine learning is a powerful set of algorithms that can be used to improve computer vision algorithms by allowing the program to build on the knowledge of many example cases(机器学习是一套功能强大的可以用来提高计算机视觉算法的算法,该算法允许该程序在许多例子案件知识的基础上建立). For face detection, this example uses a Haar classifier, which is a statistically boosted classifier supported by training on many sample images of faces(对于人脸检测,这个例子使用了haar分类器,这是一个统计上提高了的分类器,它支持许多人脸图像样本). Much more detail of machine learning theory can be found in the book(更详细的机器学习理论可以在这本书中找到). This code uses a CvHaarClassifierCascade* matrix that should be copied from your OpenCV directory to your working directory (see the code comments), and loaded withcvLoad(此代码使用一个CvHaarClassifierCascade *矩阵,应该从你的OpenCV的目录复制到你的工作目录(见代码注释),并用cvLoad加载). ThencvHaarDetectObjects takes the input image, the loaded cascade, the empty memory storage and a few options and performs the face detection(然后cvHaarDetectObjects接受输入图像,加载的级联,空的记忆存储和一些选项并执行人脸检测). The important option here is the minimum size defined incvSize(这里最重要的选项是用cvSize定义的最小规模).Base this on the size of the faces in your image, in pixels(在你的图像中,立足于脸的大小,以像素为单位). Then once the detected faces are stored in a sequence, a loop can be used to go through them and draw aCvRect object around each one(那么一旦被检测的脸被存储在一个序列中,一个循环可用于通过他们和绘制一个CvRect对象包括周围的每人一个). Here is the code(以下是代码):
int _tmain(int argc, _TCHAR* argv[])
{
IplImage* img;
img = cvLoadImage( "dasl_hubo.jpg" );
CvMemStorage* storage = cvCreateMemStorage(0);
// Note that you must copy C:\Program Files\OpenCV\data\haarcascades\haarcascade_frontalface_alt2.xml
// to your working directory
CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad( "haarcascade_frontalface_alt2.xml" );
double scale = 1.3;
static CvScalar colors[] = { {{0,0,255}}, {{0,128,255}}, {{0,255,255}},
{{0,255,0}}, {{255,128,0}}, {{255,255,0}}, {{255,0,0}}, {{255,0,255}} };
// Detect objects
cvClearMemStorage( storage );
CvSeq* objects = cvHaarDetectObjects( img, cascade, storage, 1.1, 4, 0, cvSize( 40, 50 ));
CvRect* r;
// Loop through objects and draw boxes
for( int i = 0; i < (objects ? objects->total : 0 ); i++ ){
r = ( CvRect* )cvGetSeqElem( objects, i );
cvRectangle( img, cvPoint( r->x, r->y ), cvPoint( r->x + r->width, r->y + r->height ),
colors[i%8]);
}
cvNamedWindow( "Output" );
cvShowImage( "Output", img );
cvWaitKey();
cvReleaseImage( &img );
return 0;
}
Final Words(结束语)
This tutorial's objective was to show how to use a basic machine learning classifier to detect faces(本教程的目标是展示如何使用基本的机器学习分类器来检测人脸).
Click here to email me.
Click here to return to my Tutorials page.
- OpenCV Tutorial 11 - Chapter 13
- OpenCV Tutorial 10 - Chapter 11
- OpenCV Tutorial 2 - Chapter 3
- OpenCV Tutorial 3 - Chapter 4
- OpenCV Tutorial 4 - Chapter 5
- OpenCV Tutorial 5 - Chapter 6
- OpenCV Tutorial 6 - Chapter 7
- OpenCV Tutorial 7- Chapter 8
- OpenCV Tutorial 8 - Chapter 9
- OpenCV Tutorial 9 - Chapter 10
- OpenCV Tutorial: OpenCV介紹
- Microsoft Agent Tutorial Chapter 1
- Microsoft Agent Tutorial Chapter 2
- Microsoft Agent Tutorial Chapter 2
- Chapter 1 - A Tutorial Introduction
- OpenCV Tutorial roadmap
- OpenCV Tutorial (學習筆記)
- OpenCV Tutorial CVPR 2015
- Atutor、 Claroline、 Moddle及Sakai号称为四大开源课程管理系统
- OpenCV Tutorial 10 - Chapter 11
- 锁定老帖子 主题: JAVA完全控制Oracle中BLOB CLOB说明
- Jquery最佳实践
- 编程巨星的唯一秘诀
- OpenCV Tutorial 11 - Chapter 13
- 精妙的SQL语句
- 学习Android界面设计的超级利器HierarchyView.bat
- 解决双显卡笔记本安装XP系统后独立显卡无法驱动的问题!Win7双显卡笔记本换XP系统如何安装独立显卡驱动!
- getline源代码简析
- 用java实现搜索引擎
- IT软件开发人员必去的10个社区
- 浅谈Silverlight页面显示Html问题
- 博计报表