void Start() { visionScript = vision.GetComponent <vision>(); visionCornersScript = vision.GetComponent <visionCorners>(); showRays = false; }
public static vision recognizewithImg(byte[] img) { var queryString = HttpUtility.ParseQueryString(string.Empty); queryString["visualFeatures"] = "Categories,Adult,Faces"; queryString["subscription-key"] = "<SUBSCRIPTION_KEY>"; var uri = new Uri("https://api.projectoxford.ai/vision/v1/analyses?" + queryString); var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.Proxy = null; request.ContentType = "application/octet-stream"; request.ContentLength = img.Length; var responseString = ""; using (var stream = request.GetRequestStream()) { stream.Write(img, 0, img.Length); } var response = (HttpWebResponse)request.GetResponse(); responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); DataContractJsonSerializer contract = new DataContractJsonSerializer(typeof(vision)); MemoryStream mstream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseString)); vision Vision = (vision)contract.ReadObject(mstream); return(Vision); }
void showResult(DetectedResult result, vision Vision) { this.Invoke(new Action(() => { button3.Show(); richTextBox1.Clear(); var res = result.face.OrderBy((o) => o.position.center.x).ToArray(); syn.SetOutputToDefaultAudioDevice(); bool hasFaces = false; //TODO:Check If The API Detected Adult Content In This Photo. if (Vision.categories != null) { if (Vision.categories.Count() > 0) { syn.SpeakAsync("Image Category is: "); richTextBox1.Text += "Image Category is: "; foreach (var item in Vision.categories) { syn.SpeakAsync(item.name.Replace('_', ' ') + "\n"); richTextBox1.Text += item.name.Replace('_', ' ') + "\n"; } } } //TODO:Check If The OxFord Vision API Detected Adult Content In This Photo. if (Vision.adult.isAdultContent) { syn.SpeakAsync("Image Has Adult Content\n"); richTextBox1.Text += "Image Has Adult Content\n"; } //Check If Face++ Returned Any Faces if (result.face != null) { if (result.face.Count() > 0) { hasFaces = true; } } if (hasFaces) { syn.SpeakAsync(res.Count() + " Faces Detected\n"); richTextBox1.Text += res.Count() + " Faces Detected\n"; if (res.Count() > 0) { if (res.Count() > 1) { syn.SpeakAsync("Starting from the Left\n"); richTextBox1.Text += "Starting from the Left\n"; } int count = 0; foreach (var item in res) { string[] heshe = new string[2]; if (item.attribute.gender.value.ToLower() == "female") { heshe[0] = "she"; heshe[1] = "her"; } else { heshe[0] = "he"; heshe[1] = "his"; } richTextBox1.Text += "Age: " + item.attribute.age.value + " the Gender is: " + item.attribute.gender.value + " " + heshe[1] + " Race is: " + item.attribute.race.value + " And " + heshe[0] + " Looks: " + faceState(Math.Round(item.attribute.smiling.value, 1)) + "\n"; syn.SpeakAsync("Face Number: " + (++count) + " : Age: " + item.attribute.age.value + " the Gender is: " + item.attribute.gender.value + " " + heshe[1] + " Race is: " + item.attribute.race.value + " And " + heshe[0] + " Looks: " + faceState(Math.Round(item.attribute.smiling.value, 1)) + "\n"); } } } else { //Face++ Didn't Return Any Faces So We'll See If OxFord Vision Returned any faces. if (Vision.faces.Count > 0) { var ress = Vision.faces.OrderBy(o => o.faceRectangle.left).ToArray(); syn.SpeakAsync(ress.Count() + " Faces Detected\n"); richTextBox1.Text += ress.Count() + " Faces Detected\n"; if (ress.Count() > 0) { if (ress.Count() > 1) { syn.SpeakAsync("Starting from the Left\n"); richTextBox1.Text += "Starting from the Left\n"; } int count = 0; foreach (var item in ress) { richTextBox1.Text += "Age: " + item.age + " And the Gender is: " + item.gender + " " + "\n"; syn.SpeakAsync("Face Number: " + (++count) + " : Age: " + item.age + " And the Gender is: " + item.gender); } } } else { syn.SpeakAsync("No Faces Detected\n"); richTextBox1.Text += "No Faces Detected\n"; } } button1.Enabled = true; button2.Enabled = true; lblState.Text = "Done"; })); }
void showResult(DetectedResult result, vision Vision) { new Thread(() => { new SoundPlayer(Path.GetDirectoryName(Application.ExecutablePath) + "\\done.wav").PlaySync(); }).Start(); this.Invoke(new Action(() => { richTextBox1.Text = "State: Done.\n\n"; richTextBox1.Clear(); var res = result.face.OrderBy((o) => o.position.center.x).ToArray(); syn.SetOutputToDefaultAudioDevice(); bool hasFaces = false; //TODO:Check If The API Detected Adult Content In This Photo. if (Vision.categories != null) { if (Vision.categories.Count() > 0) { richTextBox1.Text += "Image Category is: "; int count = 0; foreach (var item in Vision.categories) { if (count == Vision.categories.Count - 1) { richTextBox1.Text += item.name.Replace('_', ' ') + ".\n"; } else { richTextBox1.Text += item.name.Replace('_', ' ') + ", "; } count++; } } } ////TODO:Check If The OxFord Vision API Detected Adult Content In This Photo. if (Vision.adult.isAdultContent) { richTextBox1.Text += "Image Has Adult Content.\n"; } //Check If Face++ Returned Any Faces if (result.face != null) { if (result.face.Count() > 0) { hasFaces = true; } } if (hasFaces) { richTextBox1.Text += res.Count() + " Faces Detected.\n"; if (res.Count() > 0) { if (res.Count() > 1) { richTextBox1.Text += "Starting from the Left.\n"; } int count = 0; foreach (var item in res) { string[] heshe = new string[2]; if (item.attribute.gender.value.ToLower() == "female") { heshe[0] = "she"; heshe[1] = "her"; } else { heshe[0] = "he"; heshe[1] = "his"; } richTextBox1.Text += "Face Number " + (++count) + ": Age " + item.attribute.age.value + ", the Gender is " + item.attribute.gender.value + ", " + heshe[1] + " Race is " + item.attribute.race.value + ", And " + heshe[0] + " Looks " + faceState(Math.Round(item.attribute.smiling.value, 1)) + " (" + Math.Round(item.attribute.smiling.value, 0) + "% Smiling)." + "\n"; } } } else { //Face++ Didn't Return Any Faces So We'll See If OxFord Vision Returned any faces. if (Vision.faces.Count > 0) { var ress = Vision.faces.OrderBy(o => o.faceRectangle.left).ToArray(); richTextBox1.Text += ress.Count() + " Faces Detected.\n"; if (ress.Count() > 0) { if (ress.Count() > 1) { richTextBox1.Text += "Starting from the Left.\n"; } int count = 0; foreach (var item in ress) { richTextBox1.Text += "Face Number " + (++count) + ": Age " + item.age + ", And the Gender is " + item.gender + " " + ".\n"; } } } else { richTextBox1.Text += "No Faces Detected.\n"; } } button1.Enabled = true; // button2.Enabled = true; })); }