Image recognition using #Azure Computer Vision with C#
Assuming you have an Azure account, if you open up a Computer vision service under Cognitive Services, and grab an API key, you can use Azure to recognise the content of images. – Great for tagging images in blogs, or making sure nobody uploads a nude pic as their profile image on your website – For which you should check out AvatarApi.com for this!
So, lets see some code – I’m using C#, and Newtonsoft to parse the Json;
const string strUrl = “https://westeurope.api.cognitive.microsoft.com/vision/v1.0/analyze?visualFeatures=Tags”;
var wc = new WebClient();
wc.Headers[“Ocp-Apim-Subscription-Key”] = “xxxxxxx”;
var jPost = new { url = Url };
var strPost = JsonConvert.SerializeObject(jPost, Formatting.Indented);
var strJson = wc.UploadString(strUrl, “POST”, strPost);
var jResult = JObject.Parse(strJson);
Depending on your image of course, this will return JSON similar to the following;
{ "tags": [ { "name": "car", "confidence": 0.99999725818634 }, { "name": "outdoor", "confidence": 0.99585741758347 }, { "name": "transport", "confidence": 0.82641708850861 }, { "name": "blue", "confidence": 0.51219713687897 }, { "name": "roof", "confidence": 0.091790720820427 }, { "name": "automotive", "confidence": 0.01434036432286 }, { "name": "summer", "confidence": 0.0078773201327271 } ], "requestId": "e0010f8b-189f-4481-ad02-5b71b3ac2b2b", "metadata": { "width": 1600, "height": 1200, "format": "Jpeg" } }