Commit debb7db7 刘韬

添加通过颜色判断是否有料盘

1 个父辈 be24b727
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.Common
{
#region RGB / HSV / HSL 颜色模型类
/// <summary>
/// 类 名:ColorHSL
/// 功 能:H 色相 \ S 饱和度(纯度) \ L 亮度 颜色模型
/// 日 期:2015-02-08
/// 修 改:2015-03-20
/// 作 者:ls9512
/// </summary>
public class ColorHSL
{
public ColorHSL(int h, int s, int l)
{
this._h = h;
this._s = s;
this._l = l;
}
private int _h;
private int _s;
private int _l;
/// <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 L
{
get { return this._l; }
set
{
this._l = value;
this._l = this._l > 255 ? 255 : this._l;
this._l = this._l < 0 ? 0 : this._l;
}
}
}
/// <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;
}
}
}
/// <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);
}
}
#endregion
/// <summary>
/// 类 名:ColorHelper
/// 功 能:提供从RGB到HSV/HSL色彩空间的相互转换
/// 日 期:2015-02-08
/// 修 改:2015-03-20
/// 作 者:ls9512
/// </summary>
public static class ColorHelper
{
/// <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>
/// HSV转换RGB
/// </summary>
/// <param name="hsv"></param>
/// <returns></returns>
public static ColorRGB HsvToRgb(ColorHSV hsv)
{
if (hsv.H == 360) hsv.H = 359; // 360为全黑,原因不明
float R = 0f, G = 0f, B = 0f;
if (hsv.S == 0)
{
return new ColorRGB(hsv.V, hsv.V, hsv.V);
}
float S = hsv.S * 1.0f / 255, V = hsv.V * 1.0f / 255;
int H1 = (int)(hsv.H * 1.0f / 60), H = hsv.H;
float F = H * 1.0f / 60 - H1;
float P = V * (1.0f - S);
float Q = V * (1.0f - F * S);
float T = V * (1.0f - (1.0f - F) * S);
switch (H1)
{
case 0: R = V; G = T; B = P; break;
case 1: R = Q; G = V; B = P; break;
case 2: R = P; G = V; B = T; break;
case 3: R = P; G = Q; B = V; break;
case 4: R = T; G = P; B = V; break;
case 5: R = V; G = P; B = Q; break;
}
R = R * 255;
G = G * 255;
B = B * 255;
while (R > 255) R -= 255;
while (R < 0) R += 255;
while (G > 255) G -= 255;
while (G < 0) G += 255;
while (B > 255) B -= 255;
while (B < 0) B += 255;
return new ColorRGB((int)R, (int)G, (int)B);
}
/// <summary>
/// RGB转换HSL
/// </summary>
/// <param name="rgb"></param>
/// <returns></returns>
public static ColorHSL RgbToHsl(ColorRGB rgb)
{
float min, max, tmp, H, S, L;
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; // 此时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;
}
// L
L = 0.5f * (max + min);
// S
S = 0;
if (L == 0 || max == min)
{
S = 0;
}
else if (0 < L && L < 0.5)
{
S = (max - min) / (L * 2);
}
else if (L > 0.5)
{
S = (max - min) / (2 - 2 * L);
}
return new ColorHSL((int)H, (int)(S * 100), (int)(L * 100));
}
/// <summary>
/// HSL转换RGB
/// </summary>
/// <param name="hsl"></param>
/// <returns></returns>
public static ColorRGB HslToRgb(ColorHSL hsl)
{
float R = 0f, G = 0f, B = 0f;
float S = hsl.S * 1.0f / 255, L = hsl.L * 1.0f / 255;
float temp1, temp2, temp3;
if (S == 0f) // 灰色
{
R = L;
G = L;
B = L;
}
else
{
if (L < 0.5f)
{
temp2 = L * (1.0f + S);
}
else
{
temp2 = L + S - L * S;
}
temp1 = 2.0f * L - temp2;
float H = hsl.H * 1.0f / 360;
// R
temp3 = H + 1.0f / 3.0f;
if (temp3 < 0) temp3 += 1.0f;
if (temp3 > 1) temp3 -= 1.0f;
R = temp3;
// G
temp3 = H;
if (temp3 < 0) temp3 += 1.0f;
if (temp3 > 1) temp3 -= 1.0f;
G = temp3;
// B
temp3 = H - 1.0f / 3.0f;
if (temp3 < 0) temp3 += 1.0f;
if (temp3 > 1) temp3 -= 1.0f;
B = temp3;
}
R = R * 255;
G = G * 255;
B = B * 255;
return new ColorRGB((int)R, (int)G, (int)B);
}
}
}
......@@ -56,6 +56,7 @@
<ItemGroup>
<Compile Include="bean\Bean.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="ColorHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setting_Init.cs" />
<Compile Include="StringList.cs" />
......
......@@ -74,6 +74,7 @@
<ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" />
<Compile Include="DeviceLibrary\Camera.cs" />
<Compile Include="DeviceLibrary\CameraTest.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class CameraTest : ConfigHelper.ICustEditor
{
public object ValueEdit(object value)
{
Task.Run(() => CodeManager.TestHasReel(CodeManager.hikNameList[0]));
return "Click To Test";
}
}
}
......@@ -13,6 +13,8 @@ using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace DeviceLibrary
{
......@@ -31,6 +33,9 @@ namespace DeviceLibrary
/// </summary>
public static void LoadConfig()
{
ConfigHelper.Config.Set("CamTestReel_Test", "Click To Test");
ConfigHelper.AdvanceConfigForm.AddCustomEditor<CameraTest>("CamTestReel_Test");
string nameStr = ConfigHelper.Config.Get(Setting_Init.CameraName);
codeTypeList = new List<string>();
HDLogUtil.LogName = "RollingLogFileAppender";
......@@ -306,6 +311,97 @@ namespace DeviceLibrary
}
return codeList;
}
[HandleProcessCorruptedStateExceptions]
public static bool TestHasReel(string cameraName)
{
int retrytime = 0;
retry:
LogUtil.error($"【" + cameraName + "】开始取图片测试是否有料盘");
DateTime startTime = DateTime.Now;
Bitmap bmp = null;
try
{
bmp = Camera._cam.GrabOneImage(cameraName, PixelType.RGB8);
if (bmp == null)
{
if (retrytime > 2)
return false;
retrytime++;
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
LogUtil.error($"【" + cameraName + "】获取到图像");
int totalcover = ConfigHelper.Config.Get("CamTestReel_totalcover", 69577);
int hl = ConfigHelper.Config.Get("CamTestReel_HL", 18);
int hh = ConfigHelper.Config.Get("CamTestReel_HH", 47);
int ll = ConfigHelper.Config.Get("CamTestReel_LL", 15);
int lh = ConfigHelper.Config.Get("CamTestReel_LH", 100);
int sl = ConfigHelper.Config.Get("CamTestReel_SL", 95);
int sh = ConfigHelper.Config.Get("CamTestReel_SH", 100);
double threshold = ConfigHelper.Config.Get("CamTestReel_threshold", 0.6);
if (ConfigHelper.Config.Get("CamTestReel_debug",false))
SaveImageToFile("test", cameraName, bmp);
double maskcout = 0;
var b = new Bitmap(bmp.Width / 2, bmp.Height / 2, bmp.PixelFormat);
using (var g = Graphics.FromImage(b))
{
g.InterpolationMode = InterpolationMode.Low;
g.DrawImage(bmp, 0, 0, b.Width, b.Height);
}
ImageLockMode imageLockMode = ImageLockMode.ReadOnly;
if (ConfigHelper.Config.Get("CamTestReel_debug", false))
imageLockMode = ImageLockMode.ReadWrite;
var bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), imageLockMode, b.PixelFormat);
for (int x = 0; x < b.Width * b.Height * 3; x = x + 3)
{
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 = ColorHelper.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++;
if (ConfigHelper.Config.Get("CamTestReel_debug", false))
{
Marshal.WriteByte(bd.Scan0, x, 0);
Marshal.WriteByte(bd.Scan0, x + 1, 0);
Marshal.WriteByte(bd.Scan0, x + 2, 255);
}
}
}
b.UnlockBits(bd);
if (ConfigHelper.Config.Get("CamTestReel_debug", false))
SaveImageToFile("test2", cameraName, b);
b.Dispose();
double calc = maskcout / (double)totalcover;
LogUtil.error($" 检测到覆盖面积计数:maskcout:{maskcout}/{totalcover}={calc}<{threshold},result:{calc <= threshold}");
return calc <= threshold;
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
}
finally
{
if (bmp != null)
bmp.Dispose();
}
return true;
}
/// <summary>
///
/// </summary>
......@@ -331,7 +427,7 @@ namespace DeviceLibrary
Directory.CreateDirectory(dire);
}
bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
bitmap.Dispose();
//bitmap.Dispose();
LogUtil.info(deviceName + " 【" + cameraName + "】扫码完成,保存图片到【" + dire + iamgeName + "】成功");
}
......
......@@ -83,6 +83,20 @@ namespace DeviceLibrary
RunningLed.LedState = LedState.on;
StandbyLed.LedState = LedState.off;
AlarmLed.LedState = LedState.blink;
if (UserPause) {
RunningLed.LedState = LedState.blink;
StandbyLed.LedState = LedState.blink;
}
//if (ResetMoveInfo.MoveStep >= MoveStep.H13_HomeReset && ResetMoveInfo.MoveStep <= MoveStep.H14_HomeReset)
//{
// StandbyLed.LedState = LedState.blink;
//}
//if (ClampMoveInfo.MoveStep >= MoveStep.NGOUT_02 && ClampMoveInfo.MoveStep <= MoveStep.NGOUT_03)
//{
// StandbyLed.LedState = LedState.blink;
//}
}
Led.LedGroup.ForEach((x) => { x.run(); });
}
......
......@@ -117,6 +117,7 @@ namespace DeviceLibrary
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500,100);
IOMonitor.RegisterIO(IO_Type.AutoRun_Single, Config, IO_VALUE.HIGH, Run_BTN, 2500,100);
LedProcessInit();
ConfigHelper.Config.Get("CamTestReel_Ability", false);
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
......@@ -318,7 +319,8 @@ namespace DeviceLibrary
InOut_Axis.AbsMove(ResetMoveInfo, Config.InOut_P1, Config.InOut_P1_speed);
Middle_Axis.HomeMove(ResetMoveInfo, forceHome);
UpDown_Axis.HomeMove(ResetMoveInfo, forceHome);
OpenFlipDoor(ResetMoveInfo);
//OpenFlipDoor(ResetMoveInfo);
break;
case MoveStep.H04_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
......@@ -346,7 +348,13 @@ namespace DeviceLibrary
ResetMoveInfo.log("夹爪上有料盘,送到NG口");
}
else {
else if (IOValue(IO_Type.ReelFlipDoor_L_Home).Equals(IO_VALUE.LOW) && IOValue(IO_Type.ReelFlipDoor_R_Home).Equals(IO_VALUE.LOW) && NGDoor_Tray_Test_Reel)
{
ResetMoveInfo.NextMoveStep(MoveStep.H12_HomeReset);
ResetMoveInfo.log("反转托盘上有料盘,送到NG口");
}
else
{
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("夹爪上上没有料盘");
}
......@@ -376,19 +384,27 @@ namespace DeviceLibrary
CylinderMove(ResetMoveInfo, IO_Type.NGDoor_Close, IO_Type.NGDoor_Open, IO_VALUE.HIGH);
break;
case MoveStep.H13_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H12_HomeReset);
if (IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.LOW))
ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
if (!NGDoor_Tray_Test_Reel)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "传感器X29未检测到单料口料盘."), MsgLevel.alarm);
RobotManage.UserPause("传感器X29未检测到单料口料盘.");
}
break;
case MoveStep.H14_HomeReset:
if (IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH))
if (NGDoor_Tray_Test_Reel)
{
Msg.add(crc.GetString(L.x29_higt_has_reel, "系统启动X29检测到有无信息料盘,等待取走单料口料盘"), MsgLevel.alarm);
if (ConfigHelper.Config.Get("CamTestReel_Ability", false))
{
ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
else
{
RobotManage.UserPause("系统启动X29检测到有无信息料盘,等待取走单料口料盘");
}
}
else {
ResetMoveInfo.NextMoveStep(MoveStep.H15_HomeReset);
ResetMoveInfo.log("料盘已取走");
......@@ -405,7 +421,7 @@ namespace DeviceLibrary
}
break;
case MoveStep.H16_HomeReset:
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH))
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && NGDoor_Tray_Test_Reel)
{
ResetMoveInfo.log("NG口还是检测到料盘");
ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
......@@ -454,7 +470,7 @@ namespace DeviceLibrary
var ignorestring = "[" + crc.GetString(L.ignored, "已忽略") + "]";
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck && IOValue(IO_Type.NGDoor_Open).Equals(IO_VALUE.HIGH))
if (!IgnoreSafecheck)// && IOValue(IO_Type.NGDoor_Open).Equals(IO_VALUE.HIGH))
{
ok = false;
DeviceSuddenStop();
......
......@@ -233,7 +233,7 @@ namespace DeviceLibrary
break;
case MoveStep.NGOUT_02:
ClampMoveInfo.NextMoveStep(MoveStep.NGOUT_03);
if (IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.LOW))
if (!NGDoor_Tray_Test_Reel)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "传感器X29未检测到单料口料盘."), MsgLevel.alarm);
Msg.add(ClampMoveInfo.MoveParam.NgMsg, MsgLevel.warning);
......@@ -242,11 +242,18 @@ namespace DeviceLibrary
break;
case MoveStep.NGOUT_03:
Msg.add(ClampMoveInfo.MoveParam.NgMsg, MsgLevel.warning);
if (IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH))
if (NGDoor_Tray_Test_Reel)
{
Msg.add(crc.GetString(L.please_take_ngdoor_reel, "等待取走单口料盘"), MsgLevel.alarm);
if (ConfigHelper.Config.Get("CamTestReel_Ability", false))
{
ClampMoveInfo.NextMoveStep(MoveStep.NGOUT_03);
ClampMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
else {
RobotManage.UserPause("等待取走单口料盘");
}
}
else
{
ClampMoveInfo.NextMoveStep(MoveStep.NGOUT_04);
......@@ -264,7 +271,7 @@ namespace DeviceLibrary
}
break;
case MoveStep.NGOUT_05:
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH))
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && NGDoor_Tray_Test_Reel)
{
ClampMoveInfo.log("NG口还是检测到料盘");
ClampMoveInfo.NextMoveStep(MoveStep.NGOUT_03);
......@@ -305,7 +312,16 @@ namespace DeviceLibrary
break;
}
}
bool NGDoor_Tray_Test_Reel
{
get
{
if (ConfigHelper.Config.Get("CamTestReel_Ability", false))
return IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH) || CodeManager.TestHasReel(CodeManager.hikNameList[0]);
else
return IOValue(IO_Type.NGDoor_Tray_Check).Equals(IO_VALUE.HIGH);
}
}
private int GetWidth()
{
if(IOManager.IOValue(IO_Type.WidthCheck_15).Equals(IO_VALUE.HIGH))
......
......@@ -3,6 +3,9 @@ using log4net.Config;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
......@@ -28,6 +31,50 @@ namespace TheMachine
//datatxt = datatxt.Substring(3, 8);
//double.TryParse(datatxt, out double value);
//Console.WriteLine(value);
/*
int ff = 0;
var f = @"D:\rick\vs\SO1069MIMO_PLUS\Image_20220511153145272.bmp";
var bmp = new Bitmap(f);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var b = new Bitmap(bmp.Width/2, bmp.Height/2,bmp.PixelFormat);
using (var g = Graphics.FromImage(b))
{
g.InterpolationMode = InterpolationMode.Low;
g.DrawImage(bmp, 0, 0, b.Width, b.Height);
}
var bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, b.PixelFormat);
var Pixels = new byte[b.Width * b.Height * 3];
// Copy data from pointer to array
Marshal.Copy(bd.Scan0, Pixels, 0, Pixels.Length);
for (int x = 0; x < b.Width * b.Height * 3; x += 3)
{
//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 cr = (int)Pixels[x + 2];
var cg = (int)Pixels[x + 1];
var cb = (int)Pixels[x];
var h = ColorHelper.RgbToHsv(new ColorRGB(cr, cg, cb));
if (h.H >= 59 && h.H <= 61 && h.V >= 90 && h.S >= 90)
{
ff++;
//Marshal.WriteByte(bd.Scan0, x,0);
//Marshal.WriteByte(bd.Scan0, x+1, 0);
//Marshal.WriteByte(bd.Scan0, x+2, 255);
}
}
b.UnlockBits(bd);
stopwatch.Stop();
var t = stopwatch.ElapsedMilliseconds / 1000d;
b.Save(@"D:\rick\vs\SO1069MIMO_PLUS\11-57-09-156_11.bmp");
*/
_ = new Mutex(true, Application.ProductName, out bool ret);
if (!ret)
......
......@@ -38,6 +38,7 @@ namespace TheMachine
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.tp = new System.Windows.Forms.TableLayoutPanel();
this.cb_usefixpos = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.tp.SuspendLayout();
this.SuspendLayout();
//
......@@ -145,9 +146,21 @@ namespace TheMachine
this.cb_usefixpos.Text = "启用校准库位";
this.cb_usefixpos.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(356, 65);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(102, 48);
this.button1.TabIndex = 7;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Visible = false;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// SettingControl
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Controls.Add(this.button1);
this.Controls.Add(this.tp);
this.Name = "SettingControl";
this.Size = new System.Drawing.Size(1024, 740);
......@@ -168,5 +181,6 @@ namespace TheMachine
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.TableLayoutPanel tp;
private System.Windows.Forms.CheckBox cb_usefixpos;
private System.Windows.Forms.Button button1;
}
}
......@@ -120,5 +120,10 @@ namespace TheMachine
var t = HumitureController.LastData;
lbl_hmdstate.Text += $"{crc.GetString(L.humidity, "温度")}:{t.Temperate}℃, {crc.GetString(L.humidity, "湿度")}:{t.Humidity}%";
}
private void button1_Click_1(object sender, EventArgs e)
{
Task.Run(()=>CodeManager.TestHasReel(CodeManager.hikNameList[0]));
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!