aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.BL
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-04-02 11:58:55 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-04-02 11:58:55 +0300
commit1eb4e2409abbcffdab96b5e896cf71850ab13a01 (patch)
tree51b3a09c95c040ce864ccf4920a0b4696108da41 /Software/Visual_Studio/TCC/Tango.TCC.BL
parent05baf6a0dda66fdc1b66d3f769e709f88b540e1d (diff)
downloadTango-1eb4e2409abbcffdab96b5e896cf71850ab13a01.tar.gz
Tango-1eb4e2409abbcffdab96b5e896cf71850ab13a01.zip
Working on color capture module...
Diffstat (limited to 'Software/Visual_Studio/TCC/Tango.TCC.BL')
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetectionConfig.cs30
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetector.cs38
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.BL/ColorDetector.cs19
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.BL/TCC/benchmarks_rgb_lab.csv111
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.BL/Tango.TCC.BL.csproj12
5 files changed, 202 insertions, 8 deletions
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetectionConfig.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetectionConfig.cs
new file mode 100644
index 000000000..84acbd777
--- /dev/null
+++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetectionConfig.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PMR.TCC;
+
+namespace Tango.TCC.BL
+{
+ public class CardDetectionConfig
+ {
+ public List<DetectionBenchmark> Benchmarks { get; set; }
+ public int DesiredBitmapWidth { get; set; }
+ public int DesiredBitmapHeight { get; set; }
+ public int Columns { get; set; }
+ public int Rows { get; set; }
+ public int TargetIndex { get; set; }
+ public byte[] TemplateBitmapBytes { get; set; }
+
+ public CardDetectionConfig()
+ {
+ DesiredBitmapWidth = 300;
+ DesiredBitmapHeight = 310;
+ Columns = 10;
+ Rows = 11;
+ TargetIndex = 89;
+ Benchmarks = new List<DetectionBenchmark>();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetector.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetector.cs
index d10e99b81..5971b4be1 100644
--- a/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetector.cs
+++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/CardDetector.cs
@@ -1,11 +1,13 @@
using Google.Protobuf;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+using Tango.Core.Helpers;
using Tango.PMR.TCC;
namespace Tango.TCC.BL
@@ -13,6 +15,8 @@ namespace Tango.TCC.BL
public class CardDetector
{
private ColorDetector _colorDetector;
+ private static byte[] _defaultTemplate;
+ private static List<DetectionBenchmark> _defaultBenchmarks;
private bool _canDetect;
public bool CanDetect
@@ -23,11 +27,17 @@ namespace Tango.TCC.BL
public CardDetector()
{
+ if (_defaultTemplate == null)
+ {
+ _defaultTemplate = File.ReadAllBytes(AssemblyHelper.GetCurrentAssemblyFolder() + "\\TCC\\template.bmp");
+ _defaultBenchmarks = ColorDetector.LoadBenchmarks(AssemblyHelper.GetCurrentAssemblyFolder() + "\\TCC\\benchmarks_rgb_lab.csv").ToList();
+ }
+
CanDetect = true;
_colorDetector = new ColorDetector();
}
- public Task<CardDetectionResult> Detect(BitmapSource source)
+ public Task<CardDetectionResult> Detect(BitmapSource source, CardDetectionConfig config)
{
if (!CanDetect)
{
@@ -46,8 +56,9 @@ namespace Tango.TCC.BL
Tango.TCC.CardDetector.CardDetection detector = new TCC.CardDetector.CardDetection();
var result = detector.Detect(cloned.ToBytes(PixelFormats.Rgb24), new TCC.CardDetector.CardDetectionConfig()
{
- DesiredBitmapWidth = 300,
- DesiredBitmapHeight = 310,
+ DesiredBitmapWidth = config.DesiredBitmapWidth,
+ DesiredBitmapHeight = config.DesiredBitmapHeight,
+ TemplateBitmap = config.TemplateBitmapBytes != null ? config.TemplateBitmapBytes : _defaultTemplate.ToArray(),
});
if (result.IsDetected)
@@ -55,14 +66,25 @@ namespace Tango.TCC.BL
detectionResult.IsDetected = true;
detectionResult.DetectedBitmap = result.DetectedBitmap.ToBitmapSource();
- detectionResult.ColorDetectionOutput = _colorDetector.Detect(new DetectionInput()
+ var input = new DetectionInput()
{
Bitmap = ByteString.CopyFrom(detectionResult.DetectedBitmap.ToBmpBytes()),
- Columns = 10,
- Rows = 11,
- TargetIndex = 89,
+ Columns = config.Columns,
+ Rows = config.Rows,
+ TargetIndex = config.TargetIndex,
RequestColorMatrix = true,
- });
+ };
+
+ if (config.Benchmarks.Count > 0)
+ {
+ input.Benchmarks.AddRange(config.Benchmarks);
+ }
+ else
+ {
+ input.Benchmarks.AddRange(_defaultBenchmarks);
+ }
+
+ detectionResult.ColorDetectionOutput = _colorDetector.Detect(input);
}
CanDetect = true;
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/ColorDetector.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/ColorDetector.cs
index e3c80cb20..a41124c42 100644
--- a/Software/Visual_Studio/TCC/Tango.TCC.BL/ColorDetector.cs
+++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/ColorDetector.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Web.Hosting;
using Tango.Core.Helpers;
+using Tango.CSV;
using Tango.PMR;
using Tango.PMR.TCC;
@@ -152,6 +153,24 @@ namespace Tango.TCC.BL
return index == 1 || index == columns || index == columns * rows || index == (columns * rows) - columns + 1;
}
+ public static IEnumerable<DetectionBenchmark> LoadBenchmarks(String file)
+ {
+ var benchmarks = CsvFile.Read<DetectionBenchmark>(new CsvSource(file)).ToList();
+ return benchmarks;
+ }
+
+ public static void SaveBenchmarks(String file,IEnumerable<DetectionBenchmark> benchmarks)
+ {
+ CsvFile<DetectionBenchmark> csvFile = new CsvFile<DetectionBenchmark>(new CsvDestination(file));
+
+ foreach (var item in benchmarks)
+ {
+ csvFile.Append(item);
+ }
+
+ csvFile.Dispose();
+ }
+
public void Dispose()
{
if (!_isDisposed)
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/TCC/benchmarks_rgb_lab.csv b/Software/Visual_Studio/TCC/Tango.TCC.BL/TCC/benchmarks_rgb_lab.csv
new file mode 100644
index 000000000..141397cd4
--- /dev/null
+++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/TCC/benchmarks_rgb_lab.csv
@@ -0,0 +1,111 @@
+Red,Green,Blue,L,A,B
+0,0,0,0,0,0
+169,169,169,71.12,0.133333333,-0.051666667
+112,112,112,52.7025,-1.2625,0.225
+198,198,198,79.77166667,0.398333333,-1.038333333
+83,83,83,42.17166667,-1.261666667,-0.135
+226,226,226,87.19833333,0.988333333,-2.736666667
+54,54,54,33.112,-1.636,1.224
+255,255,255,94.06833333,1.695,-4.553333333
+26,26,26,24.80833333,-1.2,1.33
+0,0,0,0,0,0
+26,26,26,24.05,-1.5425,1.7175
+179,45,131,46.21333333,53.01666667,-15.06166667
+237,72,35,55.83,49.84666667,47.51333333
+54,70,61,36.79333333,-7.683333333,4.253333333
+38,58,111,30.57833333,8.741666667,-28.87166667
+212,132,66,63.97,19.78,39.89666667
+72,107,66,45.735,-19.39833333,17.27666667
+142,76,97,46.27333333,27.43,-0.658333333
+97,95,162,46.68166667,15.74333333,-30.815
+140,140,140,61.34833333,1.033333333,-0.151666667
+255,255,255,93.77333333,1.765,-4.411666667
+158,154,201,67.955,11.27333333,-20.06
+255,236,0,87.50166667,-12.59166667,78.655
+255,182,4,75.95833333,9.428333333,67.96333333
+243,107,33,61.09,39,52.50833333
+235,35,65,51.09833333,62.24166667,27.82333333
+106,55,134,36.80166667,32.49333333,-30.18666667
+255,185,59,76.87166667,9.426666667,57.305
+243,157,192,74.25,30.54,-7.908333333
+169,169,169,70.22333333,0.92,0.1
+54,54,54,30.775,-0.525,0.32
+116,59,54,39.87,20.87,12.47
+65,108,99,47.85833333,-15.3,1.538333333
+140,76,119,46.595,29.31666667,-10.93333333
+53,59,81,32.97333333,2.943333333,-12.37833333
+138,75,128,46.22333333,30.45666667,-15.91666667
+137,180,113,68.87833333,-23.25666667,27.84333333
+0,158,179,61.18,-20.86,-16.83833333
+113,207,244,78.175,-12.04333333,-22.53833333
+112,112,112,51.61,-0.502,-0.136
+226,226,226,87.13333333,1.495,-3.138333333
+184,50,46,45.52833333,42.72833333,29.61
+238,99,157,62.11,50.415,-7.06
+42,86,65,39.50666667,-17.82333333,8.103333333
+90,176,65,63.03166667,-42.46666667,43.37333333
+233,34,35,50.54666667,60.89166667,42.66
+190,230,250,86.84666667,-4.345,-12.96333333
+17,57,134,32.005,14.47333333,-34.95666667
+0,162,227,63.635,-10.44333333,-33.42166667
+198,198,198,79.01,1.025,-0.918333333
+83,83,83,42.464,-1.92,0.73
+0,172,198,64.285,-21.78166667,-20.35333333
+255,249,205,92.19333333,-3.3,13.94333333
+142,153,81,63.36833333,-13.99,33.38
+230,136,63,66.125,23.97666667,44.36833333
+141,76,111,45.82333333,28.36666667,-7.24
+231,22,127,52.11333333,66.82,-3.993333333
+190,157,147,68.685,10.07166667,7.398333333
+81,180,118,65.39166667,-38.2,21.53333333
+83,83,83,40.794,-0.94,-0.32
+198,198,198,79.14666667,0.791666667,-1.766666667
+234,31,101,52.21833333,64.01666667,8.343333333
+255,203,59,81.59333333,1.206666667,60.66833333
+252,173,144,76.00166667,19.22,17.49833333
+237,73,123,58.05833333,54.47333333,3.016666667
+206,138,159,66.82333333,23.78333333,-2.453333333
+143,76,82,45.865,25.65,7.266666667
+0,129,159,52.54833333,-15.35166667,-20.88666667
+0,130,198,54.21666667,-3.341666667,-36.37833333
+226,226,226,86.78666667,1.36,-2.605
+112,112,112,51.81,-0.583333333,-0.52
+0,152,77,56.07833333,-46.975,31.68
+0,164,72,58.71666667,-49.065,37.25166667
+137,75,137,45.86333333,31.94666667,-19.99
+167,210,173,79.54,-16.565,10.95166667
+59,109,116,47.90833333,-11.37166667,-8.108333333
+141,166,82,66.06833333,-20.29,37.86166667
+186,134,159,63.88,20.75166667,-5.778333333
+202,209,33,78.01833333,-18.415,67.03833333
+54,54,54,32.25,-1.4925,1.52
+169,169,169,71.545,-0.0625,-0.33
+244,110,79,62.268,39.444,32.43
+140,178,84,68.00333333,-25.05166667,39.31166667
+131,124,169,57.03833333,10.89833333,-19.545
+255,240,90,88.664,-11.328,60.484
+35,110,154,47.93333333,-5.69,-27.08833333
+0,125,73,48.08833333,-39.07333333,20.28
+0,86,159,38.855,7.425,-39.47166667
+138,190,85,69.98666667,-29.77333333,41.79833333
+255,255,255,93.715,1.663333333,-4.443333333
+140,140,140,61.934,-0.202,-0.038
+249,207,225,85.474,13.868,-6.676
+0,155,119,57.845,-37.60333333,9.745
+93,167,88,61.77166667,-35.645,29.3
+245,234,143,88.21833333,-8.618333333,37.94666667
+0,183,236,68.89666667,-15.51,-31.53166667
+81,60,92,34.46833333,13.13166667,-14.09
+255,245,153,90.20666667,-7.895,34.44333333
+70,108,81,46.88666667,-18.28333333,11.555
+26,26,26,23.2425,-0.405,0.9525
+0,0,0,0,0,0
+255,255,255,94.11333333,1.658333333,-4.575
+54,54,54,32.195,-1.735,1.2575
+226,226,226,86.62833333,1.258333333,-2.736666667
+83,83,83,40.4025,-0.7875,-1.06
+198,198,198,79.255,1.036666667,-1.23
+112,112,112,51.55,-0.24,-1.1725
+169,169,169,70.695,0.278333333,-0.368333333
+140,140,140,61.43833333,0.363333333,-0.338333333
+0,0,0,0,0,0
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/Tango.TCC.BL.csproj b/Software/Visual_Studio/TCC/Tango.TCC.BL/Tango.TCC.BL.csproj
index bb82e8c5d..df87e66b8 100644
--- a/Software/Visual_Studio/TCC/Tango.TCC.BL/Tango.TCC.BL.csproj
+++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/Tango.TCC.BL.csproj
@@ -51,6 +51,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="CardDetectionConfig.cs" />
<Compile Include="CardDetectionResult.cs" />
<Compile Include="CardDetector.cs" />
<Compile Include="ColorDetector.cs" />
@@ -60,12 +61,19 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="TCC\benchmarks_rgb_lab.csv">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj">
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Tango.CSV\Tango.CSV.csproj">
+ <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project>
+ <Name>Tango.CSV</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\Tango.PMR\Tango.PMR.csproj">
<Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project>
<Name>Tango.PMR</Name>
@@ -96,6 +104,10 @@
<Link>Tango.TCC.LoadTestLib.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="..\Images\template.bmp">
+ <Link>TCC\template.bmp</Link>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>