aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-03-26 12:54:09 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-03-26 12:54:09 +0200
commit7dbd32ddcf6611dec88ef56336b364110b019571 (patch)
tree9cb2ed657787d907b6bbd7695aafa244bba886ee /Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
parent0aaf60dbc0322abc6707b5cf057d797fc26a1734 (diff)
downloadTango-7dbd32ddcf6611dec88ef56336b364110b019571.tar.gz
Tango-7dbd32ddcf6611dec88ef56336b364110b019571.zip
A lot of work !!!!
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
new file mode 100644
index 000000000..a96328e8b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
@@ -0,0 +1,81 @@
+using Google.Protobuf;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.IO;
+using Tango.PMR.TCC;
+using Tango.TCC.BL;
+
+namespace Tango.UnitTesting.TCC
+{
+ [TestClass]
+ [TestCategory("TCC")]
+ public class TCC_TST
+ {
+ [TestMethod]
+ public void Detect()
+ {
+ var original_bitmap = Directory.GetCurrentDirectory() + "\\TCC\\TCC Resources\\bitmap.bmp";
+
+ using (ColorDetector detector = new ColorDetector())
+ {
+ DetectionInput input = new DetectionInput()
+ {
+ Number = 10,
+ Columns = 10,
+ Rows = 11,
+ TargetIndex = 99,
+ Bitmap = ByteString.CopyFrom(File.ReadAllBytes(original_bitmap)),
+ DebugMode = true,
+ };
+
+ var output = detector.Detect(input);
+
+ using (MemoryStream ms = new MemoryStream(output.DebugBitmap.ToArray()))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ ms.Position = 0;
+ Bitmap bmp = new Bitmap(ms);
+ bmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+
+ using (Bitmap colorMatrixBmp = ColorDetector.DetectionOutputToImage(input, output, 300, 320))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ colorMatrixBmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+
+ Assert.IsTrue(output.Number == 20);
+ }
+ }
+
+ private byte[] GetBitmapData(byte[] bitmap)
+ {
+ using (MemoryStream ms = new MemoryStream(bitmap))
+ {
+ ms.Position = 0;
+ Bitmap image = new Bitmap(ms);
+ Rectangle area = new Rectangle(0, 0, image.Width, image.Height);
+ BitmapData bitmapData = image.LockBits(area, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
+ int stride = bitmapData.Stride;
+ IntPtr ptr = bitmapData.Scan0;
+ int numBytes = bitmapData.Stride * image.Height;
+ byte[] rgbValues = new byte[numBytes];
+ Marshal.Copy(ptr, rgbValues, 0, numBytes);
+ return rgbValues;
+ }
+ }
+ }
+}