微軟提供的人臉識別服務可檢測圖片中一個或者多我的臉,併爲人臉標記出邊框,同時還可得到基於機器學習技術作出的面部特徵預測。可支持的人臉功能有:年齡、性別、頭部姿態、微笑檢測、鬍鬚檢測以及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(); } }
示例效果