Commit 01fa4104 张东亮

1

1 个父辈 25815d1d
...@@ -326,6 +326,8 @@ namespace BLL ...@@ -326,6 +326,8 @@ namespace BLL
public static MyConfig<bool> DataSource_Recursive; public static MyConfig<bool> DataSource_Recursive;
[MyConfigComment("是否启用OCR")] [MyConfigComment("是否启用OCR")]
public static MyConfig<bool> Func_EnabledOCR=true; public static MyConfig<bool> Func_EnabledOCR=true;
[MyConfigComment("RI自动生成时是否添加编号")]
public static MyConfig<bool> AutoRIGenID = false;
//[MyConfigComment("是否启用飞浆OCR识别")] //[MyConfigComment("是否启用飞浆OCR识别")]
//public static MyConfig<bool> UsePaddleOCR = true; //public static MyConfig<bool> UsePaddleOCR = true;
......
...@@ -53,7 +53,7 @@ namespace BLL ...@@ -53,7 +53,7 @@ namespace BLL
static bool mesResult = false; static bool mesResult = false;
Dictionary<string, string> lastkey = null; Dictionary<string, string> lastkey = null;
//读码后第一步 //读码后第一步
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg) public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
{ {
errmsg = ""; errmsg = "";
lastkey = key; lastkey = key;
...@@ -77,13 +77,14 @@ namespace BLL ...@@ -77,13 +77,14 @@ namespace BLL
else else
key.Add(config.ReelIDKeyWord, Reelidstr); key.Add(config.ReelIDKeyWord, Reelidstr);
} }
if (extensions !=null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
{
if (key.ContainsKey(Config.DataSource_DataKey) && ExtraFileData.AllData.ContainsKey(key[Config.DataSource_DataKey]))
{ {
if (key.ContainsKey(Config.DataSource_DataKey) && ExtraFileData.AllData.ContainsKey(key[Config.DataSource_DataKey])) {
var extraData = ExtraFileData.AllData[key[Config.DataSource_DataKey]]; var extraData = ExtraFileData.AllData[key[Config.DataSource_DataKey]];
foreach (var d in extraData) foreach (var d in extraData)
{ {
key[d.Key]=d.Value; key[d.Key] = d.Value;
} }
} }
...@@ -94,7 +95,7 @@ namespace BLL ...@@ -94,7 +95,7 @@ namespace BLL
extensions[i].Control.Text = key[extensions[i].Key]; extensions[i].Control.Text = key[extensions[i].Key];
} }
} }
if (!updatereelid(key,out errmsg)) if (!updatereelid(key, out errmsg))
return false; return false;
Application.DoEvents(); Application.DoEvents();
...@@ -106,14 +107,16 @@ namespace BLL ...@@ -106,14 +107,16 @@ namespace BLL
PrintLabel(null, EventArgs.Empty); PrintLabel(null, EventArgs.Empty);
} }
} }
else { else
{
//PrintLabel(null, EventArgs.Empty); //PrintLabel(null, EventArgs.Empty);
} }
SaveRetrospect?.Invoke(key); SaveRetrospect?.Invoke(key);
return true; return true;
} }
bool updatereelid(Dictionary<string, string> key,out string errmsg) { bool updatereelid(Dictionary<string, string> key, out string errmsg)
{
errmsg = ""; errmsg = "";
if (!string.IsNullOrEmpty(config.HttpReelID)) if (!string.IsNullOrEmpty(config.HttpReelID))
{ {
...@@ -124,7 +127,7 @@ namespace BLL ...@@ -124,7 +127,7 @@ namespace BLL
} }
//key["ReelID"] = newid; //key["ReelID"] = newid;
} }
if (extensions!=null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
{ {
for (int i = 0; i < extensions.Count; i++) for (int i = 0; i < extensions.Count; i++)
{ {
...@@ -159,14 +162,16 @@ namespace BLL ...@@ -159,14 +162,16 @@ namespace BLL
string[] keys = ObjConversion.StrGetKey(matchID); string[] keys = ObjConversion.StrGetKey(matchID);
for (int i = 0; i < keys.Length; i++) for (int i = 0; i < keys.Length; i++)
{ {
if (keys[i].ToLower().StartsWith("datetime")) { if (keys[i].ToLower().StartsWith("datetime"))
{
string ov = string.Format("[{0}]", keys[i]); string ov = string.Format("[{0}]", keys[i]);
var d = keys[i].Split(':'); var d = keys[i].Split(':');
if (d.Length == 2) if (d.Length == 2)
{ {
matchID = matchID.Replace(ov, DateTime.Now.ToString(d[1])); matchID = matchID.Replace(ov, DateTime.Now.ToString(d[1]));
} }
else { else
{
matchID = matchID.Replace(ov, DateTime.Now.ToString()); matchID = matchID.Replace(ov, DateTime.Now.ToString());
} }
continue; continue;
...@@ -180,11 +185,14 @@ namespace BLL ...@@ -180,11 +185,14 @@ namespace BLL
//SaveAddReelID(); //SaveAddReelID();
var reelID = ReadReelID(); var reelID = ReadReelID();
//填充0 //填充0
string text = matchPrefix+ matchID; string text = matchPrefix + matchID;
if (Config.AutoRIGenID)
{
if (matchFill) if (matchFill)
text += string.Format("{0:d" + matchPlace + "}", reelID); text += string.Format("{0:d" + matchPlace + "}", reelID);
else else
text += reelID.ToString(); text += reelID.ToString();
}
text += matchPostfix; text += matchPostfix;
return text; return text;
} }
...@@ -195,8 +203,9 @@ namespace BLL ...@@ -195,8 +203,9 @@ namespace BLL
try try
{ {
var reelidfile = FilePath.CONFIG_REELID; var reelidfile = FilePath.CONFIG_REELID;
if (config.ReelIDAutoResetByDate) { if (config.ReelIDAutoResetByDate)
Directory.CreateDirectory(reelidfile+"_dir"); {
Directory.CreateDirectory(reelidfile + "_dir");
reelidfile = Path.Combine(FilePath.CONFIG_REELID + "_dir", DateTime.Now.ToString("yyyyMMdd")); reelidfile = Path.Combine(FilePath.CONFIG_REELID + "_dir", DateTime.Now.ToString("yyyyMMdd"));
} }
if (File.Exists(reelidfile)) if (File.Exists(reelidfile))
...@@ -222,8 +231,9 @@ namespace BLL ...@@ -222,8 +231,9 @@ namespace BLL
return reelID; return reelID;
} }
private void GetHttpReelID(object sender, EventArgs e) { private void GetHttpReelID(object sender, EventArgs e)
updatereelid(lastkey,out _); {
updatereelid(lastkey, out _);
} }
private void PrintLabel(object sender, EventArgs e) private void PrintLabel(object sender, EventArgs e)
{ {
...@@ -243,12 +253,13 @@ namespace BLL ...@@ -243,12 +253,13 @@ namespace BLL
Printing?.Invoke(lastkey); Printing?.Invoke(lastkey);
} }
private bool GetHttpReelID(Dictionary<string, string> key,out string errmsg) private bool GetHttpReelID(Dictionary<string, string> key, out string errmsg)
{ {
errmsg = ""; errmsg = "";
string url = config.HttpReelID; string url = config.HttpReelID;
string json = Http.PostJson(url,null, key); string json = Http.PostJson(url, null, key);
if (json == "") { if (json == "")
{
errmsg = "Api error"; errmsg = "Api error";
if (extensions != null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog(); new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
...@@ -261,7 +272,8 @@ namespace BLL ...@@ -261,7 +272,8 @@ namespace BLL
{ {
dic = (Dictionary<string, object>)serializer.DeserializeObject(json); dic = (Dictionary<string, object>)serializer.DeserializeObject(json);
} }
catch { catch
{
errmsg = "Api parse error:\r\n" + json; errmsg = "Api parse error:\r\n" + json;
if (extensions != null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog(); new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
...@@ -274,11 +286,11 @@ namespace BLL ...@@ -274,11 +286,11 @@ namespace BLL
if (extensions != null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", "Api return data error:\r\n" + json, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog(); new FaceMessageBox("BoxReelIDInfoMaintain", "Api return data error:\r\n" + json, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
else else
errmsg="Api return data error:\r\n" + json; errmsg = "Api return data error:\r\n" + json;
return false; return false;
} }
if (Convert.ToInt32(value)!=0) if (Convert.ToInt32(value) != 0)
{ {
errmsg = "Api parse error:\r\n" + dic["MSG"].ToString(); errmsg = "Api parse error:\r\n" + dic["MSG"].ToString();
if (extensions != null && !extensions[0].Control.InvokeRequired) if (extensions != null && !extensions[0].Control.InvokeRequired)
......
...@@ -436,7 +436,7 @@ namespace BLL ...@@ -436,7 +436,7 @@ namespace BLL
} }
} }
if (keyword.Count == matchCount) if (matchCount != 0 && keyword.Count == matchCount)
{ {
isMatch = true; isMatch = true;
} }
...@@ -447,10 +447,10 @@ namespace BLL ...@@ -447,10 +447,10 @@ namespace BLL
ocrlist.Add(o); ocrlist.Add(o);
//ocrcode.Add(code[j]); //ocrcode.Add(code[j]);
} }
int ocrCount= ocrlist.Count; int ocrCount = ocrlist.Count;
if (ocrlist.Count > 0) if (ocrlist.Count > 0)
{ {
LogNet.log.Info($"{mateTemp[index].Name} 开始OCR匹配"); LogNet.log.Info($"{mateTemp[index].Name} 开始OCR匹配 [{ocrCount}]");
for (int i = 0; i < ocrlist.Count; i++) for (int i = 0; i < ocrlist.Count; i++)
{ {
List<MaterialCodeMatch> codeMatch = mateTemp[index].Match.FindAll(match => match.CodeID == ocrlist[i].ID); List<MaterialCodeMatch> codeMatch = mateTemp[index].Match.FindAll(match => match.CodeID == ocrlist[i].ID);
...@@ -475,19 +475,20 @@ namespace BLL ...@@ -475,19 +475,20 @@ namespace BLL
} }
} }
} }
if(ocrCount==0&& !isMatch) if (ocrCount == 0 && !isMatch)
{ {
isMatch = true; isMatch = true;
LogNet.log.Info($"{mateTemp[index].Name} OCR匹配成功");
} }
LogNet.log.Info($"{mateTemp[index].Name} 结束OCR匹配 "); LogNet.log.Info($"{mateTemp[index].Name} 结束OCR匹配 ");
} }
} }
if (matchCount == 0) //if (matchCount == 0)
{ //{
return false; // return false;
} //}
else //else
{ {
if (isMatch) if (isMatch)
{ {
...@@ -495,8 +496,9 @@ namespace BLL ...@@ -495,8 +496,9 @@ namespace BLL
#region Code按照 匹配到的列表重新排序 #region Code按照 匹配到的列表重新排序
MatchCodeIndex = MatchCodeIndex.Distinct().ToList(); MatchCodeIndex = MatchCodeIndex.Distinct().ToList();
var code2 = new List<BarcodeInfo>(); var code2 = new List<BarcodeInfo>();
foreach(var i in MatchCodeIndex) { foreach (var i in MatchCodeIndex)
if (code.Count>i) {
if (code.Count > i)
code2.Add(code[i]); code2.Add(code[i]);
} }
foreach (var c in code) foreach (var c in code)
......
...@@ -144,7 +144,7 @@ namespace SmartScan ...@@ -144,7 +144,7 @@ namespace SmartScan
private void btn_adddatetime_Click(object sender, EventArgs e) private void btn_adddatetime_Click(object sender, EventArgs e)
{ {
string key = "[datetime:yyyyMMdd]"; string key = "[datetime:yyyyMMddHHmmss]";
TxtReelIDMatch.AppendText(key); TxtReelIDMatch.AppendText(key);
} }
} }
......
...@@ -235,34 +235,39 @@ namespace paddleOCR ...@@ -235,34 +235,39 @@ namespace paddleOCR
static bool IsInSameLine(TextBlock t1, TextBlock t2) static bool IsInSameLine(TextBlock t1, TextBlock t2)
{ {
//同一行间隔小于多少像素可以合并 //同一行间隔小于多少像素可以合并
int intervalPixel = ConfigHelper.Config.Get("IntervalPixelInSameLine", 60); int intervalPixel = ConfigHelper.Config.Get("IntervalPixelInSameLine", 20);
int p1y1 = t1.BoxPoints[0].Y; int p1y1 = t1.BoxPoints[0].Y;
int p1y2 = t1.BoxPoints[3].Y; int p1y2 = t1.BoxPoints[1].Y;
int p1y3 = t1.BoxPoints[2].Y;
int p1y4 = t1.BoxPoints[3].Y;
int p2y1 = t2.BoxPoints[0].Y; int p2y1 = t2.BoxPoints[0].Y;
int p2y2 = t2.BoxPoints[3].Y; int p2y2 = t2.BoxPoints[1].Y;
int p2y3 = t2.BoxPoints[2].Y;
int p2y4 = t2.BoxPoints[3].Y;
int p1x0 = t1.BoxPoints[0].X; int p1x0 = t1.BoxPoints[0].X;
int p1x1 = t1.BoxPoints[1].X; int p1x1 = t1.BoxPoints[1].X;
int p2x0 = t2.BoxPoints[0].X; int p2x0 = t2.BoxPoints[0].X;
int p2x1 = t2.BoxPoints[1].X; int p2x1 = t2.BoxPoints[1].X;
if (p1y1 > p2y2 || p1y2 < p2y1) { return false; } if (p1x0 < p2x0)//t1在左侧
else
{ {
if(p1x0<p2x0)//t1在左侧
{ if (p1y2 > p2y4 || p1y3 < p2y1) return false;
if (Math.Abs(p1x1 - p2x0) > intervalPixel) return false; else if (Math.Abs(p1x1 - p2x0) > intervalPixel) return false;
else else
return true; return true;
} }
else else
{ {
if (Math.Abs(p2x1 - p1x0) > intervalPixel) return false; if (p2y2 > p1y4 || p2y3 < p1y1) return false;
else if (Math.Abs(p2x1 - p1x0) > intervalPixel) return false;
else else
return true; return true;
} }
}
} }
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!