Use #AI to recognise an image in c# @imagga
Link: https://imagga.com/?s=aZzh2zG5r2ZSPSM
Being able to tell the difference between an image of a car, and a banana is a ridiculously simple task for a human, but it’s not easy for a computer. Scan the image, and sum the yellow pixels as a percentage of the total pixels, but that doesn’t work on a yellow car, or an unripe banana.
This is where AI comes in, and it’s not just the realm of academia or data scientists any more. Real world business needs this service. Imagine you sell used cars online?, do you check every uploaded image to say it’s actually a car, or pornography?
I came across imagga, which offers a free 2,000 calls / month package. Given an image URL, it returns a list of keywords (tags) and a % confidence in each one. So if I want to check an image is a car, I can look for a tag called “car” and require a confidence > 90%
var strUrl = “http://api.imagga.com/v1/tagging?url=” + url;
var wc = new WebClient
{
Credentials = new NetworkCredential(“acc_xxxxxxxxxx”, “xxxxxxxxxxxxxxxx”)
};
var strJson = wc.DownloadString(strUrl);
var oRecognise = JavascriptDeserialize<imaggaResults>(strJson);
var carConfidence = oRecognise.results[0].tags.First(o => o.tag == “car”).confidence;
return carConfidence > 90;
With the following ‘helper’ methods
public static T JavascriptDeserialize<T>(string json)
{
var jsSerializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
return jsSerializer.Deserialize<T>(json);
}#region imagga objects
public class Tag
{
public double confidence { get; set; }
public string tag { get; set; }
}public class imaggaResult
{
public object tagging_id { get; set; }
public string image { get; set; }
public List<Tag> tags { get; set; }
}public class imaggaResults
{
public List<imaggaResult> results { get; set; }
}
#endregion