Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Add Digital Asset Management (#120)
Browse files Browse the repository at this point in the history
* Add Digital Asset Management demo

* update converters

* Remove Image Collection Insights demo

* Add docs
  • Loading branch information
Albert Davletov authored Nov 4, 2020
1 parent 7165c32 commit dff2bbc
Show file tree
Hide file tree
Showing 24 changed files with 2,885 additions and 903 deletions.
Binary file added Documentation/DigitalAssetManagement.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Documentation/DigitalAssetManagement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Digital Asset Management
This sample illustrates how Computer Vision can add a layer of insights to a collection of images.

![alt text](https://github.com/Microsoft/Cognitive-Samples-IntelligentKiosk/blob/master/Documentation/DigitalAssetManagement.jpg "Digital Asset Management")

# Key Source Code

* [DigitalAssetManagementPage](../Kiosk/Views/DigitalAssetManagement/DigitalAssetManagementPage.xaml.cs): Main page that drives the demo. It displays the images along with its associated filters. It also contains the UI to manage your cached insights extracted from your images.

* [ImageInsights](../Kiosk/Views/DigitalAssetManagement/ImageInsights.cs): POCO object representing insights extracted from each of your images.

* [ImageInsightsViewModel](../Kiosk/Views/DigitalAssetManagement/ImageInsightsViewModel.cs): A wrapper around the ImageInsights object to support data binding to the UI and filtering the image collection.

* [ImageProcessor](../Kiosk/Views/DigitalAssetManagement/ImageProcessor.cs): Uses your Azure Cognitive Service to extract ImageInsights from your images.

* [FilesViewModel](../Kiosk/Views/DigitalAssetManagement/FilesViewModel.cs): CRUD operations for ImageInsights. Stores them in JSON format within the applications local storage.

## Running the demo

The first time the solution is ran you will be prompted to enter your Azure Cognitive Service key. If you don't have one, you can create one [here](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne). Your key is stored in the applications local settings. Your key can be changed in the future using the settings menu.

Next, select either a local folder containing images, or an Azure blob collection containing images. If you are using a blob collection you will need to supply a [shared access signature URI](https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview). This URI will allow temporary access to even private containers.

Once a folder or storage collection is selected the images will be processed for insights. The image insights are cached in the applications local storage. Only the insights about the images are cached while the images themselves are not. The insights can be re opened, downloaded or deleted using the History menu.

## How it works

Each image from a local folder or a blob collection is processed through the Computer Vision API and/or the Face API, depending on which services you elect to use. The results are cached in the applications local storage using JSON file format. The images themselves are never cached. The JSON file contains the output from the API for each image, minus some extracted insights not used by this demo.

Each time the JSON file is loaded it is used to create a list of filters over the images. These filters, along with the associated images are displayed in the UI. When a filter is selected, images matching that filter are added to the image display. If no filters are selected, all images are displayed.
Binary file removed Documentation/ImageCollectionInsights.JPG
Binary file not shown.
22 changes: 0 additions & 22 deletions Documentation/ImageCollectionInsights.md

This file was deleted.

82 changes: 80 additions & 2 deletions Kiosk/Controls/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

using ServiceHelpers;
using System;
using System.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

Expand Down Expand Up @@ -254,7 +255,25 @@ public class CollectionCountToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return System.Convert.ToInt32(value) > 0 ? Visibility.Visible : Visibility.Collapsed;
//get min value
int.TryParse(parameter != null ? (string)parameter : string.Empty, out int minValue);

//get count
var count = 0;
if (value is int)
{
count = (int)value;
}
else
{
var collection = value as ICollection;
if (collection != null)
{
count = collection.Count;
}
}

return count > minValue ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand All @@ -267,7 +286,25 @@ public class ReverseCollectionCountToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return System.Convert.ToInt32(value) > 0 ? Visibility.Collapsed : Visibility.Visible;
//get min value
int.TryParse(parameter != null ? (string)parameter : string.Empty, out int minValue);

//get count
var count = 0;
if (value is int)
{
count = (int)value;
}
else
{
var collection = value as ICollection;
if (collection != null)
{
count = collection.Count;
}
}

return count > minValue ? Visibility.Collapsed : Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand Down Expand Up @@ -370,4 +407,45 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
throw new NotImplementedException();
}
}

public class MathConverter : IValueConverter
{
public double Add { get; set; }
public double Multiply { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value != null)
{
var number = System.Convert.ToDouble(value);
return (number + Add) * Multiply;
}
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value != null)
{
var number = System.Convert.ToDouble(value);
return (number / Multiply) - Add;
}
return value;
}
}

public class BooleanToIntConverter : IValueConverter
{
public int IfTrue { get; set; } = 1;
public int IfFalse { get; set; } = 0;
public object Convert(object value, Type targetType, object parameter, string language)
{

return (bool)value ? IfTrue : IfFalse;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return ((int)value) == IfTrue ? true : false;
}
}
}
31 changes: 18 additions & 13 deletions Kiosk/IntelligentKioskSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@
<Compile Include="Views\DemoLauncher\DemoLauncherPage.xaml.cs">
<DependentUpon>DemoLauncherPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\DigitalAssetManagement\DigitalAssetManagementPage.xaml.cs">
<DependentUpon>DigitalAssetManagementPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\DigitalAssetManagement\FilesViewModel.cs" />
<Compile Include="Views\DigitalAssetManagement\ImageInsightsViewModel.cs" />
<Compile Include="Views\DigitalAssetManagement\ImageInsights.cs" />
<Compile Include="Views\DigitalAssetManagement\ImageProcessor.cs" />
<Compile Include="Views\DigitalAssetManagement\StorageDialog.xaml.cs">
<DependentUpon>StorageDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\FaceApiExplorer\FaceApiExplorerPage.xaml.cs">
<DependentUpon>FaceApiExplorerPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -383,15 +393,6 @@
<Compile Include="Views\HowOldKioskPage.xaml.cs">
<DependentUpon>HowOldKioskPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ImageCollectionInsights\EmotionFilterViewModel.cs" />
<Compile Include="Views\ImageCollectionInsights\FaceFilterViewModel.cs" />
<Compile Include="Views\ImageCollectionInsights\FaceInsights.cs" />
<Compile Include="Views\ImageCollectionInsights\ImageCollectionInsights.xaml.cs" />
<Compile Include="Views\ImageCollectionInsights\ImageInsights.cs" />
<Compile Include="Views\ImageCollectionInsights\ImageInsightsViewModel.cs" />
<Compile Include="Views\ImageCollectionInsights\ImageProcessor.cs" />
<Compile Include="Views\ImageCollectionInsights\TagFilterViewModel.cs" />
<Compile Include="Views\ImageCollectionInsights\VisionInsights.cs" />
<Compile Include="Views\FormRecognizer\InitialView.xaml.cs">
<DependentUpon>InitialView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -708,6 +709,14 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\DigitalAssetManagement\DigitalAssetManagementPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DigitalAssetManagement\StorageDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\FaceApiExplorer\FaceApiExplorerPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -748,10 +757,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ImageCollectionInsights\ImageCollectionInsights.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\FormRecognizer\InitialView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
12 changes: 12 additions & 0 deletions Kiosk/ServiceHelpers/CoreUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,17 @@ public static Rect ToRect(this BoundingRect rect)
{
return new Rect(rect.X, rect.Y, rect.W, rect.H);
}

public static Rect Inflate(this Rect rect, double inflatePercentage)
{
var width = rect.Width * inflatePercentage;
var height = rect.Height * inflatePercentage;
return new Rect(rect.X - ((width - rect.Width) / 2), rect.Y - ((height - rect.Height) / 2), width, height);
}

public static Rect Scale(this Rect rect, double scale)
{
return new Rect(rect.X * scale, rect.Y * scale, rect.Width * scale, rect.Height * scale);
}
}
}
Loading

0 comments on commit dff2bbc

Please sign in to comment.