微软提供的人脸识别服务可检测图片中一个或者多我的脸,并为人脸标记出边框,同时还可得到基于机器学习技术作出的面部特征预测。可支持的人脸功能有:年龄、性别、头部姿态、微笑检测、胡须检测以及27个面部重要特征点位置等。FaceAPI 提供两个主要功能: 人脸检测和识别html
目录:web
申请订阅号算法
示例效果 json
开发过程api
using (Stream s = new MemoryStream(bytes)) { var requiredFaceAttributes = new FaceAttributeType[] { FaceAttributeType.Age, FaceAttributeType.Gender, FaceAttributeType.Smile, FaceAttributeType.FacialHair, FaceAttributeType.HeadPose, FaceAttributeType.Glasses }; var faces = await Utils.FaceClient.DetectAsync(s, returnFaceLandmarks: true, returnFaceAttributes: requiredFaceAttributes); }
也可直接使用http请求,参见:https://dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236微信
参数信息以下:网络
http post 示例代码:app
string URL = "你图片的url"; var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); // Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "你申请的key"); // Request parameters
queryString["returnFaceId"] = "true"; queryString["returnFaceLandmarks"] = "false"; queryString["returnFaceAttributes"] = "age,gender,smile"; var uri = "https://api.projectoxford.ai/face/v1.0/detect?" + queryString; HttpResponseMessage response; byte[] byteData = Encoding.UTF8.GetBytes("{\"url\":\"" + URL + "\"}"); using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var task = client.PostAsync(uri, content); response = task.Result; var task1 = response.Content.ReadAsStringAsync(); string JSON = task1.Result; }
人脸识别http参数以下:(注意:要识别出人脸的身份,你必须先定义person,参见 personGroup 、Person介绍 https://www.azure.cn/cognitive-services/en-us/face-api/documentation/face-api-how-to-topics/howtoidentifyfacesinimage)框架
var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "XXX"); var uri = "https://api.projectoxford.ai/face/v1.0/identify "; HttpResponseMessage response; byte[] byteData = Encoding.UTF8.GetBytes("{\"faceIds\":[\"XXX\"],\"personGroupId\":\"XXX\",\"maxNumOfCandidatesReturned\":5}"); using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var task = client.PostAsync(uri, content); response = task.Result; var task1 = response.Content.ReadAsStringAsync(); string JSON = task1.Result; }
var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "你申请的key"); var uri = "https://api.projectoxford.ai/face/v1.0/persongroups/你上传的分组/persons/" + personID; var task = client.GetStringAsync(uri); var response = task.Result; return JsonConvert.DeserializeObject<Person>(task.Result);
AForge.Net机器学习
FilterInfoCollection videoDevices; VideoCaptureDevice videoSource; public int selectedDeviceIndex = 0;
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); selectedDeviceIndex = 0; videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//链接摄像头。
videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex]; videoSourcePlayer1.VideoSource = videoSource; // set NewFrame event handler
videoSourcePlayer1.Start();
抓拍示代码
if (videoSource == null) return; Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame(); string fileName = string.Format("{0}.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff")); this.filePath = string.Format("c:\\temp\\{0}", fileName); bitmap.Save(this.filePath, ImageFormat.Jpeg); this.labelControl1.Text = string.Format("存储目录:{0}", this.filePath); bitmap.Dispose(); videoDevices.Clear();
窗体关闭事件
if (this.videoSource != null) { if (this.videoSource.IsRunning) { this.videoSource.Stop(); } }
示例效果