Commit 7f4d37f8 刘韬

更新点料算法,二维码识别算法

1 个父辈 9ad615d5
...@@ -510,7 +510,17 @@ namespace OnlineStore.AutoCountClient ...@@ -510,7 +510,17 @@ namespace OnlineStore.AutoCountClient
else { else {
lblXrayWork.Text = "警告:点料过程中,请勿开门"; lblXrayWork.Text = "警告:点料过程中,请勿开门";
} }
foreach (var cr in CodeManager.CamErrCount)
{
if (cr.Value > 5)
{
robot.inputEquip.MoveStop = true;
lblXrayWork.Text = $"扫码相机({cr.Key})拍照连续失败,请及时处理。";
lblXrayWork.Visible = true;
robot.inputEquip.Alarm(AlarmType.SuddenStop);
break;
}
}
string canScanCode = ""; string canScanCode = "";
lblStatus.Text = robot.GetRunStr() + canScanCode; lblStatus.Text = robot.GetRunStr() + canScanCode;
......
...@@ -99,6 +99,7 @@ namespace OnlineStore.AutoCountClient ...@@ -99,6 +99,7 @@ namespace OnlineStore.AutoCountClient
} }
if (!isShow) if (!isShow)
{ {
Environment.CurrentDirectory = Application.StartupPath;
XmlConfigurator.Configure(); XmlConfigurator.Configure();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
......
...@@ -252,7 +252,7 @@ namespace CodeLibrary ...@@ -252,7 +252,7 @@ namespace CodeLibrary
{ {
if (HDCodeLearnHelper.DefaultBitmap != null) { if (HDCodeLearnHelper.DefaultBitmap != null) {
List<CodeInfo> codeList = EyemDecode.Decoder(ref HDCodeLearnHelper.DefaultBitmap); List<CodeInfo> codeList = EyemDecode2.Decoder(ref HDCodeLearnHelper.DefaultBitmap);
HDCodeLearnHelper.DefaultBitmap.Dispose(); HDCodeLearnHelper.DefaultBitmap.Dispose();
ShowCode(codeList); ShowCode(codeList);
return; return;
...@@ -303,7 +303,7 @@ namespace CodeLibrary ...@@ -303,7 +303,7 @@ namespace CodeLibrary
//for (int i = 0; i < 1000; i++) //for (int i = 0; i < 1000; i++)
//{ //{
Bitmap b = (Bitmap)pictureBox1.Image.Clone(); Bitmap b = (Bitmap)pictureBox1.Image.Clone();
codeList = EyemDecode.Decoder(ref b); codeList = EyemDecode2.Decoder(ref b);
b.Dispose(); b.Dispose();
Thread.Sleep(10); Thread.Sleep(10);
//} //}
......
...@@ -552,7 +552,7 @@ namespace CodeLibrary ...@@ -552,7 +552,7 @@ namespace CodeLibrary
string[] strarray = code.Split(';'); string[] strarray = code.Split(';');
if (strarray.Length == 4) if (strarray.Length == 4)
{ {
if (strarray[0].StartsWith("L") && if (//strarray[0].StartsWith("L") &&
strarray[1].StartsWith("E") && strarray[1].StartsWith("E") &&
strarray[2].StartsWith("B")) strarray[2].StartsWith("B"))
{ {
......
...@@ -3,6 +3,7 @@ using System; ...@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
...@@ -12,14 +13,32 @@ using static Asa.eyemLib; ...@@ -12,14 +13,32 @@ using static Asa.eyemLib;
namespace CodeLibrary namespace CodeLibrary
{ {
public unsafe class EyemDecode
public unsafe class EyemDecode2
{ {
public static string codeType = "QR_CODE|DATA_MATRIX";
public static int Init()
{
if (!File.Exists(".\\darknet\\detect-tiny.cfg") || !File.Exists(".\\darknet\\detect-tiny.weights"))
{
throw new Exception("找不到darknet\\detect-tiny.cfg|detect-tiny.weights");
}
return eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "");
}
static EyemDecode2()
{
Init();
}
//public static List<CodeInfo> Decoder(ref Bitmap bmap, string file = null) {
// return Decoder(ref bmap, file);
//}
/// <summary> /// <summary>
/// 识别图像二维码 /// 识别图像二维码
/// </summary> /// </summary>
/// <param name="bmap">需要手动释放这个bitmap</param> /// <param name="bmap">需要手动释放这个bitmap</param>
/// <param name="file">如果传文件的话,bmp传null</param>
/// <returns></returns> /// <returns></returns>
public static List<CodeInfo> Decoder(ref Bitmap bmap,string file=null) public static List<CodeInfo> Decoder(ref Bitmap bmap, string file = null)
{ {
List<CodeInfo> codelist = new List<CodeInfo>(); List<CodeInfo> codelist = new List<CodeInfo>();
...@@ -32,16 +51,16 @@ namespace CodeLibrary ...@@ -32,16 +51,16 @@ namespace CodeLibrary
if (file == null) if (file == null)
{ {
Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height); Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat); bitmapData = bmap.LockBits(rect, ImageLockMode.ReadWrite, bmap.PixelFormat);
eyemImage = new EyemImage(); eyemImage = new EyemImage();
eyemImage.ucpImage = bitmapData.Scan0; eyemImage.ucpImage = bitmapData.Scan0;
eyemImage.iWidth = rect.Width; eyemImage.iWidth = rect.Width;
eyemImage.iHeight = rect.Height; eyemImage.iHeight = rect.Height;
//eyemImage.iChannel = 0;
eyemImage.iChannels = 1; eyemImage.iChannels = 1;
eyemImage.iDepth = 0; eyemImage.iDepth = 0;
} }
else { else
{
eyemImageRead(file, -1, out eyemImage); eyemImageRead(file, -1, out eyemImage);
} }
...@@ -51,14 +70,18 @@ namespace CodeLibrary ...@@ -51,14 +70,18 @@ namespace CodeLibrary
eyemRect.iYs = 0; eyemRect.iYs = 0;
eyemRect.iWidth = eyemImage.iWidth; eyemRect.iWidth = eyemImage.iWidth;
eyemRect.iHeight = eyemImage.iHeight; eyemRect.iHeight = eyemImage.iHeight;
string codeType = "QR_CODE|DATA_MATRIX";//QRCode //string codeType = "QR_CODE|DATA_MATRIX"; //QRCode
int ipNum; int ipNum;
EyemBarCode* tpResults; EyemBarCode* tpResults;
DataCodeHandle hObject = null; DataCodeHandle hObject = null;
try try
{ {
int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, 11, 5, 128, 215); EyemImage tpDstImg;
int result = eyemDetectAndDecodeUseNN(eyemImage, eyemRect, out hObject, out tpResults, out ipNum, out _);
// eyemImageFree(ref tpDstImg);
//hObject.Dispose();
//int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, iBlockSize, iRangeC, iSymbolMin, iSymbolMax);
HDLogUtil.info($"eyemDetectAndDecode:{result},ipNum:{ipNum}"); HDLogUtil.info($"eyemDetectAndDecode:{result},ipNum:{ipNum}");
if (result != 0 || ipNum == 0) if (result != 0 || ipNum == 0)
return codelist; return codelist;
...@@ -70,11 +93,15 @@ namespace CodeLibrary ...@@ -70,11 +93,15 @@ namespace CodeLibrary
codelist.Add(ci); codelist.Add(ci);
} }
} }
catch (Exception ex)
{
HDLogUtil.error($"" + ex.ToString());
}
finally finally
{ {
if (hObject != null) if (hObject != null)
hObject.Dispose(); hObject.Dispose();
if (bitmapData!=null) if (bitmapData != null)
bmap.UnlockBits(bitmapData); bmap.UnlockBits(bitmapData);
if (file != null) if (file != null)
eyemImageFree(ref eyemImage); eyemImageFree(ref eyemImage);
...@@ -88,9 +115,8 @@ namespace CodeLibrary ...@@ -88,9 +115,8 @@ namespace CodeLibrary
//eyemImageFree(eyemImage.ucpImage); //eyemImageFree(eyemImage.ucpImage);
return codelist; return codelist;
} }
/*
//释放解码句柄 //释放解码句柄
private class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid public class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{ {
public DataCodeHandle() : base(true) { } public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle() protected override bool ReleaseHandle()
...@@ -99,8 +125,30 @@ namespace CodeLibrary ...@@ -99,8 +125,30 @@ namespace CodeLibrary
} }
} }
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown=1, double dToleErr = 0.5, double dMinorStep = 1.0); private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 1, double dToleErr = 0.5, double dMinorStep = 1.0);
/*
* 参数说明
tpImage 输入图像,可使用”eyemImageRead“接口读取图片(需与“eyemImageFree”配合使用),也可直接创建EyemImage对象。
tpRoi 感兴趣区域,尺寸不能小于iSymbolMax。
fileName 文件名,可不填。
strCodeType 所要识别条码类型,“QRCode|DataMatrix|CODE_128”等等。
hObject 结果释放句柄,配合eyemDetectAndDecodeFree使用
tpResults 识别结果
ipNum 结果数量
bUseNiBlack 使用NiBlack二值化,默认值 false。
iBlockSize 定位块大小(奇数),略大于最大定位块(只二维码),佳世达一般设置为11。
iRangeC 搜索范围,范围越大识别越好时间也相应越长,佳世达一般设置为5。
iSymbolMin 最小二维码尺寸,默认128。
iSymbolMax 最大二维码尺寸,佳世达一般设置为215。
dScaleUpAndDown 缩放,<1表示缩小,>1表示放大,=1表示不缩放
dToleErr 最大允许误差默认50%,越小越严格但可能会识别不到。
dMinorStep 步进,默认1.0。
//返回值
-3 图像不存在
-1 内存不足
0 正常
-100 未识别到条码或参数设置不正确
*/
/// <summary> /// <summary>
/// 读取图像 /// 读取图像
/// </summary> /// </summary>
...@@ -114,23 +162,51 @@ namespace CodeLibrary ...@@ -114,23 +162,51 @@ namespace CodeLibrary
/// <summary> /// <summary>
/// 释放图像资源 /// 释放图像资源
/// </summary> /// </summary>
/// <param name="ipImage"></param> /// <param name="eyemImage"></param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(ref EyemImage eyemImage); public static extern void eyemImageFree(ref EyemImage eyemImage);
//释放工具 //释放解码句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject); private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
//基于深度学习读码程序(仅支持QR、DataMatrix)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, out EyemImage tpDstImg);
//加载模型配置文件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitNNDataCodeModel(string detectorConfigPath, string detectorModelPath, string superResolutionConfigPath, string superResolutionModelPath);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct EyemImage public struct EyemImage
{ {
public IntPtr ucpImage; // 地址 /// <summary>
public int iWidth; // 图像内存 x 方向大小 /// 地址
public int iHeight; // 图像内存 y 方向大小 /// </summary>
public IntPtr ucpImage;
/// <summary>
/// 图像内存 x 方向大小
/// </summary>
public int iWidth;
/// <summary>
/// 图像内存 y 方向大小
/// </summary>
public int iHeight;
/// <summary>
/// iDepth:
/// uint8_t 取值范围[0, 255], iDepth = 0(常用,解码图像一般为此种格式)
/// int8_t 取值范围[-128, 127], iDepth = 1
/// uint16_t 取值范围[0, 56635], iDepth = 2(常用,点料机图像一般为此种格式)
/// int16_t 取值范围[-32768, 32767], iDepth = 3
/// int32_t 取值范围[-2147483648, 2147483647], iDepth = 4
/// float_t 取值范围[-3.4028235E38, 3.4028235E38], iDepth = 5
/// double_t 取值范围[-1.7E-308, 1.7E+308], iDepth = 6
/// </summary>
public int iDepth; public int iDepth;
/// <summary>
/// 彩色图 iChannels=3或4(比RGB多了Alpha通道),一般为3
/// 灰度图 iChannels = 1
/// </summary>
public int iChannels; // 图像通道数 public int iChannels; // 图像通道数
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct EyemRect public struct EyemRect
...@@ -148,7 +224,7 @@ namespace CodeLibrary ...@@ -148,7 +224,7 @@ namespace CodeLibrary
public int iCenterY; // y坐标 public int iCenterY; // y坐标
public IntPtr hType; // 码类型 public IntPtr hType; // 码类型
public IntPtr hText; // 码内容 public IntPtr hText; // 码内容
}*/ }
} }
} }
...@@ -102,5 +102,6 @@ namespace OnlineStore.Common ...@@ -102,5 +102,6 @@ namespace OnlineStore.Common
/// </summary> /// </summary>
public static string UseLabel = "UseLabel"; public static string UseLabel = "UseLabel";
public static string OutReelCenterX = "OutReelCenterX";
} }
} }
...@@ -31,8 +31,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -31,8 +31,21 @@ namespace OnlineStore.DeviceLibrary
public string WorkShelfId = ""; public string WorkShelfId = "";
public bool AutoSendShelfOut = false; public bool AutoSendShelfOut = false;
private int LabelWaitMS = ConfigAppSettings.GetIntValue(Setting_Init.LabelWaitMS); private int LabelWaitMS = ConfigAppSettings.GetIntValue(Setting_Init.LabelWaitMS);
private int OutReelCenterX { get
{
var x = ConfigAppSettings.GetIntValue(Setting_Init.OutReelCenterX);
if (x == 0)
{
ConfigAppSettings.SaveValue(Setting_Init.OutReelCenterX, 2623);
x = 2623;
}
return x;
}
}
public OutputEquip(string cid, OutputEquip_Config config) public OutputEquip(string cid, OutputEquip_Config config)
{ {
var xxx = OutReelCenterX;
baseConfig = config; baseConfig = config;
this.DeviceID = config.Id; this.DeviceID = config.Id;
this.Config = config; this.Config = config;
......
...@@ -211,12 +211,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -211,12 +211,14 @@ namespace OnlineStore.DeviceLibrary
{ {
if (string.IsNullOrEmpty(MoveInfo.MoveParam.WareCode)) if (string.IsNullOrEmpty(MoveInfo.MoveParam.WareCode))
return; return;
int testCount = 1;
var cc = new List<CodeInfo>(); var cc = new List<CodeInfo>();
//var filename = "need"; //var filename = "need";
CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName); CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName);
saveone = true; saveone = true;
if (cc.Count == 0) if (cc.Count == 0)
{ {
testCount++;
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName); CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName);
} }
...@@ -224,7 +226,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -224,7 +226,7 @@ namespace OnlineStore.DeviceLibrary
{ {
MoveInfo.MoveParam.codePointer.X = cc[0].X; MoveInfo.MoveParam.codePointer.X = cc[0].X;
MoveInfo.MoveParam.codePointer.Y = cc[0].Y; MoveInfo.MoveParam.codePointer.Y = cc[0].Y;
WorkLog("取料:识别到二维码位置:X:" + MoveInfo.MoveParam.codePointer.X + ",Y:" + MoveInfo.MoveParam.codePointer.Y, 1); WorkLog($"取料:{testCount}次识别到二维码位置:X:" + MoveInfo.MoveParam.codePointer.X + ",Y:" + MoveInfo.MoveParam.codePointer.Y, 1);
} }
//else if (cc.Count > 1) { //else if (cc.Count > 1) {
...@@ -232,7 +234,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -232,7 +234,7 @@ namespace OnlineStore.DeviceLibrary
//} //}
else else
{ {
WorkLog("取料:2次没有识别到二维码", 1); WorkLog($"取料:{testCount}次没有识别到二维码", 1);
} }
doubleplate = false; doubleplate = false;
...@@ -771,14 +773,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -771,14 +773,14 @@ namespace OnlineStore.DeviceLibrary
//圆心位置x2230,y2115 //圆心位置x2230,y2115
var posL = false; var posL = false;
if (SecMoveInfo.MoveParam.codePointer.X < 2273 && SecMoveInfo.MoveParam.codePointer.Y < 1225+80) if (SecMoveInfo.MoveParam.codePointer.X > OutReelCenterX)//2623)// && SecMoveInfo.MoveParam.codePointer.Y < 1225+80)
{
posL = true;
}
if (SecMoveInfo.MoveParam.codePointer.X > 2273 && SecMoveInfo.MoveParam.codePointer.Y < 1225 - 80)
{ {
posL = true; posL = true;
} }
//if (SecMoveInfo.MoveParam.codePointer.X > 2623 && SecMoveInfo.MoveParam.codePointer.Y < 1225 - 80)
//{
// posL = true;
//}
if (SecMoveInfo.MoveParam.codePointer.Y == 0) if (SecMoveInfo.MoveParam.codePointer.Y == 0)
{ posL = false; } { posL = false; }
...@@ -799,13 +801,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -799,13 +801,13 @@ namespace OnlineStore.DeviceLibrary
/* /*
* R=Y_P3 * R=Y_P3
* L=Y_P4 * L=Y_P4
X0 Y0
___|___ ___|___
------\ / T \ ------\ / T \
XRAY出料口 ----- | L * R |-----Y0 圆心位置x2273,y1225 XRAY出料口 ----X0- | L * R |----- 圆心位置x2623,y933
------/ \ B / ------/ \ B /
~~~|~~~ ~~~|~~~
| |
*/ */
} }
else if (SecMoveInfo.IsTimeOut(120)) else if (SecMoveInfo.IsTimeOut(120))
......
...@@ -509,9 +509,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -509,9 +509,11 @@ namespace OnlineStore.DeviceLibrary
//转动线体 //转动线体
IOMove(IO_Type.O_ELine_InStop, IO_VALUE.LOW); IOMove(IO_Type.O_ELine_InStop, IO_VALUE.LOW);
IOMove(IO_Type.O_ELine_Run, IO_VALUE.HIGH); IOMove(IO_Type.O_ELine_Run, IO_VALUE.HIGH);
LogUtil.info(logName + $"step 1 O_ELine_Run:{IOValue(IO_Type.O_WLine_Run)},O_ELine_InStop:{IOValue(IO_Type.O_WLine_OutStop)}");
//等待进料检测信号 //等待进料检测信号
bool result = WaitIo(IO_Type.O_ELine_InCheck, IO_VALUE.HIGH, 600000, logName + "等待O_ELine_InCheck检测到料架"); bool result = WaitIo(IO_Type.O_ELine_InCheck, IO_VALUE.HIGH, 600000, logName + "等待O_ELine_InCheck检测到料架");
LogUtil.info(logName + $"step 2 O_ELine_Run:{IOValue(IO_Type.O_WLine_Run)},O_ELine_InStop:{IOValue(IO_Type.O_WLine_OutStop)}");
if (!result) if (!result)
{ {
...@@ -526,6 +528,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -526,6 +528,7 @@ namespace OnlineStore.DeviceLibrary
//等待500毫秒后停止转动 //等待500毫秒后停止转动
Thread.Sleep(5000); Thread.Sleep(5000);
LogUtil.info(logName + $"step 3 O_ELine_Run:{IOValue(IO_Type.O_WLine_Run)},O_ELine_InStop:{IOValue(IO_Type.O_WLine_OutStop)}");
IOMove(IO_Type.O_ELine_Run, IO_VALUE.LOW); IOMove(IO_Type.O_ELine_Run, IO_VALUE.LOW);
...@@ -562,7 +565,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -562,7 +565,7 @@ namespace OnlineStore.DeviceLibrary
internal void ShelfOutProcess(string id, string rfid) internal void ShelfOutProcess(string id, string rfid)
{ {
string logName = Name + "料串 "+rfid+"[" + Config.AgvOutName + "->AGV ] "; string logName = "ShelfOutProcess" + "料串 "+rfid+"[" + Config.AgvOutName + "->AGV ] ";
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
try try
...@@ -575,7 +578,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -575,7 +578,7 @@ namespace OnlineStore.DeviceLibrary
//出口阻挡下降,出口线体转动 //出口阻挡下降,出口线体转动
IOMove(IO_Type.O_WLine_OutStop, IO_VALUE.HIGH); IOMove(IO_Type.O_WLine_OutStop, IO_VALUE.HIGH);
IOMove(IO_Type.O_WLine_Run, IO_VALUE.HIGH); IOMove(IO_Type.O_WLine_Run, IO_VALUE.HIGH);
LogUtil.info(logName + $"step 1 O_WLine_Run:{IOValue(IO_Type.O_WLine_Run)},O_WLine_OutStop:{IOValue(IO_Type.O_WLine_OutStop)}");
bool result = WaitIo(IO_Type.O_WLine_OutCheck, IO_VALUE.LOW, 60000); bool result = WaitIo(IO_Type.O_WLine_OutCheck, IO_VALUE.LOW, 60000);
if (!result) if (!result)
{ {
...@@ -586,11 +589,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -586,11 +589,13 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(logName + " 已收到 O_WLine_OutCheck=LOW ,等待13000后停止转动 "); LogUtil.info(logName + " 已收到 O_WLine_OutCheck=LOW ,等待13000后停止转动 ");
} }
Thread.Sleep(13000); Thread.Sleep(13000);
LogUtil.info(logName + $"step 2 O_WLine_Run:{IOValue(IO_Type.O_WLine_Run)},O_WLine_OutStop:{IOValue(IO_Type.O_WLine_OutStop)}");
//停止转动 ,阻挡上升 //停止转动 ,阻挡上升
IOMove(IO_Type.O_WLine_OutStop, IO_VALUE.LOW); IOMove(IO_Type.O_WLine_OutStop, IO_VALUE.LOW);
//此处判断是否需要停止接料线体 //此处判断是否需要停止接料线体
IOMove(IO_Type.O_WLine_Run, IO_VALUE.LOW); IOMove(IO_Type.O_WLine_Run, IO_VALUE.LOW);
LogUtil.info(logName + $"step 3 O_WLine_Run:{IOValue(IO_Type.O_WLine_Run)},O_WLine_OutStop:{IOValue(IO_Type.O_WLine_OutStop)}");
AgvClient.SetStatus(Config.AgvOutName, "", ClientAction.FinishLeave, ClientLevel.High, true); AgvClient.SetStatus(Config.AgvOutName, "", ClientAction.FinishLeave, ClientLevel.High, true);
Thread.Sleep(3000); Thread.Sleep(3000);
......
...@@ -145,7 +145,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -145,7 +145,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop); MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:停止入口皮带线,中间皮带线"); WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW); IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH, 600);//皮带延时,控制料盘位置 IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH, 550);//皮带延时,控制料盘位置
} }
else if (MoveInfo.IsTimeOut(20)) else if (MoveInfo.IsTimeOut(20))
{ {
...@@ -782,25 +782,30 @@ namespace OnlineStore.DeviceLibrary ...@@ -782,25 +782,30 @@ namespace OnlineStore.DeviceLibrary
resfile = ""; resfile = "";
//tpDstImg = new API.EyemImage(); //tpDstImg = new API.EyemImage();
try try
{ {
string countStr = ""; Bitmap dst = null;
int[] countStr = new int[4];
int result = 0; int result = 0;
CountParam.SignType type = param.Sign; CountParam.SignType type = param.Sign;
int threshold = param.Threshold; int threshold = param.Threshold;
int windowsize = param.WindowSize; ; int windowsize = param.WindowSize; ;
if (param.Sign == CountParam.SignType.AUTO) if (param.Sign == CountParam.SignType.AUTO)
{ {
result = XrayImage.GetLocalCount(fileP, 200, out countStr, out _); result = XrayImage.GetLocalCount(fileP, 200, out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + countStr + "】"); LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
} }
else { else {
result = XrayImage.GetLocalCountIrregular(fileP, 200, type.ToString(), out countStr, out _); result = XrayImage.GetLocalCountIrregular(fileP, 200, type.ToString(), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + countStr + "】"); LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
if (dst != null)
{
dst.Save("ResOut\\" + Path.GetFileNameWithoutExtension(fileP) + "-Mark.png");
dst.Dispose();
} }
if (countStr != null) if (countStr != null)
{ {
string[] array = countStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); count = (from a in countStr where a > 0 select a).FirstOrDefault();
count = (from a in array where int.TryParse(a, out _) && int.Parse(a) > 0 select int.Parse(a)).FirstOrDefault();
} }
else { else {
count = 0; count = 0;
...@@ -832,25 +837,30 @@ namespace OnlineStore.DeviceLibrary ...@@ -832,25 +837,30 @@ namespace OnlineStore.DeviceLibrary
//tpDstImg = new API.EyemImage(); //tpDstImg = new API.EyemImage();
try try
{ {
string countStr = ""; Bitmap dst = null;
int[] countStr = new int[4];
int result = 0; int result = 0;
CountParam.SignType type = param.Sign; CountParam.SignType type = param.Sign;
int threshold = param.Threshold; int threshold = param.Threshold;
int windowsize = param.WindowSize; ; int windowsize = param.WindowSize; ;
if (param.Sign == CountParam.SignType.AUTO) if (param.Sign == CountParam.SignType.AUTO)
{ {
result = XrayImage.GetLocalCount(eyemImage, 200,Path.GetFileNameWithoutExtension(fileP), out countStr, out _); result = XrayImage.GetLocalCount(eyemImage, 250,Path.GetFileNameWithoutExtension(fileP), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + countStr + "】"); LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
} }
else else
{ {
result = XrayImage.GetLocalCountIrregular(eyemImage, 200,Path.GetFileNameWithoutExtension(fileP), type.ToString(), out countStr, out _); result = XrayImage.GetLocalCountIrregular(eyemImage, 250,Path.GetFileNameWithoutExtension(fileP), type.ToString(), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + countStr + "】"); LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
if (dst != null)
{
dst.Save("ResOut\\" + Path.GetFileNameWithoutExtension(fileP) + "-Mark.png");
dst.Dispose();
} }
if (countStr != null) if (countStr != null)
{ {
string[] array = countStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); count = (from a in countStr where a > 0 select a).FirstOrDefault();
count = (from a in array where int.TryParse(a, out _) && int.Parse(a) > 0 select int.Parse(a)).FirstOrDefault();
} }
else else
{ {
......
...@@ -100,12 +100,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -100,12 +100,16 @@ namespace OnlineStore.DeviceLibrary
} }
private static int ScanCount = 0; private static int ScanCount = 0;
private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount); private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount);
public static Dictionary<string, int> CamErrCount = new Dictionary<string, int>();
public static List<string> CameraScan(string deviceName, params string[] cameraList) { public static List<string> CameraScan(string deviceName, params string[] cameraList) {
return CameraScan(deviceName, out _, true, cameraList); return CameraScan(deviceName, out _, true, cameraList);
} }
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(string deviceName, out List<CodeInfo> ccall, bool nosave,params string[] cameraList) public static List<string> CameraScan(string deviceName, out List<CodeInfo> ccall, bool nosave,params string[] cameraList)
{ {
if (!CamErrCount.ContainsKey(deviceName))
CamErrCount.Add(deviceName, 0);
List<string> codeList = new List<string>(); List<string> codeList = new List<string>();
List<CodeInfo> cc; List<CodeInfo> cc;
ccall = new List<CodeInfo>(); ccall = new List<CodeInfo>();
...@@ -140,14 +144,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -140,14 +144,16 @@ namespace OnlineStore.DeviceLibrary
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp); ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp);
if (ho_Image == null) if (ho_Image == null)
{ {
CamErrCount[deviceName]++;
LogUtil.error(deviceName + " 【" + cameraName + "】第2次取图片失败[" + Camera._cam.ErrInfo + "],关闭相机"); LogUtil.error(deviceName + " 【" + cameraName + "】第2次取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
continue; continue;
} }
} }
CamErrCount[deviceName] = 0;
LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码"); LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码");
string r = ""; string r = "";
List<CodeInfo> tlci = EyemDecode.Decoder(ref bmp); List<CodeInfo> tlci = EyemDecode2.Decoder(ref bmp);
foreach (CodeInfo code in tlci) { foreach (CodeInfo code in tlci) {
LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr); LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
...@@ -302,9 +308,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -302,9 +308,9 @@ namespace OnlineStore.DeviceLibrary
foreach (string code in codes) foreach (string code in codes)
{ {
string[] strarray = code.Split(';'); string[] strarray = code.Split(';');
if (strarray.Length == 4) if (strarray.Length >= 4)
{ {
if (strarray[0].StartsWith("L") && if (//strarray[0].StartsWith("L") &&
strarray[1].StartsWith("E") && strarray[1].StartsWith("E") &&
strarray[2].StartsWith("B")) strarray[2].StartsWith("B"))
{ {
...@@ -391,7 +397,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -391,7 +397,7 @@ namespace OnlineStore.DeviceLibrary
} }
code = ReplaceCode(code); code = ReplaceCode(code);
if (String.IsNullOrEmpty(code)) if (string.IsNullOrEmpty(code))
{ {
return ""; return "";
} }
...@@ -406,10 +412,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -406,10 +412,11 @@ namespace OnlineStore.DeviceLibrary
string[] codearray = ReplaceCode(cc).Split(';'); string[] codearray = ReplaceCode(cc).Split(';');
if (codearray.Length >= 4) if (codearray.Length >= 4)
{ {
if (codearray[0].StartsWith("L") && if (//codearray[0].StartsWith("L") &&
codearray[1].StartsWith("E") && codearray[1].StartsWith("E") &&
codearray[2].StartsWith("B") && codearray[2].StartsWith("B")
codearray[2].Length >= 13) //&& codearray[2].Length >= 13
)
// if (codearray[2].StartsWith("B") && codearray[2].Length >= 13 && codearray[3].StartsWith("R")) // if (codearray[2].StartsWith("B") && codearray[2].Length >= 13 && codearray[3].StartsWith("R"))
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!