This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine("Faces being detected ..."); | |
IList<DetectedFace> faceList = | |
await faceClient.Face.DetectWithUrlAsync( | |
imageUrl, true, false, faceAttributes); | |
var face = faceList[0]; | |
Console.WriteLine($"FaceId: {face.FaceId}"); | |
Console.WriteLine($"Age: {face.FaceAttributes.Age}"); | |
Console.WriteLine($"Blur: {face.FaceAttributes.Blur.BlurLevel}, {face.FaceAttributes.Blur.Value}"); | |
Console.WriteLine($"Emotion: {{Anger: {face.FaceAttributes.Emotion.Anger}, Contempt: {face.FaceAttributes.Emotion.Contempt}, Disgust: {face.FaceAttributes.Emotion.Disgust}, Fear: {face.FaceAttributes.Emotion.Fear}, Happiness: {face.FaceAttributes.Emotion.Happiness}, Neutral: {face.FaceAttributes.Emotion.Neutral}, Sadness: {face.FaceAttributes.Emotion.Sadness}, Surprise: {face.FaceAttributes.Emotion.Surprise}}}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static readonly FaceAttributeType[] faceAttributes = | |
{ | |
FaceAttributeType.Age, FaceAttributeType.Gender, FaceAttributeType.Accessories, FaceAttributeType.Blur, | |
FaceAttributeType.Emotion, FaceAttributeType.Exposure, FaceAttributeType.FacialHair, | |
FaceAttributeType.Glasses, FaceAttributeType.Hair, FaceAttributeType.HeadPose, FaceAttributeType.Makeup, | |
FaceAttributeType.Noise, FaceAttributeType.Occlusion, FaceAttributeType.Smile | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FaceClient faceClient = new FaceClient( | |
new ApiKeyServiceClientCredentials(apiKey), | |
new System.Net.Http.DelegatingHandler[] { }); | |
faceClient.Endpoint = "https://southeastasia.api.cognitive.microsoft.com/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string apiKey = configuration.GetSection("apiKey").Value; | |
string imageUrl = "https://cdn-images-1.medium.com/max/1200/0*WVev4lO0ZXp6tDed"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine("Images being analyzed ..."); | |
ImageAnalysis analysis = | |
await client.AnalyzeImageAsync(imageUrl, features); | |
Console.WriteLine("Text: " + analysis.Description.Captions[0].Text); | |
Console.WriteLine("Confidence: " + analysis.Description.Captions[0].Confidence); | |
Console.WriteLine("Categories: " + string.Join(", ", analysis.Categories.Select(x=>x.Name))); | |
Console.WriteLine("Tags: " + string.Join(", ", analysis.Tags.Select(x=>x.Name))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum VisualFeatureTypes | |
{ | |
ImageType = 0, | |
Faces = 1, | |
Adult = 2, | |
Categories = 3, | |
Color = 4, | |
Tags = 5, | |
Description = 6 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 指定要回傳的資訊 | |
private static readonly List<VisualFeatureTypes> features = | |
new List<VisualFeatureTypes>() | |
{ | |
VisualFeatureTypes.Categories, VisualFeatureTypes.Description, | |
VisualFeatureTypes.ImageType, VisualFeatureTypes.Tags | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ComputerVisionClient client = new ComputerVisionClient( | |
new ApiKeyServiceClientCredentials(apiKey), | |
new System.Net.Http.DelegatingHandler[] { }); | |
// 根據 Azure Portal 上之資訊填寫 | |
client.Endpoint = "https://southeastasia.api.cognitive.microsoft.com/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string apiKey = configuration.GetSection("apiKey").Value; | |
string imageUrl = | |
"https://img.appledaily.com.tw/images/ReNews/20181016/640_32e5f4fe808e4669a337b7b30ce3df81.jpg"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
... | |
services.AddElmahIo(o => | |
{ | |
o.ApiKey = "{API_KEY}"; | |
o.LogId = new Guid("{LOG_ID}"); |