Commit 9f0e7f5b 张东亮

平台检测小程序

1 个父辈 b890c19b
...@@ -28,20 +28,313 @@ ...@@ -28,20 +28,313 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.label1 = new System.Windows.Forms.Label();
this.txtTotalCover = new System.Windows.Forms.TextBox();
this.lblHL = new System.Windows.Forms.Label();
this.lblHH = new System.Windows.Forms.Label();
this.lblLL = new System.Windows.Forms.Label();
this.lblLH = new System.Windows.Forms.Label();
this.lblSL = new System.Windows.Forms.Label();
this.lblSH = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.txtHL = new System.Windows.Forms.TrackBar();
this.txtSH = new System.Windows.Forms.TrackBar();
this.txtSL = new System.Windows.Forms.TrackBar();
this.txtLH = new System.Windows.Forms.TrackBar();
this.txtLL = new System.Windows.Forms.TrackBar();
this.txtHH = new System.Windows.Forms.TrackBar();
this.txtthreshold = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtHL)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtSH)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtSL)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtLH)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtLL)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtHH)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(383, 331);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(191, 15);
this.label1.TabIndex = 0;
this.label1.Text = "CamTestReel_totalcover:";
//
// txtTotalCover
//
this.txtTotalCover.Location = new System.Drawing.Point(582, 323);
this.txtTotalCover.Name = "txtTotalCover";
this.txtTotalCover.Size = new System.Drawing.Size(141, 25);
this.txtTotalCover.TabIndex = 1;
this.txtTotalCover.TextChanged += new System.EventHandler(this.txtTotalCover_TextChanged);
//
// lblHL
//
this.lblHL.AutoSize = true;
this.lblHL.Location = new System.Drawing.Point(13, 14);
this.lblHL.Name = "lblHL";
this.lblHL.Size = new System.Drawing.Size(187, 15);
this.lblHL.TabIndex = 2;
this.lblHL.Text = "CamTestReel_HL(色相):";
//
// lblHH
//
this.lblHH.AutoSize = true;
this.lblHH.Location = new System.Drawing.Point(398, 14);
this.lblHH.Name = "lblHH";
this.lblHH.Size = new System.Drawing.Size(187, 15);
this.lblHH.TabIndex = 4;
this.lblHH.Text = "CamTestReel_HH(色相):";
//
// lblLL
//
this.lblLL.AutoSize = true;
this.lblLL.Location = new System.Drawing.Point(12, 106);
this.lblLL.Name = "lblLL";
this.lblLL.Size = new System.Drawing.Size(187, 15);
this.lblLL.TabIndex = 6;
this.lblLL.Text = "CamTestReel_LL(亮度):";
//
// lblLH
//
this.lblLH.AutoSize = true;
this.lblLH.Location = new System.Drawing.Point(398, 106);
this.lblLH.Name = "lblLH";
this.lblLH.Size = new System.Drawing.Size(187, 15);
this.lblLH.TabIndex = 8;
this.lblLH.Text = "CamTestReel_LH(亮度):";
//
// lblSL
//
this.lblSL.AutoSize = true;
this.lblSL.Location = new System.Drawing.Point(23, 220);
this.lblSL.Name = "lblSL";
this.lblSL.Size = new System.Drawing.Size(202, 15);
this.lblSL.TabIndex = 10;
this.lblSL.Text = "CamTestReel_SL(饱和度):";
//
// lblSH
//
this.lblSH.AutoSize = true;
this.lblSH.Location = new System.Drawing.Point(383, 220);
this.lblSH.Name = "lblSH";
this.lblSH.Size = new System.Drawing.Size(202, 15);
this.lblSH.TabIndex = 12;
this.lblSH.Text = "CamTestReel_SH(饱和度):";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(12, 326);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(183, 15);
this.label8.TabIndex = 14;
this.label8.Text = "CamTestReel_threshold:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(358, 360);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(629, 87);
this.textBox1.TabIndex = 16;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(358, 453);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(308, 256);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 17;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(679, 453);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(308, 256);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 18;
this.pictureBox2.TabStop = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(850, 91);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(144, 55);
this.button1.TabIndex = 19;
this.button1.Text = "打开图片";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 453);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(337, 256);
this.textBox2.TabIndex = 20;
//
// button2
//
this.button2.Location = new System.Drawing.Point(208, 376);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(144, 55);
this.button2.TabIndex = 21;
this.button2.Text = "保存ROI";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click_1);
//
// txtHL
//
this.txtHL.Location = new System.Drawing.Point(16, 42);
this.txtHL.Maximum = 360;
this.txtHL.Name = "txtHL";
this.txtHL.Size = new System.Drawing.Size(333, 56);
this.txtHL.TabIndex = 22;
this.txtHL.Scroll += new System.EventHandler(this.txtHL_Scroll);
//
// txtSH
//
this.txtSH.Location = new System.Drawing.Point(386, 249);
this.txtSH.Maximum = 255;
this.txtSH.Name = "txtSH";
this.txtSH.Size = new System.Drawing.Size(327, 56);
this.txtSH.TabIndex = 23;
this.txtSH.Scroll += new System.EventHandler(this.txtSH_Scroll);
//
// txtSL
//
this.txtSL.Location = new System.Drawing.Point(26, 249);
this.txtSL.Maximum = 255;
this.txtSL.Name = "txtSL";
this.txtSL.Size = new System.Drawing.Size(327, 56);
this.txtSL.TabIndex = 24;
this.txtSL.Scroll += new System.EventHandler(this.txtSL_Scroll);
//
// txtLH
//
this.txtLH.Location = new System.Drawing.Point(386, 140);
this.txtLH.Maximum = 255;
this.txtLH.Name = "txtLH";
this.txtLH.Size = new System.Drawing.Size(327, 56);
this.txtLH.TabIndex = 25;
this.txtLH.Scroll += new System.EventHandler(this.txtLH_Scroll);
//
// txtLL
//
this.txtLL.Location = new System.Drawing.Point(16, 140);
this.txtLL.Maximum = 255;
this.txtLL.Name = "txtLL";
this.txtLL.Size = new System.Drawing.Size(333, 56);
this.txtLL.TabIndex = 26;
this.txtLL.Scroll += new System.EventHandler(this.txtLL_Scroll);
//
// txtHH
//
this.txtHH.Location = new System.Drawing.Point(386, 42);
this.txtHH.Maximum = 360;
this.txtHH.Name = "txtHH";
this.txtHH.Size = new System.Drawing.Size(327, 56);
this.txtHH.TabIndex = 27;
this.txtHH.Scroll += new System.EventHandler(this.txtHH_Scroll);
//
// txtthreshold
//
this.txtthreshold.Location = new System.Drawing.Point(208, 323);
this.txtthreshold.Name = "txtthreshold";
this.txtthreshold.Size = new System.Drawing.Size(141, 25);
this.txtthreshold.TabIndex = 28;
//
// button3
//
this.button3.Location = new System.Drawing.Point(12, 376);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(144, 55);
this.button3.TabIndex = 29;
this.button3.Text = "加载ROI";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(1006, 721);
this.Controls.Add(this.button3);
this.Controls.Add(this.txtthreshold);
this.Controls.Add(this.txtHH);
this.Controls.Add(this.txtLL);
this.Controls.Add(this.txtLH);
this.Controls.Add(this.txtSL);
this.Controls.Add(this.txtSH);
this.Controls.Add(this.txtHL);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label8);
this.Controls.Add(this.lblSH);
this.Controls.Add(this.lblSL);
this.Controls.Add(this.lblLH);
this.Controls.Add(this.lblLL);
this.Controls.Add(this.lblHH);
this.Controls.Add(this.lblHL);
this.Controls.Add(this.txtTotalCover);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.Name = "Form1"; this.Name = "Form1";
this.Text = "视觉检测料盘调试"; this.Text = "视觉检测料盘调试";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtHL)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtSH)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtSL)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtLH)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtLL)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtHH)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtTotalCover;
private System.Windows.Forms.Label lblHL;
private System.Windows.Forms.Label lblHH;
private System.Windows.Forms.Label lblLL;
private System.Windows.Forms.Label lblLH;
private System.Windows.Forms.Label lblSL;
private System.Windows.Forms.Label lblSH;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TrackBar txtHL;
private System.Windows.Forms.TrackBar txtSH;
private System.Windows.Forms.TrackBar txtSL;
private System.Windows.Forms.TrackBar txtLH;
private System.Windows.Forms.TrackBar txtLL;
private System.Windows.Forms.TrackBar txtHH;
private System.Windows.Forms.TextBox txtthreshold;
private System.Windows.Forms.Button button3;
} }
} }
using System; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Linq;
namespace ImgCheckReel namespace ImgCheckReel
{ {
...@@ -15,6 +22,530 @@ namespace ImgCheckReel ...@@ -15,6 +22,530 @@ namespace ImgCheckReel
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
ConfigHelper.Config.PropertyBind("txtTotalCover", txtTotalCover, "Text", "TextChanged", "100");
ConfigHelper.Config.PropertyBind("txtthreshold", txtthreshold, "Text", "TextChanged", "0.6");
ConfigHelper.Config.PropertyBind("txtHL", txtHL, "Value", "Scroll", "40");
ConfigHelper.Config.PropertyBind("txtHH", txtHH, "Value", "Scroll", "70");
ConfigHelper.Config.PropertyBind("txtLL", txtLL, "Value", "Scroll", "15");
ConfigHelper.Config.PropertyBind("txtLH", txtLH, "Value", "Scroll", "100");
ConfigHelper.Config.PropertyBind("txtSL", txtSL, "Value", "Scroll", "20");
ConfigHelper.Config.PropertyBind("txtSH", txtSH, "Value", "Scroll", "100");
UpdateValue();
}
[HandleProcessCorruptedStateExceptions]
public bool? TestHasReel(string filename, out string msg)
{
msg = "";
DateTime startTime = DateTime.Now;
Bitmap bmp = null;
textBox1.Text = "";
pictureBox1.Image = null;
pictureBox2.Image = null;
using (var s = File.Open(filename, FileMode.Open))
{
bmp = (Bitmap)Bitmap.FromStream(s);
}
try
{
if (bmp == null)
{
return false;
}
pictureBox1.Image = (Image)bmp.Clone();
var b = new Bitmap(bmp.Width / 2, bmp.Height / 2, bmp.PixelFormat);
bool hasReel = false;
using (var g = Graphics.FromImage(b))
{
g.InterpolationMode = InterpolationMode.Low;
g.DrawImage(bmp, 0, 0, b.Width, b.Height);
ImageLockMode imageLockMode = ImageLockMode.ReadWrite;
var bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), imageLockMode, b.PixelFormat);
var rois = TestRoi.GetRois();
if (rois == null || rois.Count == 0)
{
rois = new List<TestRoi>() { new TestRoi() };
rois[0].CoverCount = totalcover;
rois[0].RoiPath.Add(new Point(0, 0));
rois[0].RoiPath.Add(new Point(bmp.Width, 0));
rois[0].RoiPath.Add(new Point(bmp.Width, bmp.Height));
rois[0].RoiPath.Add(new Point(0, bmp.Height));
TestRoi.SaveConfig(rois);
}
for (int i = 0; i < rois.Count; i++)
{
rois[i].CoverCount = totalcover;
double maskcout = 0;
var roi = rois[i];
var rp = roi.RoiPath.Select(r => new Point(r.X / 2, r.Y / 2)).ToList();
// rp.ForEach(s => g.DrawString("新的角点", new Font("黑体", 9), new SolidBrush(Color.FromArgb(0, 255, 0)), s));
var fp = GetFilledPoints(rp);
var nfp = fp.Where(f => IsPointInPath(f.X, f.Y, rp)).ToList();
foreach (var xy in nfp)
{
int x = (xy.Y * bd.Width + xy.X) * 3;
//Marshal.WriteByte(bd.Scan0, x, 0);
//Marshal.WriteByte(bd.Scan0, x + 1, 0);
//Marshal.WriteByte(bd.Scan0, x + 2, 255);
var cr = (int)Marshal.ReadByte(bd.Scan0, x + 2);
var cg = (int)Marshal.ReadByte(bd.Scan0, x + 1);
var cb = (int)Marshal.ReadByte(bd.Scan0, x);
var h = RgbToHsv(new ColorRGB(cr, cg, cb));
if (h.H >= hl && h.H <= hh && h.V >= ll && h.V <= lh && h.S >= sl && h.S <= sh)
{
maskcout++;
Marshal.WriteByte(bd.Scan0, x, 0);
Marshal.WriteByte(bd.Scan0, x + 1, 0);
Marshal.WriteByte(bd.Scan0, x + 2, 255);
}
else
{
Marshal.WriteByte(bd.Scan0, x, 255);
Marshal.WriteByte(bd.Scan0, x + 1, 255);
Marshal.WriteByte(bd.Scan0, x + 2, 255);
}
}
double calc = maskcout / (double)roi.CoverCount;
textBox1.Text += $" 检测到Roi[{i}]覆盖面积计数:maskcout:{maskcout}/{roi.CoverCount}={calc}<{threshold},result:{(calc <= threshold ? "有料" : "无料")}\r\n";
if (calc <= threshold)
{
hasReel = true;
break;
}
}
b.UnlockBits(bd);
pictureBox2.Image = (Image)b.Clone();
}
b.Dispose();
return hasReel;
}
catch (AccessViolationException e)
{
MessageBox.Show(" 扫码出现AccessViolationException异常:" + e.ToString());
return null;
}
catch (Exception ex)
{
MessageBox.Show(" 扫码出错:" + ex.ToString());
return null;
}
finally
{
if (bmp != null)
bmp.Dispose();
}
}
int totalcover, hh, hl, ll, lh, sl, sh;
double threshold;
string fName;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter = "图片|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
fName = openFileDialog.FileName;
TestHasReel(fName, out string msg);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(fName))
{
TestHasReel(fName, out string msg);
}
}
void UpdateValue()
{
lblHL.Text = $"CamTestReel_HL(色相):{txtHL.Value}";
hl = txtHL.Value;
lblHH.Text = $"CamTestReel_HH(色相):{txtHH.Value}";
hh = txtHH.Value;
lblLL.Text = $"CamTestReel_LL(亮度):{txtLL.Value}";
ll = txtLL.Value;
lblLH.Text = $"CamTestReel_LH(亮度):{txtLH.Value}";
lh = txtLH.Value;
lblSL.Text = $"CamTestReel_SL(饱和度):{txtSL.Value}";
sl = txtSL.Value;
lblSH.Text = $"CamTestReel_SH(饱和度):{txtSH.Value}";
sh = txtSH.Value;
}
private void button2_Click_1(object sender, EventArgs e)
{
TestRoi.SaveConfig(textBox2.Text);
TestHasReel(fName, out string msg);
}
private void txtHL_Scroll(object sender, EventArgs e)
{
UpdateValue();
button2_Click(null, null);
}
private void txtHH_Scroll(object sender, EventArgs e)
{
UpdateValue();
button2_Click(null, null);
}
private void txtLL_Scroll(object sender, EventArgs e)
{
UpdateValue();
button2_Click(null, null);
}
private void txtLH_Scroll(object sender, EventArgs e)
{
UpdateValue();
button2_Click(null, null);
}
private void button3_Click(object sender, EventArgs e)
{
textBox2.Text = TestRoi.LoadConfig();
}
private void txtSL_Scroll(object sender, EventArgs e)
{
UpdateValue();
button2_Click(null, null);
}
private void txtSH_Scroll(object sender, EventArgs e)
{
UpdateValue(); ;
button2_Click(null, null);
}
private void txtTotalCover_TextChanged(object sender, EventArgs e)
{
int.TryParse(txtTotalCover.Text, out totalcover);
button2_Click(null, null);
}
private static List<Point> GetFilledPoints(List<Point> points)
{
List<Point> filledPoints = new List<Point>();
// 获取路径的边界框
int minX = int.MaxValue;
int minY = int.MaxValue;
int maxX = int.MinValue;
int maxY = int.MinValue;
foreach (Point point in points)
{
if (point.X < minX)
{
minX = point.X;
}
if (point.Y < minY)
{
minY = point.Y;
}
if (point.X > maxX)
{
maxX = point.X;
}
if (point.Y > maxY)
{
maxY = point.Y;
}
}
// 遍历边界框内的每个像素点
for (int y = minY; y <= maxY; y++)
{
for (int x = minX; x <= maxX; x++)
{
if (IsPointInPath(x, y, points))
{
filledPoints.Add(new Point(x, y));
}
}
}
return filledPoints;
}
private static bool IsPointInPath(int x, int y, List<Point> points)
{
bool inside = false;
for (int i = 0, j = points.Count - 1; i < points.Count; j = i++)
{
if (((points[i].Y > y) != (points[j].Y > y)) &&
(x < (points[j].X - points[i].X) * (y - points[i].Y) / (points[j].Y - points[i].Y) + points[i].X))
{
inside = !inside;
}
}
return inside;
}
/// <summary>
/// RGB转换HSV
/// </summary>
/// <param name="rgb"></param>
/// <returns></returns>
public static ColorHSV RgbToHsv(ColorRGB rgb)
{
float min, max, tmp, H, S, V;
float R = rgb.R * 1.0f / 255, G = rgb.G * 1.0f / 255, B = rgb.B * 1.0f / 255;
tmp = Math.Min(R, G);
min = Math.Min(tmp, B);
tmp = Math.Max(R, G);
max = Math.Max(tmp, B);
// H
H = 0;
if (max == min)
{
H = 0;
}
else if (max == R && G > B)
{
H = 60 * (G - B) * 1.0f / (max - min) + 0;
}
else if (max == R && G < B)
{
H = 60 * (G - B) * 1.0f / (max - min) + 360;
}
else if (max == G)
{
H = H = 60 * (B - R) * 1.0f / (max - min) + 120;
}
else if (max == B)
{
H = H = 60 * (R - G) * 1.0f / (max - min) + 240;
}
// S
if (max == 0)
{
S = 0;
}
else
{
S = (max - min) * 1.0f / max;
}
// V
V = max;
return new ColorHSV((int)H, (int)(S * 100), (int)(V * 100));
}
}
/// <summary>
/// 类 名:ColorRGB
/// 功 能:R 红色 \ G 绿色 \ B 蓝色 颜色模型
/// 所有颜色模型的基类,RGB是用于输出到屏幕的颜色模式,所以所有模型都将转换成RGB输出
/// 日 期:2015-01-22
/// 修 改:2015-03-20
/// 作 者:ls9512
/// </summary>
public class ColorRGB
{
/// <summary>
/// 构造方法
/// </summary>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="b"></param>
public ColorRGB(int r, int g, int b)
{
this._r = r;
this._g = g;
this._b = b;
}
private int _r;
private int _g;
private int _b;
/// <summary>
/// 红色
/// </summary>
public int R
{
get { return this._r; }
set
{
this._r = value;
this._r = this._r > 255 ? 255 : this._r;
this._r = this._r < 0 ? 0 : this._r;
}
}
/// <summary>
/// 绿色
/// </summary>
public int G
{
get { return this._g; }
set
{
this._g = value;
this._g = this._g > 255 ? 255 : this._g;
this._g = this._g < 0 ? 0 : this._g;
}
}
/// <summary>
/// 蓝色
/// </summary>
public int B
{
get { return this._b; }
set
{
this._b = value;
this._b = this._b > 255 ? 255 : this._b;
this._b = this._b < 0 ? 0 : this._b;
}
}
/// <summary>
/// 获取实际颜色
/// </summary>
/// <returns></returns>
public Color GetColor()
{
return Color.FromArgb(this._r, this._g, this._b);
}
}
internal class TestRoi
{
public int CoverCount = 1;
public List<Point> RoiPath = new List<Point>();
const string roifile = "Config\\coverroi.json";
static List<TestRoi> listroi = null;
public static List<TestRoi> GetRois()
{
return listroi;
}
static TestRoi()
{
ReloadConfig();
}
public static string LoadConfig()
{
if (!File.Exists(roifile))
return "";
return File.ReadAllText(roifile);
}
public static void ReloadConfig()
{
if (!File.Exists(roifile))
return;
var roidata = File.ReadAllText(roifile);
listroi = JsonConvert.DeserializeObject<List<TestRoi>>(roidata);
return;
}
public static void SaveConfig(List<TestRoi> data)
{
if (!File.Exists(roifile))
return;
var dataStr = JsonConvert.SerializeObject(data);
File.WriteAllText(roifile, dataStr);
ReloadConfig();
}
public static void SaveConfig(string data)
{
if (!File.Exists(roifile))
return;
File.WriteAllText(roifile, data);
ReloadConfig();
}
}
/// <summary>
/// 类 名:ColorHSV
/// 功 能:H 色相 \ S 饱和度(纯度) \ V 明度 颜色模型
/// 日 期:2015-01-22
/// 修 改:2015-03-20
/// 作 者:ls9512
/// </summary>
public class ColorHSV
{
/// <summary>
/// 构造方法
/// </summary>
/// <param name="h"></param>
/// <param name="s"></param>
/// <param name="v"></param>
public ColorHSV(int h, int s, int v)
{
this._h = h;
this._s = s;
this._v = v;
}
private int _h;
private int _s;
private int _v;
/// <summary>
/// 色相
/// </summary>
public int H
{
get { return this._h; }
set
{
this._h = value;
this._h = this._h > 360 ? 360 : this._h;
this._h = this._h < 0 ? 0 : this._h;
}
}
/// <summary>
/// 饱和度(纯度)
/// </summary>
public int S
{
get { return this._s; }
set
{
this._s = value;
this._s = this._s > 255 ? 255 : this._s;
this._s = this._s < 0 ? 0 : this._s;
}
}
/// <summary>
/// 明度
/// </summary>
public int V
{
get { return this._v; }
set
{
this._v = value;
this._v = this._v > 255 ? 255 : this._v;
this._v = this._v < 0 ? 0 : this._v;
}
} }
} }
} }
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ConfigHelper">
<HintPath>..\..\..\..\..\SharedRefDll\Neotel\ConfigHelper\Debug\net461\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="Cyotek.Windows.Forms.ImageBox">
<HintPath>.\Cyotek.Windows.Forms.ImageBox.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
...@@ -66,6 +75,7 @@ ...@@ -66,6 +75,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" />
</packages>
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!