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

Commit

Permalink
Merge pull request #2 from TheSwerik/SaveResults
Browse files Browse the repository at this point in the history
Save results & Cleanup UI
  • Loading branch information
TheSwerik authored May 8, 2020
2 parents a12043c + 9585e67 commit 67e6ec0
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Inno Config.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Variables:
#define MyAppName "RedEye"
#define MyAppVersion "1.2.0"
#define MyAppVersion "1.3.0"
#define MyAppPublisher "Swerik"
#define MyAppURL "https://github.com/TheSwerik/RedEye"
#define MyAppExeName "RedEye.exe"
Expand Down
5 changes: 5 additions & 0 deletions RedEye.Backend/src/Util/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Emgu.CV.Cuda;
using Microsoft.VisualBasic.FileIO;

Expand All @@ -23,6 +24,10 @@ static Config()
}

IsCudaEnabled = GetBool("Cuda") && CudaInvoke.HasCuda;

if (Get("ScreenshotLocation").ToLowerInvariant().Contains("default"))
Set("ScreenshotLocation", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\RedEye Screenshots");
Directory.CreateDirectory(Get("ScreenshotLocation"));
}

public static void Set(string setting, string value)
Expand Down
1 change: 1 addition & 0 deletions RedEye.UI/RedEye.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<AssemblyName>RedEye</AssemblyName>
<ProjectGuid>{C3591D81-347D-4F3E-B3F2-7FD71441E0CA}</ProjectGuid>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion RedEye.UI/src/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RedEye"
StartupUri="src/MainWindow.xaml">
StartupUri="MainWindow.xaml">
<Application.Resources>

<local:BoolToGridRowHeightConverter x:Key="BoolToGridRowHeightConverter" />
</Application.Resources>
</Application>
21 changes: 21 additions & 0 deletions RedEye.UI/src/BoolToGridRowHeightConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace RedEye
{
[ValueConversion(typeof(bool), typeof(GridLength))]
public class BoolToGridRowHeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((bool)value == true) ? new GridLength(1, GridUnitType.Star) : new GridLength(0);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ // Don't need any convert back
return null!;
}
}
}
15 changes: 10 additions & 5 deletions RedEye.UI/src/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RedEye"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Closed="Window_OnClosed" SizeChanged="Window_OnSizeChanged">
Title="RedEye" Height="450" Width="800" Closed="Window_OnClosed" SizeChanged="Window_OnSizeChanged"
d:DataContext="{d:DesignInstance }">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
Expand All @@ -15,8 +16,9 @@
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" x:Name="DeviceComboRow" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" x:Name="NextButtonRow" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1.25*" />
</Grid.RowDefinitions>
Expand All @@ -31,14 +33,17 @@
<RadioButton Grid.Column="2" Content="Camera" x:Name="RadioButtonCam" Checked="RadioButtonCamera_OnChecked" />
</Grid>

<ComboBox Grid.Column="1" Grid.Row="2" Text="Device:" x:Name="DeviceBox" SelectionChanged="DeviceBox_OnSelectionChanged" />
<ComboBox Grid.Column="1" Grid.Row="2" Text="Device:" x:Name="DeviceBox"
SelectionChanged="DeviceBox_OnSelectionChanged" />

<Canvas Grid.Column="1" Grid.Row="3" x:Name="MainCanvas" IsHitTestVisible="False"
Width="{Binding ActualWidth, ElementName=Pic, Mode=OneWay}" ClipToBounds="True">
<Canvas Grid.Column="1" Grid.Row="3" x:Name="MainCanvas" IsHitTestVisible="False" ClipToBounds="True"
Width="{Binding ActualWidth, ElementName=Pic, Mode=OneWay}">
<Image x:Name="Pic" RenderOptions.BitmapScalingMode="Fant"
Height="{Binding ActualHeight, ElementName=MainCanvas, Mode=OneWay}" />
</Canvas>

<Button Grid.Column="1" Grid.Row="4" Content="Next" x:Name="NextButton" Click="NextButton_OnClick" />

<Button Grid.Column="1" Grid.Row="5" Content="Save" x:Name="SaveButton" Click="SaveButton_OnClick" />
</Grid>
</Window>
41 changes: 41 additions & 0 deletions RedEye.UI/src/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Emgu.CV;
using Emgu.CV.Cuda;
Expand Down Expand Up @@ -59,6 +62,8 @@ private void RadioButtonCamera_OnChecked(object sender, RoutedEventArgs e)
DeviceBox_OnSelectionChanged(null, null);
NextButton.Visibility = Visibility.Hidden;
DeviceBox.Visibility = Visibility.Visible;
NextButtonRow.Height = new GridLength(0);
DeviceComboRow.Height = GridLength.Auto;
}

private void DeviceBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs? e)
Expand All @@ -81,6 +86,8 @@ private void Window_OnSizeChanged(object sender, SizeChangedEventArgs e)
);
}

private void SaveButton_OnClick(object sender, RoutedEventArgs e) => Dispatcher.BeginInvoke((Action) SavePNG, DispatcherPriority.ContextIdle);

// Helper Methods:
private void ClearCanvas()
{
Expand Down Expand Up @@ -130,12 +137,46 @@ private void SwitchToImage()
NextButton_OnClick(null, null);
NextButton.Visibility = Visibility.Visible;
DeviceBox.Visibility = Visibility.Hidden;
DeviceComboRow.Height = new GridLength(0);
NextButtonRow.Height = GridLength.Auto;
}

private void DetectAsync()
{
if (!Config.IsCudaEnabled) DrawDetection(new Mat(_images.CurrentImagePath()).ToImage<Gray, byte>());
else DrawDetection(new GpuMat(new Mat(_images.CurrentImagePath()).ToImage<Gray, byte>()));
}

private void SavePNG()
{
var bounds = VisualTreeHelper.GetDescendantBounds(MainCanvas);
var rtb = new RenderTargetBitmap((int) bounds.Width, (int) bounds.Height, 96d, 96d, PixelFormats.Default);

DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(MainCanvas);
dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}

rtb.Render(dv);
var pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(rtb));

try
{
var ms = new MemoryStream();
pngEncoder.Save(ms);
ms.Close();
File.WriteAllBytes(
Config.Get("ScreenshotLocation") + $@"\RedEye {DateTime.Now:yyyy-MM-dd hh-mm-ss}.png",
ms.ToArray());
}
catch (Exception err)
{
const string message = "Failed to Save Image:\n";
MessageBox.Show(message + err.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
my_version_number: 1.2.0 # DONT FORGET TO CHANGE IS IN THE ISS FILE
my_version_number: 1.3.0 # DONT FORGET TO CHANGE IS IN THE ISS FILE
application_name: RedEye # DONT FORGET TO CHANGE IS IN THE ISS FILE
project_name: RedEye.UI

Expand Down
7 changes: 4 additions & 3 deletions assets/config.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
StartWithCamera: true
EyeImageVerticalOffset: 2
EyeImageVerticalOffset: 4
DetectionFrequency: 20
Neighbors: 2
PickAverage: false
Cuda: false
DrawRectangles: false
Neighbors: 1
Cuda: false
ScreenshotLocation: default

0 comments on commit 67e6ec0

Please sign in to comment.