Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hauerCodes committed Dec 13, 2014
1 parent ff018a9 commit 8d4a9e3
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 382 deletions.
Binary file not shown.
25 changes: 12 additions & 13 deletions NumberRecognizer/NumberRecognizer.App/NumberRecognizer.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@
<DesignTime>True</DesignTime>
<DependentUpon>Reference.svcmap</DependentUpon>
</Compile>
<Compile Include="ViewModel\CreateNetworkViewModel.cs" />
<Compile Include="ViewModel\GroupedNetworksDesignViewModel.cs" />
<Compile Include="ViewModel\GroupedNetworksViewModel.cs" />
<Compile Include="View\GroupedNetworksPage.xaml.cs">
<DependentUpon>GroupedNetworksPage.xaml</DependentUpon>
</Compile>
<Compile Include="View\NetworkDetailPage.xaml.cs">
<DependentUpon>NetworkDetailPage.xaml</DependentUpon>
</Compile>
Expand All @@ -132,12 +136,6 @@
<Compile Include="View\CreateNetworkPage.xaml.cs">
<DependentUpon>CreateNetworkPage.xaml</DependentUpon>
</Compile>
<Compile Include="View\GroupDetailPage.xaml.cs">
<DependentUpon>GroupDetailPage.xaml</DependentUpon>
</Compile>
<Compile Include="View\GroupedNetworksPage.xaml.cs">
<DependentUpon>GroupedNetworksPage.xaml</DependentUpon>
</Compile>
<Compile Include="View\RecognizePage.xaml.cs">
<DependentUpon>RecognizePage.xaml</DependentUpon>
</Compile>
Expand All @@ -162,6 +160,7 @@
<Content Include="Assets\LightGray.png" />
<Content Include="Assets\MediumGray.png" />
<Content Include="Assets\DarkGray.png" />
<Content Include="Lib\De.TorstenMandelkow.MetroChart.dll" />
<None Include="Service References\NumberRecognizerService\NumberRecognizerService1.disco" />
<None Include="Service References\NumberRecognizerService\NumberRecognizerService1.wsdl" />
<None Include="Service References\NumberRecognizerService\NumberRecognizerService4.xsd">
Expand Down Expand Up @@ -193,19 +192,15 @@
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="View\NetworkDetailPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\CreateNetworkPage.xaml">
<Page Include="View\GroupedNetworksPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\GroupDetailPage.xaml">
<Page Include="View\NetworkDetailPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\GroupedNetworksPage.xaml">
<Page Include="View\CreateNetworkPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand All @@ -215,6 +210,10 @@
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="De.TorstenMandelkow.MetroChart, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\De.TorstenMandelkow.MetroChart.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight">
<HintPath>..\packages\Portable.MvvmLightLibs.5.0.2.0\lib\netcore451\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
Expand Down
5 changes: 5 additions & 0 deletions NumberRecognizer/NumberRecognizer.App/Style/AppStyle.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chart="using:De.TorstenMandelkow.MetroChart"
xmlns:local="using:NumberRecognizer.App.Style">
<Style x:Key="CustomHeaderTextBlockStyle" BasedOn="{StaticResource BaseTextBlockStyle}" TargetType="TextBlock">
<Setter Property="FontSize" Value="56"/>
Expand All @@ -21,5 +22,9 @@
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
<Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
<Setter Property="Width" Value="500"/>
<Setter Property="Height" Value="500"/>
</Style>

</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,20 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid Grid.Row="0" Grid.Column="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" Name="NameTextBox" FontSize="{StaticResource FontSize}"/>
<Button Grid.Column="1" Margin="10,0" Command="{Binding CreateNetwork}">Train Network</Button>
</Grid>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Description:&#42;" Style="{StaticResource SubheaderTextBlockStyle}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="0" Grid.Column="1" Name="NameTextBox" FontSize="{StaticResource FontSize}"/>


<TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="1" Text="Please write some Network Training Data Numbers on each Canvas."
Style="{StaticResource CustomTextBlockStyle}" Margin="0, 10"
Foreground="OrangeRed" VerticalAlignment="Center"/>
Expand Down Expand Up @@ -117,6 +128,7 @@
StrokeThickness="{StaticResource StrokeThickness}"
Height="{StaticResource InkHeight}" Margin="0,10"/>
</Grid>

</ScrollViewer>
</Grid>
</Page>
135 changes: 30 additions & 105 deletions NumberRecognizer/NumberRecognizer.App/View/CreateNetworkPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
// <author>Markus Zytek</author>
// <summary>Create Network Page.</summary>
//-----------------------------------------------------------------------


using NumberRecognizer.App.Common;
using NumberRecognizer.App.Common;
using NumberRecognizer.App.Control;
using NumberRecognizer.App.Help;
using NumberRecognizer.App.ViewModel;
using NumberRecognizer.Labeling;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.System.UserProfile;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;

namespace NumberRecognizer.App
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using NumberRecognizer.App.Common;
using NumberRecognizer.App.Common;
using NumberRecognizer.App.Control;
using NumberRecognizer.App.Help;
using Windows.System.UserProfile;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;
using NumberRecognizer.Labeling;


/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
Expand All @@ -40,12 +39,7 @@ public sealed partial class CreateNetworkPage : Page
/// <summary>
/// The default view model
/// </summary>
private ObservableDictionary defaultViewModel = new ObservableDictionary();

/// <summary>
/// The ink canvases
/// </summary>
private List<InkCanvasRT> inkCanvasRT = new List<InkCanvasRT>();
private CreateNetworkViewModel defaultViewModel = new CreateNetworkViewModel();

/// <summary>
/// Initializes a new instance of the <see cref="CreateNetworkPage"/> class.
Expand All @@ -65,7 +59,7 @@ public CreateNetworkPage()
/// <imgByte>
/// The default view model.
/// </imgByte>
public ObservableDictionary DefaultViewModel
public CreateNetworkViewModel DefaultViewModel
{
get { return this.defaultViewModel; }
}
Expand Down Expand Up @@ -115,18 +109,16 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
/// </summary>
private async void InitPage()
{
this.inkCanvasRT.Add(this.InkCanvasRT0);
this.inkCanvasRT.Add(this.InkCanvasRT1);
this.inkCanvasRT.Add(this.InkCanvasRT2);
this.inkCanvasRT.Add(this.InkCanvasRT3);
this.inkCanvasRT.Add(this.InkCanvasRT4);
this.inkCanvasRT.Add(this.InkCanvasRT5);
this.inkCanvasRT.Add(this.InkCanvasRT6);
this.inkCanvasRT.Add(this.InkCanvasRT7);
this.inkCanvasRT.Add(this.InkCanvasRT8);
this.inkCanvasRT.Add(this.InkCanvasRT9);

this.NameTextBox.Text = string.Format("{0}_{1}", await UserInformation.GetLastNameAsync(), DateTime.Now.ToFileTime());
DefaultViewModel.CanvasList.Add(this.InkCanvasRT0);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT1);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT2);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT3);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT4);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT5);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT6);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT7);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT8);
DefaultViewModel.CanvasList.Add(this.InkCanvasRT9);
}

/// <summary>
Expand Down Expand Up @@ -156,72 +148,5 @@ private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
}

/// <summary>
/// Handles the Click event of the NextButton control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Windows.UI.Xaml.RoutedEventArgs"/> instance containing the event data.</param>
private async void NextButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
foreach (InkCanvasRT inkCanvas in this.inkCanvasRT)
{
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(inkCanvas);

byte[] canvasRGBABytes = (await renderTargetBitmap.GetPixelsAsync()).ToArray();
byte[] canvasBytes = await ImageHelperRT.GetByteArrayFromRGBAByteArrayAsync(canvasRGBABytes, inkCanvas.ForegroundColor);

double canvasWidth = inkCanvas.ActualWidth;
double canvasHeight = inkCanvas.ActualHeight;
double[,] canvasPixels = await ImageHelperRT.Get2DPixelArrayFromByteArrayAsync(canvasBytes, canvasWidth, canvasHeight);

inkCanvas.ConnectedComponentLabeling = new ConnectedComponentLabeling(canvasPixels, 0.0);

foreach (ConnectedComponent connectedComponent in inkCanvas.ConnectedComponentLabeling.ConnectedComponents)
{
MinimumBoundingRectangle mbr = connectedComponent.MinBoundingRect;
Rectangle rectangle = new Rectangle()
{
Stroke = new SolidColorBrush(Colors.Blue),
StrokeThickness = inkCanvas.StrokeThickness / 2,
Width = mbr.Width,
Height = mbr.Height,
Margin = new Thickness() { Top = mbr.Top, Left = mbr.Left }
};
inkCanvas.Children.Add(rectangle);

byte[] orgBytes = new byte[(int)(mbr.Width * mbr.Height)];
byte[] scaBytes = new byte[(int)Math.Pow(mbr.Size, 2)];
for (int y = 0; y < mbr.Height; y++)
{
for (int x = 0; x < mbr.Width; x++)
{
if (connectedComponent.Points.Exists(p => p.X == mbr.Left + x && p.Y == mbr.Top + y))
{
double row = (mbr.Top + y) * canvasWidth;
double col = mbr.Left + x;
byte val = canvasBytes[(int)(row + col)];

int orgIdx = (int)(y * mbr.Width) + x;
orgBytes[orgIdx] = val;

int scaIdx = (int)(((y + mbr.PadTop) * mbr.Size) + (x + mbr.PadLeft));
scaBytes[scaIdx] = val;
}
}
}

byte[] orgRGBABytes = ImageHelperRT.GetRGBAByteArrayFromByteArrayAsync(orgBytes, Colors.Black);
await ImageHelperRT.SaveRGBAByteArrayAsBitmapImageAsync(orgRGBABytes, mbr.Width, mbr.Height, inkCanvas.Name + "_org");
connectedComponent.Pixels = await ImageHelperRT.Get2DPixelArrayFromByteArrayAsync(orgBytes, mbr.Width, mbr.Height);

byte[] scaRGBABytes = ImageHelperRT.GetRGBAByteArrayFromByteArrayAsync(scaBytes, Colors.Black);
scaRGBABytes = await ImageHelperRT.ScaleRGBAByteArrayAsync(scaRGBABytes, mbr.Size, mbr.Size, ImageHelperRT.ImageWidth, ImageHelperRT.ImageHeight);
scaBytes = await ImageHelperRT.GetByteArrayFromRGBAByteArrayAsync(scaRGBABytes, inkCanvas.ForegroundColor);
await ImageHelperRT.SaveRGBAByteArrayAsBitmapImageAsync(scaRGBABytes, ImageHelperRT.ImageWidth, ImageHelperRT.ImageHeight, inkCanvas.Name + "_sca");
connectedComponent.ScaledPixels = await ImageHelperRT.Get2DPixelArrayFromByteArrayAsync(scaBytes, ImageHelperRT.ImageWidth, ImageHelperRT.ImageHeight);
}
}
}
}
}
102 changes: 0 additions & 102 deletions NumberRecognizer/NumberRecognizer.App/View/GroupDetailPage.xaml

This file was deleted.

Loading

0 comments on commit 8d4a9e3

Please sign in to comment.