Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis.lee committed Aug 29, 2023
1 parent 6705814 commit 92116e1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 85 deletions.
8 changes: 1 addition & 7 deletions Basler.Base/Data/Item.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Basler.Base.Data
namespace Basler.Base.Data
{
public class Item
{
Expand Down
7 changes: 1 addition & 6 deletions Basler.Base/Data/SystemData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Basler.Base.Data
{
Expand Down
4 changes: 1 addition & 3 deletions Basler.Base/Enumers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace Basler.Base
namespace Basler.Base
{
public enum PixelFormat
{
Expand Down
13 changes: 2 additions & 11 deletions Basler.Vision/Algorithm/HSIClassImple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
using Emgu.CV;
using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Basler.Base;
using Emgu.CV.Ocl;
using Emgu.CV.Util;

namespace Basler.Vision.Algorithm
{
Expand All @@ -22,8 +14,8 @@ public class HSIClassImple : IHSIClass
private Mat _kernel11x11;
public HSIClassImple()
{
_kernel5x5 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(5, 5), new Point(2, 2));
_kernel11x11 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(11, 11), new Point(2, 2));
_kernel5x5 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(5, 5), new Point(2, 2));
_kernel11x11 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(11, 11), new Point(2, 2));
}
public byte[] Execute((IntPtr bytes, int width, int height) image, (ResultSelection result, PixelFormat pxielFormat, Point H, Point S, Point I) p)
{
Expand Down Expand Up @@ -120,7 +112,6 @@ public byte[] Execute((IntPtr bytes, int width, int height) image, (ResultSelect
i?.Dispose();
opening?.Dispose();
closing?.Dispose();
//Marshal.FreeHGlobal(buffer);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions Basler.Vision/VisionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using Emgu.CV;
using Emgu.CV.Structure;

Expand All @@ -9,13 +8,10 @@ public class VisionHelper
{
public static byte[] Resize(IntPtr img, int w, int h, int sw, int sh)
{
//var buffer = IntPtr.Zero;
Image<Gray, byte> img1 = null;
Image<Gray, byte> simg = null;
try
{
//buffer = Marshal.AllocHGlobal(img.Length);
//Marshal.Copy(img, 0, buffer, img.Length);
img1 = new Image<Gray, byte>(w, h, w, img);
simg = img1.Resize(sw, sh, Emgu.CV.CvEnum.Inter.Nearest);

Expand All @@ -25,8 +21,6 @@ public static byte[] Resize(IntPtr img, int w, int h, int sw, int sh)
{
img1?.Dispose();
simg?.Dispose();
//Marshal.FreeHGlobal(img);
//Marshal.FreeHGlobal(buffer);
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions Main/ConfigHandler.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using Basler.Base;
using Basler.Base.Data;
using Basler.Vision;
using Main.Helper;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Main
{
internal class ConfigHandler
{
private static ConfigHandler _instance;
/// <summary>
/// Save system file in executable exist path.
/// </summary>
private static string SystemFile = $@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\System.xml";
internal static ConfigHandler Instance => _instance ?? (_instance = new ConfigHandler());
internal ConfigHandler()
Expand Down
21 changes: 0 additions & 21 deletions Main/Helper/XMLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Xml;

namespace Main.Helper
{
public static class XmlHelper
{
//public static bool Compare(string source, string changed)
//{
// XmlDocument sourceDoc = new XmlDocument();
// sourceDoc.LoadXml(source);
// XmlNode sourceNode = sourceDoc.DocumentElement;

// XmlDocument changedDoc = new XmlDocument();
// changedDoc.LoadXml(changed);
// XmlNode changedNode = changedDoc.DocumentElement;

// XmlDiff xmlDiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreWhitespace);

// var isDiff = xmlDiff.Compare(sourceNode, changedNode);

// return isDiff;
//}

/// <summary>
/// Convert generic type which had IFormattable to string.
/// </summary>
Expand Down
27 changes: 2 additions & 25 deletions Main/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Input;
using Main.Helper;
using Main.Models;
using Basler.Text;
using Basler.Base.Data;
using Basler.Vision;
using System.Threading;
Expand All @@ -19,10 +15,6 @@
using System.Windows;
using Basler.Base;
using Point = System.Drawing.Point;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Media.Media3D;
using System.Drawing.Drawing2D;

namespace Main.ViewModels
{
Expand Down Expand Up @@ -509,30 +501,15 @@ private void ShowRGB(byte[] img)
Xy = "";
}
}
catch
catch(Exception ex)
{

Console.WriteLine(ex);
}
}
private byte[] CPUProcess(IntPtr img)
{
return VisionHandler.Instance.HSIClass.Execute((img, _size.Width, _size.Height), (SelectDisplayItem, SelectDebayerFormatItem,
new Point(HueMin, HueMax), new Point(SaturationMin, SaturationMax), new Point(IntensityMin, IntensityMax)));
}
private void AddLog(string msg)
{
this.DispatchToUi(() =>
{
if (LogMessage.Count > 50)
{
LogMessage.RemoveAt(LogMessage.Count - 1);
}
if (LogMessage.Count > 0)
LogMessage.Insert(0, msg);
else
LogMessage.Add(msg);
OnPropertyChanged("LogMessage");
});
}
}
}

0 comments on commit 92116e1

Please sign in to comment.