Created
January 16, 2014 02:48
-
-
Save KentaKomai/8449010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IplImage FaceDe(IplImage srcImg) | |
{ | |
const double Scale = 1.04; | |
const double ScaleFactor = 1.139; | |
const int MinNeighbors = 2; | |
using (IplImage smallImg = new IplImage(new CvSize(Cv.Round(srcImg.Width / Scale), Cv.Round(srcImg.Height / Scale)), BitDepth.U8, 1)) | |
{ | |
// 顔検出用の画像の生成 | |
using (IplImage gray = new IplImage(srcImg.Size, BitDepth.U8, 1)) | |
{ | |
Cv.CvtColor(srcImg, gray, ColorConversion.BgrToGray); | |
Cv.Resize(gray, smallImg, Interpolation.Linear); | |
Cv.EqualizeHist(smallImg, smallImg); | |
} | |
//using (CvHaarClassifierCascade cascade = Cv.Load<CvHaarClassifierCascade>(Const.XmlHaarcascade)) // どっちでも可 | |
using (CvHaarClassifierCascade cascade = CvHaarClassifierCascade.FromFile("C:\\haarcascade_frontalface_alt.xml")) // | |
using (CvMemStorage storage = new CvMemStorage()) | |
{ | |
storage.Clear(); | |
// 顔の検出 | |
CvSeq<CvAvgComp> faces = Cv.HaarDetectObjects(smallImg, cascade, storage, ScaleFactor, MinNeighbors, 0, new CvSize(30, 30)); | |
// モザイク処理 | |
for (int d = 0; d < faces.Total; d++) | |
{ | |
CvRect r = faces[d].Value.Rect; | |
Cv.Rectangle(srcImg, r, new CvScalar( 0x00FFFF ) ); | |
} | |
return srcImg; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment