Skip to content

Instantly share code, notes, and snippets.

@rnrneverdies
Last active March 13, 2018 14:10
Show Gist options
  • Save rnrneverdies/ae4116a219dcd24952f3a395fbbb28a7 to your computer and use it in GitHub Desktop.
Save rnrneverdies/ae4116a219dcd24952f3a395fbbb28a7 to your computer and use it in GitHub Desktop.
Test method for the Windows Machine Learning, EmotionRecognition sample.
// Load the model
var recognizer = new EmotionRecognizer();
await recognizer.LoadModelAsync());
// Trigger file picker to select an image file
var fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.FileTypeFilter.Add(".png");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
var selectedStorageFile = await fileOpenPicker.PickSingleFileAsync();
SoftwareBitmap softwareBitmap;
using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read))
{
// Create a decoder from the stream
var decoder = await BitmapDecoder.CreateAsync(stream);
// Get the SoftwareBitmap representation of the file in BGRA8 format
var = await decoder.GetSoftwareBitmapAsync();
softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Gray8,
BitmapAlphaMode.Ignore);
}
// Encapsulate the image within a VideoFrame to be bound and evaluated
var inputImage = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);
// Evaluate the image
var result = await recognizer.EvaluateAsync(inputImage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment