in code_examples/dotnet_examples/image/net-detect-labels-local-file.cs [11:52]
public static void Example()
{
String photo = "input.jpg";
Amazon.Rekognition.Model.Image image = new Amazon.Rekognition.Model.Image();
try
{
using (FileStream fs = new FileStream(photo, FileMode.Open, FileAccess.Read))
{
byte[] data = null;
data = new byte[fs.Length];
fs.Read(data, 0, (int)fs.Length);
image.Bytes = new MemoryStream(data);
}
}
catch (Exception)
{
Console.WriteLine("Failed to load file " + photo);
return;
}
AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();
DetectLabelsRequest detectlabelsRequest = new DetectLabelsRequest()
{
Image = image,
MaxLabels = 10,
MinConfidence = 77F
};
try
{
DetectLabelsResponse detectLabelsResponse = rekognitionClient.DetectLabels(detectlabelsRequest);
Console.WriteLine("Detected labels for " + photo);
foreach (Label label in detectLabelsResponse.Labels)
Console.WriteLine("{0}: {1}", label.Name, label.Confidence);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}