Skip to content

Commit 92116e1

Browse files
author
elvis.lee
committed
Clean code
1 parent 6705814 commit 92116e1

8 files changed

Lines changed: 10 additions & 85 deletions

File tree

Basler.Base/Data/Item.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Basler.Base.Data
1+
namespace Basler.Base.Data
82
{
93
public class Item
104
{

Basler.Base/Data/SystemData.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Drawing;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
1+
using System.Drawing;
72

83
namespace Basler.Base.Data
94
{

Basler.Base/Enumers.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace Basler.Base
1+
namespace Basler.Base
42
{
53
public enum PixelFormat
64
{

Basler.Vision/Algorithm/HSIClassImple.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
using Emgu.CV;
44
using Emgu.CV.CvEnum;
55
using System;
6-
using System.Collections.Generic;
76
using System.Drawing;
8-
using System.Linq;
9-
using System.Runtime.InteropServices;
10-
using System.Text;
11-
using System.Threading.Tasks;
12-
using System.Windows;
137
using Basler.Base;
14-
using Emgu.CV.Ocl;
15-
using Emgu.CV.Util;
168

179
namespace Basler.Vision.Algorithm
1810
{
@@ -22,8 +14,8 @@ public class HSIClassImple : IHSIClass
2214
private Mat _kernel11x11;
2315
public HSIClassImple()
2416
{
25-
_kernel5x5 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(5, 5), new Point(2, 2));
26-
_kernel11x11 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(11, 11), new Point(2, 2));
17+
_kernel5x5 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(5, 5), new Point(2, 2));
18+
_kernel11x11 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(11, 11), new Point(2, 2));
2719
}
2820
public byte[] Execute((IntPtr bytes, int width, int height) image, (ResultSelection result, PixelFormat pxielFormat, Point H, Point S, Point I) p)
2921
{
@@ -120,7 +112,6 @@ public byte[] Execute((IntPtr bytes, int width, int height) image, (ResultSelect
120112
i?.Dispose();
121113
opening?.Dispose();
122114
closing?.Dispose();
123-
//Marshal.FreeHGlobal(buffer);
124115
}
125116
}
126117
}

Basler.Vision/VisionHelper.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Runtime.InteropServices;
32
using Emgu.CV;
43
using Emgu.CV.Structure;
54

@@ -9,13 +8,10 @@ public class VisionHelper
98
{
109
public static byte[] Resize(IntPtr img, int w, int h, int sw, int sh)
1110
{
12-
//var buffer = IntPtr.Zero;
1311
Image<Gray, byte> img1 = null;
1412
Image<Gray, byte> simg = null;
1513
try
1614
{
17-
//buffer = Marshal.AllocHGlobal(img.Length);
18-
//Marshal.Copy(img, 0, buffer, img.Length);
1915
img1 = new Image<Gray, byte>(w, h, w, img);
2016
simg = img1.Resize(sw, sh, Emgu.CV.CvEnum.Inter.Nearest);
2117

@@ -25,8 +21,6 @@ public static byte[] Resize(IntPtr img, int w, int h, int sw, int sh)
2521
{
2622
img1?.Dispose();
2723
simg?.Dispose();
28-
//Marshal.FreeHGlobal(img);
29-
//Marshal.FreeHGlobal(buffer);
3024
}
3125
}
3226
}

Main/ConfigHandler.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using Basler.Base;
22
using Basler.Base.Data;
3-
using Basler.Vision;
43
using Main.Helper;
5-
using System;
6-
using System.Collections.Generic;
74
using System.Drawing;
85
using System.IO;
9-
using System.Linq;
106
using System.Reflection;
11-
using System.Text;
12-
using System.Threading.Tasks;
137
using System.Xml;
148

159
namespace Main
1610
{
1711
internal class ConfigHandler
1812
{
1913
private static ConfigHandler _instance;
14+
/// <summary>
15+
/// Save system file in executable exist path.
16+
/// </summary>
2017
private static string SystemFile = $@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\System.xml";
2118
internal static ConfigHandler Instance => _instance ?? (_instance = new ConfigHandler());
2219
internal ConfigHandler()

Main/Helper/XMLHelper.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,12 @@
44
using System.Diagnostics;
55
using System.Globalization;
66
using System.IO;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
10-
using System.Xml.Serialization;
117
using System.Xml;
128

139
namespace Main.Helper
1410
{
1511
public static class XmlHelper
1612
{
17-
//public static bool Compare(string source, string changed)
18-
//{
19-
// XmlDocument sourceDoc = new XmlDocument();
20-
// sourceDoc.LoadXml(source);
21-
// XmlNode sourceNode = sourceDoc.DocumentElement;
22-
23-
// XmlDocument changedDoc = new XmlDocument();
24-
// changedDoc.LoadXml(changed);
25-
// XmlNode changedNode = changedDoc.DocumentElement;
26-
27-
// XmlDiff xmlDiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreWhitespace);
28-
29-
// var isDiff = xmlDiff.Compare(sourceNode, changedNode);
30-
31-
// return isDiff;
32-
//}
33-
3413
/// <summary>
3514
/// Convert generic type which had IFormattable to string.
3615
/// </summary>

Main/ViewModels/MainViewModel.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
22
using System.Collections.ObjectModel;
33
using System.IO;
4-
using System.Reflection;
54
using System.Threading.Tasks;
6-
using System.Windows.Input;
75
using Main.Helper;
8-
using Main.Models;
9-
using Basler.Text;
106
using Basler.Base.Data;
117
using Basler.Vision;
128
using System.Threading;
@@ -19,10 +15,6 @@
1915
using System.Windows;
2016
using Basler.Base;
2117
using Point = System.Drawing.Point;
22-
using System.Drawing;
23-
using System.Drawing.Imaging;
24-
using System.Windows.Media.Media3D;
25-
using System.Drawing.Drawing2D;
2618

2719
namespace Main.ViewModels
2820
{
@@ -509,30 +501,15 @@ private void ShowRGB(byte[] img)
509501
Xy = "";
510502
}
511503
}
512-
catch
504+
catch(Exception ex)
513505
{
514-
506+
Console.WriteLine(ex);
515507
}
516508
}
517509
private byte[] CPUProcess(IntPtr img)
518510
{
519511
return VisionHandler.Instance.HSIClass.Execute((img, _size.Width, _size.Height), (SelectDisplayItem, SelectDebayerFormatItem,
520512
new Point(HueMin, HueMax), new Point(SaturationMin, SaturationMax), new Point(IntensityMin, IntensityMax)));
521513
}
522-
private void AddLog(string msg)
523-
{
524-
this.DispatchToUi(() =>
525-
{
526-
if (LogMessage.Count > 50)
527-
{
528-
LogMessage.RemoveAt(LogMessage.Count - 1);
529-
}
530-
if (LogMessage.Count > 0)
531-
LogMessage.Insert(0, msg);
532-
else
533-
LogMessage.Add(msg);
534-
OnPropertyChanged("LogMessage");
535-
});
536-
}
537514
}
538515
}

0 commit comments

Comments
 (0)