From f82ae06fbae6d69ea493906feb5ac13b57472b9d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Fri, 10 May 2019 14:50:37 +0300 Subject: MERGE --- .../Properties/Resources.Designer.cs | 45 +- .../Properties/Resources.resx | 26 +- .../Tango.MachineStudio.ColorCapture.csproj | 3 + .../ViewModels/MainViewVM.cs | 127 +++- .../Views/MainView.xaml | 712 ++++++++++++--------- 5 files changed, 586 insertions(+), 327 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.Designer.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.Designer.cs index 80918eb2e..c401c2134 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.Designer.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.Designer.cs @@ -9,6 +9,7 @@ //------------------------------------------------------------------------------ namespace Tango.MachineStudio.ColorCapture.Properties { + using System; /// @@ -18,7 +19,7 @@ namespace Tango.MachineStudio.ColorCapture.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -37,7 +38,7 @@ namespace Tango.MachineStudio.ColorCapture.Properties { [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { - if ((resourceMan == null)) { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.MachineStudio.ColorCapture.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } @@ -58,5 +59,45 @@ namespace Tango.MachineStudio.ColorCapture.Properties { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap bottomLeft { + get { + object obj = ResourceManager.GetObject("bottomLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap bottomRight { + get { + object obj = ResourceManager.GetObject("bottomRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap topleft { + get { + object obj = ResourceManager.GetObject("topleft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap topRight { + get { + object obj = ResourceManager.GetObject("topRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.resx b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.resx index af7dbebba..2803cb5b3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.resx +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,22 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Images\bottomLeft.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Images\bottomRight.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Images\topleft.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Images\topRight.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj index 9f21cadf2..a38db1b53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj @@ -207,5 +207,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs index 31eec0871..2f8d421cd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs @@ -117,7 +117,14 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels public ObservableCollection Benchmarks { get { return _benchmarks; } - set { _benchmarks = value; RaisePropertyChangedAuto(); } + set { _benchmarks = value; RaisePropertyChangedAuto(); OnBenchmarksChanged(); } + } + + private ObservableCollection emulatedColors; + public ObservableCollection EmulatedColors + { + get { return emulatedColors; } + set { emulatedColors = value; RaisePropertyChangedAuto(); } } private CaptureConfig _config; @@ -148,6 +155,33 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels set { _barcode = value; RaisePropertyChangedAuto(); } } + private bool _isEmulated; + public bool IsEmulated + { + get { return _isEmulated; } + set { _isEmulated = value; RaisePropertyChangedAuto(); } + } + + private int emulatedR; + public int EmulatedR + { + get { return emulatedR; } + set { emulatedR = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private int emulatedG; + public int EmulatedG + { + get { return emulatedG; } + set { emulatedG = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private int emulatedB; + public int EmulatedB + { + get { return emulatedB; } + set { emulatedB = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } public RelayCommand ImportBenchmarksCommand { get; set; } @@ -163,6 +197,10 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels public RelayCommand SelectTemplateFileCommand { get; set; } + public RelayCommand LiveCommand { get; set; } + + public RelayCommand EmulatedCommand { get; set; } + public MainViewVM() { Config = new CaptureConfig(); @@ -185,6 +223,8 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels SelectSamplesFolderCommand = new RelayCommand(SelectSamplesFolder); SelectBenchmarksFileCommand = new RelayCommand(SelectBenchmarkFile); SelectTemplateFileCommand = new RelayCommand(SelectTemplateFile); + LiveCommand = new RelayCommand(() => IsEmulated = false); + EmulatedCommand = new RelayCommand(() => IsEmulated = true); } public MainViewVM(IVideoCaptureProvider videoProvider, INotificationProvider notificationProvider) : this() @@ -403,13 +443,18 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels } } - private async void OnVideoFrameReceived(object sender, Video.DirectShow.EventArguments.FrameReceivedEventArgs args) + private void OnVideoFrameReceived(object sender, Video.DirectShow.EventArguments.FrameReceivedEventArgs args) { - if (_abort || IsPaused) return; + if (_abort || IsPaused || IsEmulated) return; + PerformDetection(args.BitmapSource); + } + + private async void PerformDetection(BitmapSource source) + { if (_cardDetector.CanDetect) { - var result = await _cardDetector.Detect(args.BitmapSource, new CardDetectionConfig() + var result = await _cardDetector.Detect(source, new CardDetectionConfig() { Benchmarks = Benchmarks.ToList().Select(x => x.ToDetectionBenchmark()).ToList(), Columns = Config.Columns, @@ -539,5 +584,79 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels return _deltaEComparison; } + + private void OnBenchmarksChanged() + { + EmulatedColors = new ObservableCollection(); + + if (Benchmarks != null) + { + foreach (var mark in Benchmarks) + { + EmulatedColors.Add(Color.FromRgb((byte)mark.Red, (byte)mark.Green, (byte)mark.Blue)); + } + + OnEmulatedColorChanged(); + } + } + + private void OnEmulatedColorChanged() + { + if (EmulatedColors != null && EmulatedColors.Count > Config.TargetIndex) + { + Color color = Color.FromRgb((byte)EmulatedR, (byte)EmulatedG, (byte)EmulatedB); + EmulatedColors[Config.TargetIndex] = color; + + if (IsEmulated) + { + DetectionOutput output = new DetectionOutput(); + output.ColorMatrix.AddRange(EmulatedColors.Select(x => new DetectionColor() + { + R = x.R, + G = x.G, + B = x.B, + })); + output.ProcessedColor = new DetectionColor() + { + R = EmulatedR, + G = EmulatedG, + B = EmulatedB, + }; + + var bitmap = ColorDetector.DetectionOutputToImage(new DetectionInput() + { + Columns = Config.Columns, + Rows = Config.Rows, + TargetIndex = Config.TargetIndex + + }, output, Config.SampleWidth, Config.SampleHeight, true, true, false); + + float rectWidth = (bitmap.Width / Config.Columns) - 4; + float rectHeight = (bitmap.Height / Config.Rows) - 4; + + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) + { + g.DrawImage(Properties.Resources.topleft, new System.Drawing.RectangleF(0, 0, rectWidth, rectHeight)); + g.DrawImage(Properties.Resources.topRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, 0, rectWidth, rectHeight)); + + g.DrawImage(Properties.Resources.bottomLeft, new System.Drawing.RectangleF(0, bitmap.Height - rectHeight, rectWidth, rectHeight)); + g.DrawImage(Properties.Resources.bottomRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, bitmap.Height - rectHeight, rectWidth, rectHeight)); + } + + var bitmapContainer = new System.Drawing.Bitmap(640, 480); + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapContainer)) + { + g.Clear(System.Drawing.Color.White); + g.DrawImageUnscaled(bitmap, (bitmapContainer.Width / 2) - bitmap.Width / 2, (bitmapContainer.Height / 2) - bitmap.Height / 2); + } + + bitmap.Dispose(); + + PerformDetection(bitmapContainer.ToBitmapSource()); + + bitmapContainer.Dispose(); + } + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml index afdac7e18..616bdcfed 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml @@ -68,106 +68,150 @@ + - - - - - - - - - + + + + + + + + + + - - - - - Capture Device - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - Similarity - - + + + + + + + + + + R + + + + + G + + + + + B + + + + + + + + + + + + + + Similarity + + - - - - - - - - - - - - - - - - - Rectified Image - - - - - Calculated Averages - - - + + + - - - - - + + + + + + + + + + + + Rectified Image + + + - - - Captured Color - - - - - - - - - - - - - - - + Calculated Averages + + + - - - Processed Color - - - - - - - - - - - - - - - - - - Barcode: - - - + + + + + - - Delta E Reference Point - + - L: - + Captured Color + + + + + + + + + + + + + + + + - A: - + Processed Color + + + + + + + + + + + + + + - - B: - - - - + + Barcode: + + + + + + Delta E Reference Point + + + L: + + + + + A: + + + + + B: + + + + + - - - - - - - - - - - Snapshots - + + + + + + + + + + Snapshots + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Delta E Distance - + + + Delta E Distance + ( ) - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.3.1