資源簡介
一個基于 OpenCV 的人臉識別系統,源代碼清楚,對學習圖像識別的同學會很有用

代碼片段和文件信息
#include?“cv.h“
#include?“highgui.h“
#include?
char?filename[100];
char?subfilename[100];
void?GetSubFileName(?char?subfilename[100]int?ichar?filename[100]?);
IplImage*?GetSubImage(?IplImage*?src?CvRect?rect)
{
IplImage*?subImg=cvCreateImage(?cvSize(?rect.widthrect.height?)
IPL_DEPTH_8U
3);
CvScalar?s;
for(?int?row=1;row {
for(?int?col=1;col {
s=cvGet2D(?srcrow+rect.ycol+rect.x?);
cvSet2D(?subImgrowcols?);
}
}
return?subImg;
}
void?OutputLarger(?IplImage*?img?CvRect?face_rectchar?savepath[100]?)
{
CvPoint?mid;
mid.x=face_rect.x+face_rect.width/2;
mid.y=face_rect.y+face_rect.height/3;
CvRect?new_rect;
new_rect.x=face_rect.x-int(0.2*face_rect.width/2);//新矩形的x,y坐標往左上移動
if(?new_rect.x<1?)
new_rect.x=1;
new_rect.y=face_rect.y-int(0.4*face_rect.height*(double(2)/3));
if(?new_rect.y<1?)
new_rect.y=1;
new_rect.width=int(face_rect.width*1.2);
new_rect.height=int(?face_rect.height*1.4?);
CvScalar?s;
IplImage*?subImg=cvCreateImage(?cvSize(?new_rect.widthnew_rect.height?)
IPL_DEPTH_8U
3);
for(?int?row=1;row {
for(?int?col=1;col {
s=cvGet2D(?imgrow+new_rect.ycol+new_rect.x?);
cvSet2D(?subImgrowcols?);
}
}
cvSaveImage(?savepathsubImg?);
}
void?GetSubFileName(?char?subfilename[100]int?ichar?filename[100]?)
{
char?tmp[]={‘0‘+i‘\0‘};
memset(subfilename0100);
strcpy(subfilename“sub“);
strcat(subfilenametmp?);
strcat(subfilenamefilename);
}
CvHaarClassifierCascade*?load_object_detector(?const?char*?cascade_path?)
{
????return?(CvHaarClassifierCascade*)cvLoad(?cascade_path?);//現在分類器都存儲在xml文件中,所以用load,再類型轉換
}
void?detect_and_draw_objects(?IplImage*?image
??????????????????????????????CvHaarClassifierCascade*?cascade
??????????????????????????????int?do_pyramids?)
{
????IplImage*?small_image?=?image;
????CvMemStorage*?storage?=?cvCreateMemStorage(0);//默認大小的存儲塊是64kb
????CvSeq*?faces;//OpenCv基礎動態數據結構
????int?i?scale?=?1;
?
????if(?do_pyramids?)//如果聲明,則Gaussian金字塔向下采樣把圖像變小再做可以提高速度,但是精度不如用原始圖像好
????{
????????small_image?=?cvCreateImage(?cvSize(image->width/2image->height/2)?
IPL_DEPTH_8U?3?);
????????cvPyrDown(?image?small_image?CV_GAUSSIAN_5x5?);//向下采樣輸出是原始圖像的一半?,先使用指定濾波器對輸入圖像進行卷積
//然后通過去除偶數的行與列向下采樣圖像
????????scale?=?2;
????}
else
{
//small_image?=?cvCreateImage(?cvSize(image->widthimage->height??)IPL_DEPTH_8U3?);
small_image=image;
}
faces?=?cvHaarDetectobjects(?small_image?cascade?storage?1.2?2
0/*CV_HAAR_DO_CANNY_PRUNING*/?);
????for(?i?=?0;?i?total;?i++?)
????{
?
????????CvRect?face_rect?=?*(CvRect*)cvGetSeqElem(?faces?i?);//序列,索引構成
/*
繪制簡單、指定粗細或者帶填充的?矩形?
void?cvRectangle(?CvArr*?img?CvPoint?pt1?CvPoint?pt2?CvScalar?color
??int?thickness=1?int?line_type=8
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????843824??2006-10-18?21:49??faceidentifysys\cv100.dll
?????文件?????598067??2006-10-18?21:50??faceidentifysys\cvaux100.dll
?????文件??????49152??2006-10-19?17:16??faceidentifysys\cvcam100.dll
?????文件????1011764??2006-10-18?21:49??faceidentifysys\cxcore100.dll
?????文件?????131133??2006-10-18?21:50??faceidentifysys\cxts001.dll
?????文件???????5974??2008-03-10?12:44??faceidentifysys\haarcascade.cpp
?????文件???????4210??2008-03-06?12:23??faceidentifysys\haarcascade.dsp
?????文件????????547??2007-03-07?20:41??faceidentifysys\haarcascade.dsw
?????文件?????208957??2008-03-10?12:44??faceidentifysys\haarcascade.exe
?????文件??????50176??2008-03-11?10:02??faceidentifysys\haarcascade.ncb
?????文件??????53760??2008-03-11?10:02??faceidentifysys\haarcascade.opt
?????文件????????960??2008-03-10?12:44??faceidentifysys\haarcascade.plg
?????文件?????946032??2005-03-16?19:18??faceidentifysys\haarcascade_frontalface_alt.xm
?????文件?????626741??2006-10-18?21:50??faceidentifysys\highgui100.dll
?????文件??????66058??2008-03-10?12:51??faceidentifysys\hu.JPG
?????文件?????196608??2006-02-28?18:04??faceidentifysys\libguide40.dll
?????文件?????249904??2006-10-18?21:50??faceidentifysys\ml100.dll
?????文件??????53214??2008-03-10?12:47??faceidentifysys\news.jpg
?????文件??????23333??2008-03-11?10:01??faceidentifysys\result.jpg
?????文件???????5121??2008-03-11?10:01??faceidentifysys\sub0hu.jpg
?????文件???????5125??2008-03-11?10:01??faceidentifysys\sub0news.jpg
?????文件??????48750??2008-03-11?10:01??faceidentifysys\sub0zhang.jpg
?????文件???????4817??2008-03-11?10:01??faceidentifysys\sub1news.jpg
????..A.SH.??????8192??2008-03-31?10:26??faceidentifysys\Thumbs.db
?????文件??????43848??2008-03-05?16:18??faceidentifysys\zhang.jpg
?????文件?????220936??2008-03-05?16:18??faceidentifysys\zhang1.jpg
?????文件??????19968??2008-03-11?13:55??faceidentifysys\輸入格式.doc
?????目錄??????????0??1998-02-08?09:51??faceidentifysys
-----------?---------??----------?-----??----
??????????????5477171????????????????????28
............此處省略1個文件信息
評論
共有 條評論