From 08dd6000fe3a218221003876a699f448835b62e4 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 8 Apr 2019 00:44:51 +0300 Subject: Working on TCC... --- .../Models/CaptureConfig.cs | 41 ++++ .../Models/DeltaEComparisons.cs | 16 ++ .../Tango.MachineStudio.ColorCapture.csproj | 5 + .../ViewModels/MainViewVM.cs | 103 +++++++++- .../Views/MainView.xaml | 226 ++++++++++++++++----- 5 files changed, 336 insertions(+), 55 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/DeltaEComparisons.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/CaptureConfig.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/CaptureConfig.cs index c1f5d4f48..9f54837cb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/CaptureConfig.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/CaptureConfig.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Helpers; +using Tango.TCC.BL; namespace Tango.MachineStudio.ColorCapture.Models { @@ -67,6 +68,42 @@ namespace Tango.MachineStudio.ColorCapture.Models set { _sampleHeight = value; RaisePropertyChangedAuto(); } } + private bool _autoRelease; + public bool AutoRelease + { + get { return _autoRelease; } + set { _autoRelease = value; RaisePropertyChangedAuto(); } + } + + private double _similarityTolerance; + public double SimilarityTolerance + { + get { return _similarityTolerance; } + set { _similarityTolerance = value; RaisePropertyChangedAuto(); } + } + + private DeltaEComparisons _deltaEComparison; + public DeltaEComparisons DeltaEComparison + { + get { return _deltaEComparison; } + set { _deltaEComparison = value; RaisePropertyChangedAuto(); } + } + + private CardDetectionHistogramMethods _histogramComparison; + public CardDetectionHistogramMethods HistogramComparison + { + get { return _histogramComparison; } + set { _histogramComparison = value; RaisePropertyChangedAuto(); } + } + + private bool _enableDoubleChecking; + public bool EnableDoubleChecking + { + get { return _enableDoubleChecking; } + set { _enableDoubleChecking = value; RaisePropertyChangedAuto(); } + } + + public CaptureConfig() { Columns = 10; @@ -74,9 +111,13 @@ namespace Tango.MachineStudio.ColorCapture.Models TargetIndex = 89; SampleWidth = 300; SampleHeight = 330; + SimilarityTolerance = 50; SamplesFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "TCC Samples"); BenchmarksFile = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "TCC", "benchmarks_rgb_lab.csv"); TemplateFile = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "TCC", "template.bmp"); + DeltaEComparison = DeltaEComparisons.CieDe2000; + HistogramComparison = CardDetectionHistogramMethods.Chi_Square; + EnableDoubleChecking = true; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/DeltaEComparisons.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/DeltaEComparisons.cs new file mode 100644 index 000000000..8f3ab87c8 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Models/DeltaEComparisons.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.ColorCapture.Models +{ + public enum DeltaEComparisons + { + Cie1976, + Cie94, + CieDe2000, + Cmc + } +} 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 1679f2af9..c30520f13 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 @@ -104,6 +104,7 @@ + Code @@ -150,6 +151,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {6efd5895-177b-4bbb-af52-29f4d53b3fbd} + Tango.CircularGauge + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core 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 5b9d20bc4..21bb0baf0 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 @@ -37,6 +37,8 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels private BitmapSource _last_original_source; private DetectionOutput _last_detection_output; private byte[] templateBitmap; + private DeltaEComparisons _lastDeltaEComparison; + private IColorSpaceComparison _deltaEComparison; public IVideoCaptureProvider VideoProvider { get; set; } @@ -124,6 +126,20 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels set { _config = value; RaisePropertyChangedAuto(); } } + private bool _isPaused; + public bool IsPaused + { + get { return _isPaused; } + set { _isPaused = value; RaisePropertyChangedAuto(); } + } + + private double _similarity; + public double Similarity + { + get { return _similarity; } + set { _similarity = value; RaisePropertyChangedAuto(); } + } + public RelayCommand ImportBenchmarksCommand { get; set; } public RelayCommand ExportBenchmarksCommand { get; set; } @@ -233,6 +249,19 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels var rgb = new Lab(MeasureL, _measureA, _measureB).ToRgb(); Color refColor = Color.FromArgb(255, (byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + CsvFile means_csv = new CsvFile(new CsvDestination(sample_folder + "\\means.csv")); + + foreach (var item in ColorDetector.EmptyColorMatrixFiducials(new DetectionInput() + { + Columns = Config.Columns, + Rows = Config.Rows, + }, _last_detection_output)) + { + means_csv.Append(item); + } + + means_csv.Dispose(); + var captureItem = new CaptureItem() { Image = rectified_file, @@ -250,6 +279,8 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels File.WriteAllText(capture_item_file, captureItem.ToJsonString()); CaptureItems.Insert(0, captureItem); + + Clear(); } catch (Exception ex) { @@ -313,13 +344,17 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels { if (SelectedVideoDevice.IsStarted) { - _abort = true; - SelectedVideoDevice.Stop(); - ProcessedColor = System.Windows.Media.Colors.Transparent; - CapturedColor = System.Windows.Media.Colors.Transparent; - Colors = null; - DetectedSource = null; - CaptureDeltaEController.Clear(); + if (!IsPaused) + { + _abort = true; + SelectedVideoDevice.Stop(); + Clear(); + } + else + { + IsPaused = false; + Clear(); + } } else { @@ -330,6 +365,16 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels } } + private void Clear() + { + ProcessedColor = System.Windows.Media.Colors.Transparent; + CapturedColor = System.Windows.Media.Colors.Transparent; + Colors = null; + DetectedSource = null; + CaptureDeltaEController.Clear(); + Similarity = 0; + } + private void OnSelectedVideoDeviceChanged(CaptureDevice previousDevice, CaptureDevice newDevice) { if (previousDevice != null) @@ -346,7 +391,7 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels private async void OnVideoFrameReceived(object sender, Video.DirectShow.EventArguments.FrameReceivedEventArgs args) { - if (_abort) return; + if (_abort || IsPaused) return; if (_cardDetector.CanDetect) { @@ -359,10 +404,23 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels DesiredBitmapHeight = Config.SampleHeight, TargetIndex = Config.TargetIndex, TemplateBitmapBytes = templateBitmap, + SimilarityTolerance = Config.SimilarityTolerance, + HistogramMethod = Config.HistogramComparison, + EnableDoubleChecking = Config.EnableDoubleChecking, }); + if (result.Similarity > 0) + { + Similarity = result.Similarity; + } + if (result.IsDetected) { + if (Config.AutoRelease) + { + IsPaused = true; + } + _last_original_source = result.Source; _last_detection_output = result.ColorDetectionOutput; @@ -386,7 +444,7 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels //calculate delta E. Lab measureLab = new Lab(MeasureL, MeasureA, MeasureB); - DeltaE = measureLab.Compare(new Rgb(ProcessedColor.R, ProcessedColor.G, ProcessedColor.B), new CieDe2000Comparison()); + DeltaE = measureLab.Compare(new Rgb(ProcessedColor.R, ProcessedColor.G, ProcessedColor.B), GetDeltaEComparison()); }); } } @@ -432,5 +490,32 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels SettingsManager.Default.GetOrCreate().Config = Config; SettingsManager.Default.Save(); } + + private IColorSpaceComparison GetDeltaEComparison() + { + if (_lastDeltaEComparison != Config.DeltaEComparison || _deltaEComparison == null) + { + _lastDeltaEComparison = Config.DeltaEComparison; + + if (Config.DeltaEComparison == DeltaEComparisons.Cie1976) + { + _deltaEComparison = new Cie1976Comparison(); + } + else if (Config.DeltaEComparison == DeltaEComparisons.Cie94) + { + _deltaEComparison = new Cie94Comparison(); + } + else if (Config.DeltaEComparison == DeltaEComparisons.CieDe2000) + { + _deltaEComparison = new CieDe2000Comparison(); + } + else if (Config.DeltaEComparison == DeltaEComparisons.Cmc) + { + _deltaEComparison = new CmcComparison(); + } + } + + return _deltaEComparison; + } } } 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 c1555fbcd..d6f4890d7 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 @@ -1,9 +1,11 @@  - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -62,6 +77,7 @@ + @@ -82,6 +98,22 @@ + + + + + + + + + + + + + + + + @@ -91,27 +123,94 @@ - - - - - + + + + + + + + + + + + + + + + + + + - + + + Similarity + + + + + + + + + @@ -206,6 +305,7 @@ + @@ -265,7 +365,7 @@ - + @@ -312,10 +412,17 @@ - - Delta E Distance + + + Delta E Distance + + ( + + ) + + - + @@ -358,7 +465,7 @@ - + @@ -454,23 +561,27 @@ - + - - - + + + - - - - - - - + + + + + + + - + + + + + Columns @@ -490,19 +601,42 @@ Samples Folder - + Benchmarks - + Template - + + + x + + + + + - + + + Similarity Tolerance + + + + Auto Release + + + Delta E Standard + + + Histogram Similarity + + + Double Checking + -- cgit v1.3.1