資源簡介
基于Gabor+PCA+SVM的性別識別.圖像預(yù)處理。從人臉數(shù)據(jù)庫提取人臉。為提取特征做準(zhǔn)備
代碼片段和文件信息
#include?“opencv2/opencv.hpp“
#include?“opencv2/imgproc/imgproc.hpp“
#include?
#include?
using?namespace?std;
using?namespace?cv;
int?CropImageCount?=?0;?//裁剪出來的樣本圖片個(gè)數(shù)
string?face_cascade_name?=“D:\\Program?Files\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml“;
CascadeClassifier?face_cascade;
string?window_name?=?“人臉識別“;
Mat?detectAndDisplay(?Mat);
int?main()
{
????Mat?imageROI;
????//image?=?imread(“pangzi.jpg“);
if(?!face_cascade.load(?face_cascade_name?)?)
??{?
????????printf(“[error]?無法加載級聯(lián)分類器文件!\n“);
????????return?-1;?
??????}
string?ImgName;
char?saveName[256];??//裁剪出來的負(fù)樣本圖片文件名
ifstream?fin(“woman.txt“);//打開原始樣本圖片文件列表
//ifstream?fin(“woman.txt“);//打開原始樣本圖片文件列表
//一行一行讀取文件列表
while(getline(finImgName))
{??
cout<<“處理:“< //ImgName?=?“D:\\Mycode\\man\\“?+?ImgName+“.png“;
ImgName?=?“D:\\Mycode\\woman\\“?+?ImgName+“.png“;
//cout< image=?imread(ImgName);//讀取圖片
????????if(image.data?==0)
???{
??????????printf(“[error]?沒有圖片\n“);
??????????return?-5;
???????}
??????ROI=?detectAndDisplay(image);
??//?cout< //sprintf(saveName“man%d.png“++CropImageCount);//生成裁剪出的樣本圖片的文件名
sprintf(saveName“woman%d.png“++CropImageCount);//生成裁剪出的樣本圖片的文件名
imwrite(saveName?ROI);//保存文件
?}
????waitKey(0);?
return?4;
}
Mat?detectAndDisplay(?Mat?frame)
{
????std::vector?faces;
????Mat?frame_grayROI;
frame_gray=?frame;
????cvtColor(?frame?frame_gray?CV_BGR2GRAY?);
????equalizeHist(?frame_gray?frame_gray?);
????face_cascade.detectMultiScale(?frame_gray?faces?1.1?2?0|CV_HAAR_SCALE_IMAGE?Size(30?30)?);
????for(?int?i?=?0;?i? {
????????Point?center(?faces[i].x?+?faces[i].width*0.5?faces[i].y?+?faces[i].height*0.5?);
???????//?ellipse(?frame?center?Size(?faces[i].width*0.5?faces[i].height*0.5)?0?0?360?Scalar(?255?0?255?)?4?8?0?);
?????rectangle(frame????????????????//圖像.
?????faces[i].tl()?????????????//矩形的一個(gè)頂點(diǎn)。
?faces[i].br()?????????????//矩形對角線上的另一個(gè)頂點(diǎn)
?Scalar(0?255?0)??//線條顏色?(RGB)?或亮度(灰度圖像?)(grayscale?image)
??3);?????????????????//組成矩形的線條的粗細(xì)程度。取負(fù)值時(shí)(如?CV_FILLED)函數(shù)繪制填充了色彩的矩形
?????ROI=frame_gray(Rect(faces[i].tl().xfaces[i].tl().yfaces[i].widthfaces[i].height));
?resize(ROIROISize(2118)00CV_INTER_LINEAR);
}
//namedWindow(“qq“2);
//imshow(?“qq“?ROI?);
???
?//?imshow(?window_name?frame?);
return?ROI;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????107520??2015-12-26?17:08??face_cut\Debug\face_cut.exe
?????文件????1179576??2015-12-26?17:08??face_cut\Debug\face_cut.ilk
?????文件????1911808??2015-12-26?17:08??face_cut\Debug\face_cut.pdb
?????文件?????175113??2015-12-13?19:37??face_cut\face_cut\Debug\BrowseDir.obj
?????文件???????5222??2015-12-26?17:08??face_cut\face_cut\Debug\cl.command.1.tlog
?????文件??????99568??2015-12-26?17:08??face_cut\face_cut\Debug\CL.read.1.tlog
?????文件???????3404??2015-12-26?17:08??face_cut\face_cut\Debug\CL.write.1.tlog
?????文件?????445019??2015-12-13?19:37??face_cut\face_cut\Debug\detect.obj
?????文件?????229362??2015-12-13?19:37??face_cut\face_cut\Debug\detection.obj
?????文件????????406??2015-12-14?10:21??face_cut\face_cut\Debug\face_cut.exe.em
?????文件????????472??2015-12-14?10:21??face_cut\face_cut\Debug\face_cut.exe.em
?????文件????????381??2015-12-26?17:08??face_cut\face_cut\Debug\face_cut.exe.intermediate.manifest
?????文件?????????57??2015-12-26?17:08??face_cut\face_cut\Debug\face_cut.lastbuildstate
?????文件???????3354??2015-12-26?17:08??face_cut\face_cut\Debug\face_cut.log
?????文件????????713??2015-12-13?19:37??face_cut\face_cut\Debug\face_cut.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2015-12-13?19:37??face_cut\face_cut\Debug\face_cut.write.1.tlog
?????文件????????206??2015-12-13?19:46??face_cut\face_cut\Debug\face_cut_manifest.rc
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
?????文件??????????2??2015-12-26?17:08??face_cut\face_cut\Debug\li
............此處省略103個(gè)文件信息
- 上一篇:ssh注冊登錄
- 下一篇:基于Gabor+PCA+SVM的性別識別(3)
評論
共有 條評論