/// <summary> /// 保存样本图 从本地图片 /// </summary> /// <param name="name"></param> private int SaveImg(string name, string fileName, bool fromOther) { Com.KingFaceDetect detect = new Com.KingFaceDetect(); Mat mat = new Mat(fileName, LoadImageType.Color); Com.KingFaceDetect.faceDetectedObj currentfdo = detect.GetFaceRectangle(mat); if (currentfdo.facesRectangle == null || currentfdo.facesRectangle.Count == 0) { return(1); } Image <Gray, byte> result = currentfdo.originalImg.ToImage <Gray, byte>().Copy(currentfdo.facesRectangle[0]).Resize(100, 100, Emgu.CV.CvEnum.Inter.Cubic); result._EqualizeHist();//灰度直方图均衡化 string filePath = System.Web.HttpContext.Current.Server.MapPath("~/") + "\\trainedFaces\\" + name + "_" + System.Guid.NewGuid().ToString() + ".jpg"; result.Bitmap.Save(filePath); return(2); }
/// <summary> /// 脸和姓名都查找 /// </summary> /// <param name="image"></param> /// <returns></returns> static Com.KingFaceDetect.faceDetectedObj Run1(Mat image) { if (HttpContext.Current.Application["detect"] == null) { HttpContext.Current.Application["detect"] = new Com.KingFaceDetect(); //存入全局 否则好像会报内存错误 } Com.KingFaceDetect detect = (Com.KingFaceDetect)HttpContext.Current.Application["detect"]; Com.KingFaceDetect.faceDetectedObj resut = detect.faceRecognize(image); return(resut); }