private void CornrowsHair(XmlDocument document, XmlElement paper, int width, int height) { var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M 36,229" + "v -10" + "m 40,-10" + "v -60" + "m 50,37" + "v -75" + "m 50,65" + "v -76" + "m 50,76" + "v -76" + "m 50,93" + "v -75" + "m 50,92" + "v -60" + "m 40,80" + "v -10"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-linecap", "round"); e.SetAttribute("stroke-width", "22"); FaceHelper.ScaleCentered(e, FaceHelper.FatScale(Fatness), 1, width, height); }
/// <summary> /// 获取随机消息 /// </summary> /// <param name="SendParam"></param> /// <returns></returns> private string GetRandomMessage(SendParamModel SendParam) { string tempMessage = ""; //固定消息,只会传一条消息模板过来 if (SendParam.TemplateRule == 0) { tempMessage = SendParam.Message[0]; } //随机消息,随机获取 else if (SendParam.TemplateRule == 1) { int messageIndex = PublicUtils.GetRandom(0, SendParam.Message.Count); tempMessage = SendParam.Message[messageIndex]; } //替换时间变量 tempMessage = tempMessage.Replace("[时间]", "[Time]"); //替换昵称变量 tempMessage = tempMessage.Replace("[昵称]", "[ObjName]"); //替换时段 tempMessage = tempMessage.Replace("[时段]", "[TimePer]"); //替换分段 //自己进行分段 //tempMessage = tempMessage.Replace("[分段]", "[Next]"); //替换随机表情 //tempMessage = tempMessage.Replace("[随机表情]", "[RFace]"); return(FaceHelper.ReplaceRandomFace(tempMessage)); }
private async Task ConvertUnKnownPic(List <List <string> > tempUnknownPictures) { await Task.Run(() => { unknownSet = FaceHelper.ConvertFaces(tempUnknownPictures, true); }); }
/// <summary> /// Thin smile with ends /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> private void ThinSmileWithEndsMouth(XmlDocument document, XmlElement paper) { var x = CX - 75; var y = CY - 15; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "c 0,0 75,60 150,0"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); var e2 = FaceHelper.NewPath(document, paper); e2.SetAttribute("d", "M " + (x + 145) + "," + (y + 19) + "c 15.15229,-18.18274 3.03046,-32.32488 3.03046,-32.32488"); e2.SetAttribute("stroke", "#000"); e2.SetAttribute("stroke-width", "8"); e2.SetAttribute("fill", "none"); var e3 = FaceHelper.NewPath(document, paper); e3.SetAttribute("d", "M " + (x + 5) + "," + (y + 19) + "c -15.15229,-18.18274 -3.03046,-32.32488 -3.03046,-32.32488"); e3.SetAttribute("stroke", "#000"); e3.SetAttribute("stroke-width", "8"); e3.SetAttribute("fill", "none"); }
private async Task ConvertKnownPic(List <List <string> > pictures) { await Task.Run(() => { learningSet = FaceHelper.ConvertFaces(pictures, true); }); }
private void AfroHair(XmlDocument document, XmlElement paper, int width, int height) { var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M 25,250" + "a 210,150 0 1 1 352,0" + "c 0,0 -180,-150 -352,0"); FaceHelper.ScaleCentered(e, FaceHelper.FatScale(Fatness), 1, width, height); }
private void NormalShortHair(XmlDocument document, XmlElement paper, int width, int height) { var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M 200,100" + "c 0,0 180,-10 176,150" + "c 0,0 -180,-150 -352,0" + "c 0,0 0,-160 176,-150"); FaceHelper.ScaleCentered(e, FaceHelper.FatScale(Fatness), 1, width, height); }
/// <summary> /// Generic open mouth /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> private void GenericOpenMouth(XmlDocument document, XmlElement paper) { var x = CX - 55; var y = CY; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "a 54,10 0 1 1 110,0" + "a 54,20 0 1 1 -110,0"); }
/// <summary> /// Dot /// </summary> /// <param name="document"></param> /// <param name="paper"></param> private void DotEye(XmlDocument document, XmlElement paper, int width, int height) { var x = CX; var y = CY + 13; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "a 20,15 0 1 1 0.1,0"); FaceHelper.RotateCentered(e, (LR == LR.Left ? Angle : -Angle), width, height); }
public FaceUploaderAPIController(EmotionCoreContext context, IOptions <AppSettings> settings, IHostingEnvironment environment) { _context = context; faceHelper = new FaceHelper(settings.Value.ApiKey, settings.Value.BaseUri); faceAttributes = new FaceAttributeType[] { FaceAttributeType.Emotion }; UPLOAD_DIR = settings.Value.UploadDir; this._environment = environment; }
private void FlatTopHair(XmlDocument document, XmlElement paper, int width, int height) { var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M 25,60" + "h 352" + "v 190" + "c 0,0 -180,-150 -352,0" + "v -190"); FaceHelper.ScaleCentered(e, FaceHelper.FatScale(Fatness), 1, width, height); }
private void DefaultHead(XmlDocument document, XmlElement paper, int width, int height) { var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M 200,100" + "c 0,0 180,-10 180,200" + "c 0,0 0,210 -180,200" + "c 0,0 -180,10 -180,-200" + "c 0,0 0,-210 180,-200"); e.SetAttribute("fill", FaceHelper.GetHtmlColor(SkinColor)); FaceHelper.ScaleCentered(e, FaceHelper.FatScale(Fatness), 1, width, height); }
public UploaderController(IConfiguration config, IWebHostEnvironment webHostEnvironment, CognitiveServicesFaceContext context) { _config = config; _webHostEnvironment = webHostEnvironment; string key = _config.GetValue <string>("CognitiveServiceFaceKey"); string endPoint = _config.GetValue <string>("CognitiveServiceFaceEndPoint"); _faceHelper = new FaceHelper(key, endPoint); _context = context; }
public async void Init(CoreDispatcher coreDispatcher, CaptureElement element, Canvas faceCanvas) { _dispatcher = coreDispatcher; _captureElement = element; _faceCanvas = faceCanvas; _faceHelper = new FaceHelper( SettingsHelper.ReadSettings(SettingsHelper.FaceApiSubscriptionKey), SettingsHelper.ReadSettings(SettingsHelper.FaceApiRoot)); await _faceHelper.InitFaceGroup(SettingsHelper.ReadSettings(SettingsHelper.FaceApiPersonGroup)); }
/// <summary> /// Thin smile /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> private void ThinSmileMouth(XmlDocument document, XmlElement paper) { var x = CX - 75; var y = CY - 15; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "c 0,0 75,60 150,0"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); }
/// <summary> /// Thin flat /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> private void ThinFlatMouth(XmlDocument document, XmlElement paper) { var x = CX - 55; var y = CY; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "h 110"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); }
/// <summary> /// Horizontal /// </summary> /// <param name="document"></param> /// <param name="paper"></param> private void HorizontalEye(XmlDocument document, XmlElement paper, int width, int height) { var x = CX - 30; var y = CY; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "h 60"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); FaceHelper.RotateCentered(e, (LR == LR.Left ? Angle : -Angle), width, height); }
/// <summary> /// Big single /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> /// <param name="Size"></param> /// <param name="Flip"></param> private void BigSingleNose(XmlDocument document, XmlElement paper, int width, int height) { var scale = Size + 0.5; var x = CX - 9; var y = CY - 25; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "c 0,0 -20,60 9,55" + "c 0,0 29,5 9,-55"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); FaceHelper.ScaleCentered(e, scale, scale, width, height); }
private void _DrowLine(FaceModelRect faceRect, Color color, int thickness) { decimal d = base.Height / this.CaptureSize.Height; decimal d2 = base.Width / this.CaptureSize.Width; faceRect.Top = Convert.ToInt32(Math.Ceiling(faceRect.Top * d)); faceRect.Bottom = Convert.ToInt32(Math.Ceiling(faceRect.Bottom * d)); faceRect.Left = Convert.ToInt32(Math.Ceiling(faceRect.Left * d2)); faceRect.Right = Convert.ToInt32(Math.Ceiling(faceRect.Right * d2)); Rectangle rect = FaceHelper.MC_GetRectangleByRect(faceRect); Graphics expr_D9 = base.CreateGraphics(); expr_D9.SmoothingMode = SmoothingMode.AntiAlias; expr_D9.DrawRectangle(new Pen(color, (float)thickness), rect); expr_D9.Dispose(); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message && activity.Attachments.Count > 0) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); var imageattachment = activity.Attachments?.FirstOrDefault(a => a.ContentType.Contains("image")); Activity reply = activity.CreateReply(await FaceHelper.UploadAndDetectFaces(imageattachment.ContentUrl)); await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public async Task <ActionResult> Index() { try { var list = await FaceHelper.GetFaceModelList("https://images2015.cnblogs.com/blog/658978/201609/658978-20160922111329527-2030285818.png"); //todo:web端的处理(我这边就不弄了,需求是搞PC版的处理) ViewBag.InfoList = await list.ObjectToJsonAsync(); } catch (FaceException ex) { ViewBag.ErrorInfo = ex.Message; } return(View()); }
/// <summary> /// Arc eyelid /// </summary> /// <param name="document"></param> /// <param name="paper"></param> private void ArcEyelidEye(XmlDocument document, XmlElement paper, int width, int height) { var x = CX; var y = CY + 20; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "a 17,17 0 1 1 0.1,0 z"); FaceHelper.RotateCentered(e, (LR == LR.Left ? Angle : -Angle), width, height); var e2 = FaceHelper.NewPath(document, paper); e2.SetAttribute("d", "M " + (x - 40) + "," + (y - 14) + "c 36,-44 87,-4 87,-4"); e2.SetAttribute("stroke", "#000"); e2.SetAttribute("stroke-width", "4"); e2.SetAttribute("fill", "none"); FaceHelper.RotateCentered(e, (LR == LR.Left ? Angle : -Angle), width, height); }
/// <summary> /// Open-mouthed smile, top teeth /// </summary> /// <param name="document"></param> /// <param name="paper"></param> /// <param name="CX"></param> /// <param name="CY"></param> private void OpenMouthedSmileMouth(XmlDocument document, XmlElement paper) { var x = CX - 75; var y = CY - 15; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "c 0,0 75,100 150,0" + "h -150"); var e2 = FaceHelper.NewPath(document, paper); e2.SetAttribute("d", "M " + (x + 16) + "," + (y + 8) + "l 16,16" + "h 86" + "l 16,-16" + "h -118"); e2.SetAttribute("fill", "#f0f0f0"); }
/// <summary> /// Normal (circle with a dot in it) /// </summary> /// <param name="document"></param> /// <param name="paper"></param> private void NormalEye(XmlDocument document, XmlElement paper, int width, int height) { var x = CX; var y = CY + 20; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + x + "," + y + "a 30,20 0 1 1 0.1,0"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "6"); e.SetAttribute("fill", "#f0f0f0"); FaceHelper.RotateCentered(e, (LR == LR.Left ? Angle : -Angle), width, height); var e2 = FaceHelper.NewPath(document, paper); e2.SetAttribute("d", "M " + x + "," + (y - 12) + "a 12,8 0 1 1 0.1,0"); FaceHelper.RotateCentered(e2, (LR == LR.Left ? Angle : -Angle), width, height); }
public JsonResult FaceLogin(string account, string imgStr) { try { if (!SSOClient.Validate(account, out SysUser user)) { return(Json(new { Code = 1, Msg = "帐号不存在,请重新输入!" })); } if (!FaceHelper.Verify(account, imgStr)) { return(Json(new { Code = 1, Msg = "验证不通过!" })); } SSOClient.SignIn(user.UserId); return(Json(new { Code = 0, Msg = "登录成功!" })); } catch (Exception ex) { LogHelper.SaveLog(ex); return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" })); } }
private void DefaultEyebrow(XmlDocument document, XmlElement paper) { var x = CX - 30; var y = CY; var e = FaceHelper.NewPath(document, paper); if (LR == LR.Left) { e.SetAttribute("d", "M " + x + "," + y + "c 0,0 -3,-30 60,0"); } else { e.SetAttribute("d", "M " + x + "," + y + "c 0,0 63,-30 60,0"); } e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); }
private async void RunFacialDetection() { SetBusy("Detecting faces..."); ProgressIndeterminate = false; ProgressMin = 0; ProgressMax = Frames.Count; ProgressValue = 0; await Task.Run(() => { for (int i = 0; i < Frames.Count; i++) { BusyMessage = $"Checking for faces {(i + 1).ToString("#,###")} of {Frames.Count.ToString("#,###")}"; ProgressValue = i; Frames[i].HasFace = FaceHelper.HasFace(Frames[i].FullPath); } }); ProgressIndeterminate = true; SetFree(); }
/// <summary> /// Pinnochio /// </summary> /// <param name="document"></param> /// <param name="paper"></param> private void PinnochioNose(XmlDocument document, XmlElement paper, int width, int height) { var scale = Size + 0.5; var x = CX; var y = CY - 10; var e = FaceHelper.NewPath(document, paper); e.SetAttribute("d", "M " + (Flip ? x - 48 : x) + "," + y + "c 0,0 50,-30 0,30"); e.SetAttribute("stroke", "#000"); e.SetAttribute("stroke-width", "8"); e.SetAttribute("fill", "none"); if (Flip) { FaceHelper.ScaleCentered(e, -scale, scale, width, height); } else { FaceHelper.ScaleCentered(e, scale, scale, width, height); } }
public void Execute() { while (!this._stop) { this._haveImage.WaitOne(); if (!this._stop) { try { if (this._image != null && this._faceModels != null) { Image <Bgr, byte> image = this._image.Copy(); FaceModel[] array = this._faceModels.ToArray <FaceModel>(); byte[] data = image.Mat.GetData(new int[0]); int cols = image.Mat.Cols; int rows = image.Mat.Rows; int widthstep = image.Mat.Cols * 3; FaceModel[] array2 = array; for (int i = 0; i < array2.Length; i++) { FaceModel faceModel = array2[i]; if (faceModel.FaceRect.fConf >= this._faceCompreaSet.FaceConf) { Rectangle rect = FaceHelper.MC_GetRectangleByRect(faceModel.FaceRect, image.Size); Image <Bgr, byte> image2 = image.GetSubRect(rect).Copy(); this.OnShowFaceDeteiveImageEventHandler(image2.ToJpegData(95), faceModel, ""); FaceModel faceModel2 = faceModel.Clone(); if (this._ifaceCompareBase.ExtractFeature(data, cols, rows, widthstep, ref faceModel2) >= 0) { List <ResultInfo> list = new List <ResultInfo>(); foreach (FaceTemplate current in this._faceCompreaSet.FaceTemplates.ToList <FaceTemplate>()) { float num = this._ifaceCompareBase.Compare2Feature(faceModel2.Feature, current.FaceFeature); if (num >= this._faceCompreaSet.Threshold) { list.Add(new ResultInfo { FaceImage = image2.ToJpegData(95), FaceTemplate = current, FaceModel = faceModel2, Score = num }); } } image2.Dispose(); if (list.Count > 0) { IEnumerable <ResultInfo> arg_1E8_0 = list; Func <ResultInfo, float> arg_1E8_1; if ((arg_1E8_1 = FaceCompreaThread.class_c.class_c_9__13_0) == null) { arg_1E8_1 = (FaceCompreaThread.class_c.class_c_9__13_0 = new Func <ResultInfo, float>(FaceCompreaThread.class_c.class_c_9._Execute_b__13_0)); } list = arg_1E8_0.OrderByDescending(arg_1E8_1).Take(this._faceCompreaSet.CompareSuccessCount).ToList <ResultInfo>(); this.OnCompareSuccessEventHandler(list); } } if (this._faceCompreaSet.IsMaxFace) { break; } } } image.Dispose(); } } catch (Exception message) { this._log.Error(message); } } } }
private void button5_Click(object sender, EventArgs e) { string message = "aaa[随机表情]bbb[随机表情][随机表情]"; MessageBox.Show(FaceHelper.ReplaceRandomFace(message)); }