Created
December 25, 2021 19:04
-
-
Save norton287/07317fe75f7843eb899b2b81c8bf05d6 to your computer and use it in GitHub Desktop.
Computer Vision Code
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
try | |
{ | |
var connectionString = AppSettings.VisionEndPoint; | |
var visionKey = AppSettings.VisionKey; | |
List<VisualFeatureTypes?> features = new List<VisualFeatureTypes?>() | |
{ | |
VisualFeatureTypes.Categories, VisualFeatureTypes.Description, | |
VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType, | |
VisualFeatureTypes.Tags, VisualFeatureTypes.Adult, | |
VisualFeatureTypes.Color, VisualFeatureTypes.Brands, | |
VisualFeatureTypes.Objects | |
}; | |
ComputerVisionClient computerVisionClient = new ComputerVisionClient( | |
new ApiKeyServiceClientCredentials(visionKey), | |
new DelegatingHandler[] { } | |
) | |
{ | |
Endpoint = connectionString | |
}; | |
using var myStream2 = File.OpenRead(PhotoPath); | |
using (var fs = myStream2) | |
{ | |
ImageAnalysis result = computerVisionClient.AnalyzeImageInStreamAsync(image: fs, features) | |
.Result; | |
Debug.WriteLine(result.Adult.IsAdultContent + " :: " + result.Adult.IsRacyContent + " :: " + result.Adult.IsGoryContent); | |
{ | |
if (result.Adult.IsAdultContent || result.Adult.IsRacyContent || | |
result.Adult.IsGoryContent) | |
{ | |
DependencyService.Get<iToast>().Show("Adult Content Is Not Allowed!"); | |
donotrun = true; | |
} | |
} | |
myStream2.Close(); | |
} | |
if (!donotrun) | |
{ | |
using var myStream = File.OpenRead(PhotoPath); | |
await blobClient.UploadAsync(myStream); | |
myStream.Close(); | |
} | |
} | |
catch (RequestFailedException e) | |
{ | |
Crashes.TrackError(e); | |
Debug.WriteLine("Something Occurred: " + e.Status); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment