Commit 35dcc71a 刘韬

优化超时时间设定和日志输出

1 个父辈 350ea013
using HalconDotNet; using HalconDotNet;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
...@@ -86,7 +87,9 @@ namespace ScanCodeServer ...@@ -86,7 +87,9 @@ namespace ScanCodeServer
} }
public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount, int timeOut = 1500) public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount, int timeOut = 1500)
{ {
Common.log.Debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始"); Common.log.Debug("开始 DecodeCode[" + symbolType + "][" + codeCount + "][" + hv_model_path + "]");
Stopwatch sw = new Stopwatch();
sw.Start();
List<CodeInfo> codeList = new List<CodeInfo>(); List<CodeInfo> codeList = new List<CodeInfo>();
try try
{ {
...@@ -150,7 +153,9 @@ namespace ScanCodeServer ...@@ -150,7 +153,9 @@ namespace ScanCodeServer
} }
} }
} }
Common.log.Debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:" + codeList.Count); sw.Stop();
Common.log.Debug("结束 DecodeCode[" + symbolType + "][" + codeCount + "]["+ (sw.ElapsedMilliseconds/1000f).ToString("0.00")+ "]返回数量:" + codeList.Count);
if (hv_Area != null) if (hv_Area != null)
{ {
hv_Area.UnPinTuple(); hv_Area.UnPinTuple();
...@@ -311,6 +316,9 @@ namespace ScanCodeServer ...@@ -311,6 +316,9 @@ namespace ScanCodeServer
} }
public static List<CodeInfo> DecodeBarCode(HObject ho_Image) public static List<CodeInfo> DecodeBarCode(HObject ho_Image)
{ {
Common.log.Debug("开始 DecodeCode[barcode]");
Stopwatch sw = new Stopwatch();
sw.Start();
List<CodeInfo> codeList = new List<CodeInfo>(); List<CodeInfo> codeList = new List<CodeInfo>();
try try
{ {
...@@ -368,6 +376,10 @@ namespace ScanCodeServer ...@@ -368,6 +376,10 @@ namespace ScanCodeServer
} }
} }
} }
sw.Stop();
Common.log.Debug("结束 DecodeCode[barcode][" + (sw.ElapsedMilliseconds / 1000f).ToString("0.00") + "]返回数量:" + codeList.Count);
HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle); HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle);
if (hv_Area != null) if (hv_Area != null)
{ {
......
...@@ -22,7 +22,12 @@ namespace ScanCodeServer ...@@ -22,7 +22,12 @@ namespace ScanCodeServer
return; return;
} }
Config.LoadMyConfig(new Setting().GetType()); Config.LoadMyConfig(new Setting().GetType());
var prop = System.Diagnostics.Process.GetCurrentProcess();
prop.PriorityClass = Setting.ProcessPriorityClass;
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Form1());
......
using ConfigHelper; using ConfigHelper;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -14,5 +15,17 @@ namespace ScanCodeServer ...@@ -14,5 +15,17 @@ namespace ScanCodeServer
[MyConfigComment("emphasize")] [MyConfigComment("emphasize")]
public static MyConfig<bool> HOperatorSet_enable_emphasize = true; public static MyConfig<bool> HOperatorSet_enable_emphasize = true;
[MyConfigComment("scale_image_range")]
public static MyConfig<bool> HOperatorSet_enable_scale_image = false;
[MyConfigComment("scale_image_mult")]
public static MyConfig<int> scale_image_mult = 2;
[MyConfigComment("scale_image_add")]
public static MyConfig<int> scale_image_add = 5;
[MyConfigComment("进程优先级")]
public static MyConfig<ProcessPriorityClass> ProcessPriorityClass = System.Diagnostics.ProcessPriorityClass.High;
} }
} }
...@@ -10,6 +10,7 @@ using System.Text; ...@@ -10,6 +10,7 @@ using System.Text;
using System.Drawing; using System.Drawing;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Diagnostics;
namespace ScanCodeServer namespace ScanCodeServer
{ {
...@@ -51,11 +52,18 @@ namespace ScanCodeServer ...@@ -51,11 +52,18 @@ namespace ScanCodeServer
string[] codeTypeList = remoteDecodeParam.codeTypeList; string[] codeTypeList = remoteDecodeParam.codeTypeList;
int codeCount = remoteDecodeParam.codeCount; int codeCount = remoteDecodeParam.codeCount;
int timeout = remoteDecodeParam.timeout; int timeout = remoteDecodeParam.timeout;
Common.log.Info($"参数:codeTypeList:{string.Join(",",codeTypeList)}, codeCount:{codeCount}, timeout:{timeout}"); Common.log.Info($"<===========================>");
Common.log.Info($"开始扫码参数:codeTypeList:{string.Join(",",codeTypeList)}, codeCount:{codeCount}, timeout:{timeout},emphasize:{Setting.HOperatorSet_enable_emphasize},scale_image:{Setting.HOperatorSet_enable_scale_image}");
Stopwatch sw = new Stopwatch();
sw.Start();
Result res = new Result(); Result res = new Result();
if (Setting.HOperatorSet_enable_emphasize) if (Setting.HOperatorSet_enable_emphasize)
HOperatorSet.Emphasize(ho_Image, out ho_Image, 3, 3, 1); HOperatorSet.Emphasize(ho_Image, out ho_Image, 3, 3, 1);
if (Setting.HOperatorSet_enable_scale_image)
HOperatorSet.ScaleImage(ho_Image, out ho_Image, new HTuple(Setting.scale_image_mult), new HTuple(Setting.scale_image_add));
List<string> code = new List<string>(); List<string> code = new List<string>();
Task[] t = new Task[codeTypeList.Length]; Task[] t = new Task[codeTypeList.Length];
int ti = 0; int ti = 0;
...@@ -116,10 +124,14 @@ namespace ScanCodeServer ...@@ -116,10 +124,14 @@ namespace ScanCodeServer
}); });
ti++; ti++;
} }
Task.WaitAll(t,1000*10); var r = Task.WaitAll(t, timeout+1000 * 5);
sw.Stop();
ho_Image.Dispose(); ho_Image.Dispose();
if (bitmap != null) if (bitmap != null)
bitmap.Dispose(); bitmap.Dispose();
Common.log.Info($"结束扫码:task finish:{r}, codeCount:{sw.ElapsedMilliseconds/1000f:0.00}");
using (MemoryStream respStream = new MemoryStream()) using (MemoryStream respStream = new MemoryStream())
{ {
XmlSerializer xff = new XmlSerializer(typeof(List<CodeInfo>)); XmlSerializer xff = new XmlSerializer(typeof(List<CodeInfo>));
......
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
...@@ -38,7 +39,9 @@ namespace ScanCodeServer ...@@ -38,7 +39,9 @@ namespace ScanCodeServer
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>();
Common.log.Info("开始 DecodeCode[eyem]");
Stopwatch sw = new Stopwatch();
sw.Start();
try try
{ {
//创建图像引用 //创建图像引用
...@@ -79,7 +82,10 @@ namespace ScanCodeServer ...@@ -79,7 +82,10 @@ namespace ScanCodeServer
// eyemImageFree(ref tpDstImg); // eyemImageFree(ref tpDstImg);
//hObject.Dispose(); //hObject.Dispose();
//int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, iBlockSize, iRangeC, iSymbolMin, iSymbolMax); //int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, iBlockSize, iRangeC, iSymbolMin, iSymbolMax);
Common.log.Info($"eyemDetectAndDecode:{result},ipNum:{ipNum}"); //Common.log.Info($"eyemDetectAndDecode:{result},ipNum:{ipNum}");
sw.Stop();
Common.log.Info("结束 DecodeCode[eyem][" + (sw.ElapsedMilliseconds / 1000f).ToString("0.00") + $"]返回数量:result:{result},ipNum:{ipNum}");
if (result != 0 || ipNum == 0) if (result != 0 || ipNum == 0)
return codelist; return codelist;
...@@ -89,6 +95,8 @@ namespace ScanCodeServer ...@@ -89,6 +95,8 @@ namespace ScanCodeServer
ci.CodeType = Marshal.PtrToStringAnsi(tpResults[i].hType); ci.CodeType = Marshal.PtrToStringAnsi(tpResults[i].hType);
codelist.Add(ci); codelist.Add(ci);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!