diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp | bin | 0 -> 140174 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs | 81 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj | 15 |
3 files changed, 95 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp Binary files differnew file mode 100644 index 000000000..1d48c010b --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp 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; + } + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index d1bba995e..b515ac420 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -102,6 +102,7 @@ <HintPath>..\packages\System.Data.SQLite.Linq.1.0.108.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath> <Private>True</Private> </Reference> + <Reference Include="System.Drawing" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> @@ -126,6 +127,7 @@ <Compile Include="RemoteRunner_TST.cs" /> <Compile Include="SQLExaminer\SQLExaminer_TST.cs" /> <Compile Include="Core\TemporaryManager_TST.cs" /> + <Compile Include="TCC\TCC_TST.cs" /> <Compile Include="TFS\TFS_TST.cs" /> <Compile Include="Outlook_TST.cs" /> <Compile Include="Embroidery\Embroidery_TST.cs" /> @@ -138,6 +140,9 @@ <Content Include="AdvancedInstaller\DemoProject\DemoProject.aip"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> + <Content Include="TCC\TCC Resources\bitmap.bmp"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <None Include="App.config" /> <None Include="packages.config" /> </ItemGroup> @@ -230,6 +235,14 @@ <Project>{5001990f-977b-48ff-b217-0236a5022ad8}</Project> <Name>Tango.Web</Name> </ProjectReference> + <ProjectReference Include="..\TCC\Tango.TCC.BL\Tango.TCC.BL.csproj"> + <Project>{f209fae8-73f9-441b-97f4-0844a0279390}</Project> + <Name>Tango.TCC.BL</Name> + </ProjectReference> + <ProjectReference Include="..\TCC\Tango.TCC.OpenCV.DLL\Tango.TCC.OpenCV.DLL.csproj"> + <Project>{5d0d4053-cab3-4a4a-929e-37a76483bc22}</Project> + <Name>Tango.TCC.OpenCV.DLL</Name> + </ProjectReference> <ProjectReference Include="..\Utilities\Tango.DBObservablesGenerator.CLI\Tango.DBObservablesGenerator.CLI.csproj"> <Project>{ebb7cb9f-6af2-456b-a5dd-1b136b605d90}</Project> <Name>Tango.DBObservablesGenerator.CLI</Name> @@ -264,7 +277,7 @@ <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
