Commit 36760465 张东亮

检测料盘图片采集异常问题

1 个父辈 51065abc
...@@ -22,8 +22,8 @@ namespace DeviceLibrary ...@@ -22,8 +22,8 @@ namespace DeviceLibrary
{ {
public class CodeManager public class CodeManager
{ {
public static string CodeType = ConfigHelper.Config.Get(Setting_Init.CodeType,"QR Code"); public static string CodeType = ConfigHelper.Config.Get(Setting_Init.CodeType, "QR Code");
private static int QRCodeCount = ConfigHelper.Config.Get(Setting_Init.QRCodeCount,3); private static int QRCodeCount = ConfigHelper.Config.Get(Setting_Init.QRCodeCount, 3);
private static int CodeTimeOut = ConfigHelper.Config.Get(Setting_Init.CodeTimeOut, 1000); private static int CodeTimeOut = ConfigHelper.Config.Get(Setting_Init.CodeTimeOut, 1000);
public static List<string> cameraNameList = new List<string>(); public static List<string> cameraNameList = new List<string>();
public static List<string> codeTypeList = new List<string>(); public static List<string> codeTypeList = new List<string>();
...@@ -170,7 +170,7 @@ namespace DeviceLibrary ...@@ -170,7 +170,7 @@ namespace DeviceLibrary
LoadCamera(true); LoadCamera(true);
return; return;
} }
if (idx==0) if (idx == 0)
camera_event?.Invoke(null, bmp); camera_event?.Invoke(null, bmp);
LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码"); LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码");
string r = ""; string r = "";
...@@ -183,7 +183,7 @@ namespace DeviceLibrary ...@@ -183,7 +183,7 @@ namespace DeviceLibrary
List<CodeInfo> cc = new List<CodeInfo>(); List<CodeInfo> cc = new List<CodeInfo>();
cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam); cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
if (cc != null && cc.Count>0) if (cc != null && cc.Count > 0)
{ {
lock (codeList) lock (codeList)
{ {
...@@ -237,27 +237,30 @@ namespace DeviceLibrary ...@@ -237,27 +237,30 @@ namespace DeviceLibrary
} }
catch (AccessViolationException e) catch (AccessViolationException e)
{ {
LogUtil.error( " 扫码出现AccessViolationException异常:" + e.ToString()); LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常"); //throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect(); // GC.Collect();
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error( " 扫码出错:" + ex.ToString()); LogUtil.error(" 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错"); //throw new Exception("扫码出错");
} }
return codeList; return codeList;
} }
static bool lastHasReel = false; static bool lastHasReel = false;
public static bool? TestHasRight=null; public static bool? TestHasRight = null;
static object testLocObj = new object();
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static bool? TestHasReel(string cameraName,out string srcimg,out string prcimg) public static bool? TestHasReel(string cameraName, out string srcimg, out string prcimg)
{ {
srcimg = ""; srcimg = "";
prcimg = ""; prcimg = "";
int retrytime = 0; int retrytime = 0;
if (Monitor.TryEnter(testLocObj))
{
retry: retry:
string logtxt = $"【" + cameraName + "】开始取图片测试是否有料盘"+"\r\n"; string logtxt = $"【" + cameraName + "】开始取图片测试是否有料盘" + "\r\n";
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
Bitmap bmp = null; Bitmap bmp = null;
try try
...@@ -273,10 +276,10 @@ namespace DeviceLibrary ...@@ -273,10 +276,10 @@ namespace DeviceLibrary
//LoadCamera(true); //LoadCamera(true);
LogUtil.info($"bitmap为空重试第{retrytime}次"); LogUtil.info($"bitmap为空重试第{retrytime}次");
Thread.Sleep(500); Thread.Sleep(2000);
goto retry; goto retry;
} }
logtxt +=$"【" + cameraName + "】获取到图像"+"\r\n"; logtxt += $"【" + cameraName + "】获取到图像" + "\r\n";
int totalcover = ConfigHelper.Config.Get("CamTestReel_totalcover", 69577); int totalcover = ConfigHelper.Config.Get("CamTestReel_totalcover", 69577);
int hl = ConfigHelper.Config.Get("CamTestReel_HL", 40); int hl = ConfigHelper.Config.Get("CamTestReel_HL", 40);
int hh = ConfigHelper.Config.Get("CamTestReel_HH", 70); int hh = ConfigHelper.Config.Get("CamTestReel_HH", 70);
...@@ -287,8 +290,8 @@ namespace DeviceLibrary ...@@ -287,8 +290,8 @@ namespace DeviceLibrary
double threshold = ConfigHelper.Config.Get("CamTestReel_threshold", 0.6); double threshold = ConfigHelper.Config.Get("CamTestReel_threshold", 0.6);
if (ConfigHelper.Config.Get("CamTestReel_debug",false)) if (ConfigHelper.Config.Get("CamTestReel_debug", false))
srcimg= SaveImageToFile("test", cameraName, bmp); srcimg = SaveImageToFile("test", cameraName, bmp);
var b = new Bitmap(bmp.Width / 2, bmp.Height / 2, bmp.PixelFormat); var b = new Bitmap(bmp.Width / 2, bmp.Height / 2, bmp.PixelFormat);
...@@ -313,11 +316,12 @@ namespace DeviceLibrary ...@@ -313,11 +316,12 @@ namespace DeviceLibrary
rois[0].RoiPath.Add(new Point(0, bmp.Height)); rois[0].RoiPath.Add(new Point(0, bmp.Height));
} }
bool hasReel=false; bool hasReel = false;
for (int i = 0; i < rois.Count; i++) { for (int i = 0; i < rois.Count; i++)
{
double maskcout = 0; double maskcout = 0;
var roi = rois[i]; var roi = rois[i];
var rp = roi.RoiPath.Select(r=>new Point(r.X/2,r.Y/2)).ToList(); var rp = roi.RoiPath.Select(r => new Point(r.X / 2, r.Y / 2)).ToList();
var fp = GetFilledPoints(rp); var fp = GetFilledPoints(rp);
var nfp = fp.Where(f => IsPointInPath(f.X, f.Y, rp)).ToList(); var nfp = fp.Where(f => IsPointInPath(f.X, f.Y, rp)).ToList();
foreach (var xy in nfp) foreach (var xy in nfp)
...@@ -374,13 +378,15 @@ namespace DeviceLibrary ...@@ -374,13 +378,15 @@ namespace DeviceLibrary
}*/ }*/
b.UnlockBits(bd); b.UnlockBits(bd);
if (hasReel != lastHasReel) { if (hasReel != lastHasReel)
{
lastHasReel = hasReel; lastHasReel = hasReel;
}else if (!ConfigHelper.Config.Get("CamTestReel_debug", false)) }
else if (!ConfigHelper.Config.Get("CamTestReel_debug", false))
logtxt = ""; logtxt = "";
if (ConfigHelper.Config.Get("CamTestReel_debug", false) || (TestHasRight.HasValue && TestHasRight.Value!= hasReel)) if (ConfigHelper.Config.Get("CamTestReel_debug", false) || (TestHasRight.HasValue && TestHasRight.Value != hasReel))
prcimg= SaveImageToFile("test2", cameraName, b); prcimg = SaveImageToFile("test2", cameraName, b);
b.Dispose(); b.Dispose();
TestHasRight = null; TestHasRight = null;
return hasReel; return hasReel;
...@@ -402,8 +408,12 @@ namespace DeviceLibrary ...@@ -402,8 +408,12 @@ namespace DeviceLibrary
bmp.Dispose(); bmp.Dispose();
if (!string.IsNullOrEmpty(logtxt)) if (!string.IsNullOrEmpty(logtxt))
LogUtil.error(logtxt); LogUtil.error(logtxt);
Monitor.Exit(testLocObj);
} }
} }
else
return null;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -412,7 +422,8 @@ namespace DeviceLibrary ...@@ -412,7 +422,8 @@ namespace DeviceLibrary
/// <param name="pX"></param> /// <param name="pX"></param>
/// <param name="pY"></param> /// <param name="pY"></param>
/// <returns>x,y</returns> /// <returns>x,y</returns>
static (int, int) PointRoate270(int imgWidth, int imgHeight, int pX, int pY) { static (int, int) PointRoate270(int imgWidth, int imgHeight, int pX, int pY)
{
int x = pY; int x = pY;
int y = imgWidth - pX; int y = imgWidth - pX;
return (x, y); return (x, y);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!