Commit 5bd32f6f 刘韬

修改ocr定位 移动到条码左侧中间

1 个父辈 d035a2e3
......@@ -143,6 +143,9 @@ namespace BLL
}
if (!string.IsNullOrEmpty(keydata) && !AllData.ContainsKey(keydata))
AllData.Add(keydata, rowdata);
if (string.IsNullOrEmpty(keydata))
emptyrow++;
currow++;
}
}
......
......@@ -119,13 +119,14 @@ class NiRenIO: IO_Interface
iomonitorrun = true;
while (iomonitorrun && systemrun)
{
Thread.Sleep(2);
Thread.Sleep(3);
try
{
ReadDO();
}
catch (SocketException)
{
readerrtimes = 0;
if (tcpClient.Connected)
tcpClient.Close();
ConnectionState_Event?.Invoke(this, false);
......@@ -160,7 +161,7 @@ class NiRenIO: IO_Interface
try
{
tcpClient.Client.Send(sendbyte);
Thread.Sleep(1);
Thread.Sleep(2);
byte[] result = new byte[100];
var ulength = tcpClient.Client.Receive(result);
if (ulength > 0) {
......@@ -190,6 +191,7 @@ class NiRenIO: IO_Interface
public bool[] DOstate = new bool[IoCount];
bool[] lastDIstate = new bool[IoCount];
bool[] lastDOstate = new bool[IoCount];
int readerrtimes = 0;
/// <summary>
/// 读全部IO
/// </summary>
......@@ -201,7 +203,7 @@ class NiRenIO: IO_Interface
const string CMD_ReadALL = CMD_ReadDI + CMD_ReadD0;
var sendbyte = Encoding.ASCII.GetBytes(CMD_ReadALL);
Debug.WriteLine("CMD_ReadALL:"+ sendbyte);
Debug.WriteLine("CMD_ReadALL:"+ CMD_ReadALL);
var resultbuffer = new byte[2048];
int ulength = 0;
lock (tcpClient)
......@@ -209,13 +211,20 @@ class NiRenIO: IO_Interface
try
{
tcpClient.Client.Send(sendbyte);
Thread.Sleep(1);
Thread.Sleep(5);
ulength = tcpClient.Client.Receive(resultbuffer);
readerrtimes = 0;
}
catch (SocketException se)
{
throw se;
readerrtimes++;
Thread.Sleep(100);
if (readerrtimes > 5)
{
Debug.WriteLine("Read IO Error");
throw se;
}
return;
}
}
if (ulength == 0) {
......@@ -320,6 +329,14 @@ class NiRenIO: IO_Interface
public bool WriteDO(int add, Status sta)
{
return WriteDO(add, sta == Status.On);
for (int i = 0; i < 10; i++)
{
if (WriteDO(add, sta == Status.On))
{
return true;
}
Thread.Sleep(100);
}
return false;
}
}
......@@ -4,6 +4,8 @@ using System.Drawing;
using System.IO;
using System.Xml;
using CameraVisionLib.Model;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Math;
using Model;
using Newtonsoft.Json;
......@@ -134,10 +136,12 @@ namespace BLL
/// <returns></returns>
public bool MatchingTemplate(List<BarcodeInfo> code, string firstMaterial,bool analyisMode, out string mateName, out Dictionary<string, string> keyword, out bool[] isCodeUsed)
{
if (Directory.Exists("ocr"))
Directory.Delete("ocr", true);
mateName = "";
keyword = null;
isCodeUsed = null;
isCodeUsed = null;
code.ForEach((c)=> {
LogNet.log.Info($"扫描到 {c.CodeType},{c.Text}");
});
......@@ -416,6 +420,7 @@ namespace BLL
LogNet.log.Info("OCR匹配 " + ocrlist.Count);
if (ocrlist.Count > 0)
{
LogNet.log.Info("开始OCR匹配 ");
//增加ocr匹配
// OCR oCR = new();
......@@ -425,7 +430,7 @@ namespace BLL
matchCount += codeMatch.Count;
Bitmap bmp = CodeOcr(mateTemp[index].Name,ocrcode[i], ocrlist[i], CurrntBitmap);
Bitmap bmp = CodeOcr(mateTemp[index].Name,ocrcode[i], ocrlist[i], CurrntBitmap,out string ocrname);
bool algro = ConfigHelper.Config.Get("UsePaddleOCR", false);
string codeOcr = "";
if (algro)
......@@ -452,7 +457,7 @@ namespace BLL
#endregion ocr文字提取结束
}
LogNet.log.Info($"OCR匹配 {ocrname} = {codeOcr}");
var x = new BarcodeInfo() {Text=codeOcr,CodeType="OCR"};
Dictionary<string, string> matchKey = CodeMatch(x, codeMatch);
if (matchKey != null)
......@@ -477,8 +482,9 @@ namespace BLL
}
}
private Bitmap CodeOcr(string templatename, BarcodeInfo code, MaterialCodeOCR ocr, Bitmap codeImage)
private Bitmap CodeOcr(string templatename, BarcodeInfo code, MaterialCodeOCR ocr, Bitmap codeImage,out string ocrname)
{
ocrname = "";
int smside = ocr.Width < ocr.Height ? ocr.Width : ocr.Height;
smside = (int)(smside * 0.2);
float OffsetX = ocr.OffsetX - smside;
......@@ -486,8 +492,15 @@ namespace BLL
int Width = ocr.Width + smside * 2;
int Height = ocr.Height + smside * 2;
var a = code.Angle >= 0 ? 180+code.Angle*-1 : 180 + Math.Abs(code.Angle);
double centerX = code.Center.X;
double centerY = code.Center.Y;
double centerY = code.Center.Y;
var cent = PointWithAngle(code.Center, a, code.Size.Width/2);
centerX=cent.X;
centerY=cent.Y;
double aa = Math.Atan2(centerY, centerX);
aa = aa * 180 / Math.PI; //转角度
double cc = Math.Sqrt(centerX * centerX + centerY * centerY);
......@@ -515,10 +528,10 @@ namespace BLL
g.Dispose();
ocrRotate.Save(@"ocr.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Directory.CreateDirectory("ocr");
ocrRotate.Save($"ocr\\{templatename}_{ocr.OffsetX}_{ocr.OffsetY}.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
ocrname = $"{templatename}_{ocr.OffsetX}_{ocr.OffsetY}";
ocrRotate.Save($"ocr\\{ocrname}.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
return ocrRotate;
}
private Dictionary<string, string> CodeMatch(BarcodeInfo codeinfo, List<MaterialCodeMatch> codeMatch)
{
Dictionary<string, string> key = new();
......@@ -724,7 +737,18 @@ namespace BLL
return tempIndex;
}
public static void OffsetCoordinate(float x, float y, double radian, double offsetX, out double newX, out double newY)
{
var aaa = PointWithAngle(new System.Drawing.PointF(x, y), radian+270, offsetX);
newX = aaa.X;
newY = aaa.Y;
}
public static System.Drawing.PointF PointWithAngle(System.Drawing.PointF p1, double angle, double distance)
{
var x2 = p1.X + distance * Math.Cos(angle / 180 * Math.PI);
var y2 = p1.Y + distance * Math.Sin(angle / 180 * Math.PI);
return new System.Drawing.Point((int)x2, (int)y2);
}
//public Dictionary<string, string> ExtractCode(List<MaterialCode> code, int mateIndex)
//{
// Dictionary<string, string> keyword = new Dictionary<string, string>();
......
......@@ -34,7 +34,7 @@ namespace Model
RestRequest request = new(Method.GET);
IRestResponse response = client.Execute(request);
string s = response.Content;
LogNet.log.Info($"[GET][URL:{url}][Return:{s}]");
///LogNet.log.Info($"[GET][URL:{url}][Return:{s}]");
return FormatContent(s);
}
......
......@@ -138,6 +138,9 @@ namespace SmartScan
RectangleF src = new(0, 0, codeImage.Width, codeImage.Height);
g.DrawImage(codeImage, src, src, GraphicsUnit.Pixel);
g.ResetTransform();
codeCenter.X -= mateCode.Width / 2;
//codeCenter.Y += mateCode.Height / 4;
g.DrawLine(PEN_SELECT, codeCenter.X - 10, codeCenter.Y - 10, codeCenter.X + 10, codeCenter.Y + 10);
g.DrawLine(PEN_SELECT, codeCenter.X - 10, codeCenter.Y + 10, codeCenter.X + 10, codeCenter.Y - 10);
g.Save();
......@@ -206,6 +209,8 @@ namespace SmartScan
string codeOcrs = getOcrString();
codeOcr[ocrRectIndex].Text = codeOcrs;
codeOcr[ocrRectIndex].OffsetX = ocrRect[ocrRectIndex].X-codeCenter.X;
codeOcr[ocrRectIndex].OffsetY = ocrRect[ocrRectIndex].Y-codeCenter.Y;
PicImage.Cursor = Cursors.Cross;
//_ocr[ocrIndex[codeOcrIndex]].Offset = new Point(Convert.ToInt32(ocrRect[codeOcrIndex].X - codeCenter.X), Convert.ToInt32(ocrRect[codeOcrIndex].Y - codeCenter.Y));
}
......
using System;
using Model;
using System;
using System.IO.Ports;
namespace SmartScan
......@@ -42,8 +43,11 @@ namespace SmartScan
{
if (sourceFromIO)
{
if (Common.config.EnabledIO && Common.ioModule.IsConn)
Common.ioModule?.WriteDO(Common.config.IOLight, BLL.Status.On);
if (Common.config.EnabledIO)
{
var r=Common.ioModule?.WriteDO(Common.config.IOLight, BLL.Status.On);
LogNet.log.Info("Light TurnOn,IsConn:" + Common.ioModule?.IsConn+ ",WriteDO:" + r);
}
}
else
{
......
......@@ -283,7 +283,7 @@ namespace SmartScan
LogNet.log.Info("Work MatchingTemplate");
if (workCodeInfo.Count == 0) return false;
originalCodeText = Common.cameraVision.GetBarCodeText(workCodeInfo);
bool rtn = Common.mateEdit.MatchingTemplate(workCodeInfo, Common.config.DefaultMaterialName,false, out string mateName, out workCodeKeyword, out originalCodeIsUsed);
BLL.MatchAnalysis.ShowResult();
Common.frmMain.Invoke(delegate ()
......
......@@ -274,11 +274,17 @@ namespace SmartScan
if (codeIndex == -1) return;
var m = mateCopy[mateIndex].Match.Find(m=>m.CodeID==codeIndex);
if (m == null) {
if (m == null)
{
string text = Language.Dialog("OcrNeedCodeSetKey");
new FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
return;
}
else if (m.CodeType == "QR Code" || m.CodeType == "Data Matrix ECC 200") {
string text = Language.Dialog("OcrNotSupport2DCode","二维码不能用于OCR定位基准");
new FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
return;
}
List<MaterialCodeOCR> codeOcr = mateCopy[mateIndex].Ocr.FindAll(s => s.CodeID == mateCopy[mateIndex].Code[codeIndex].ID);
FrmCodeOCR frm = new(mateCopy[mateIndex].Code[codeIndex], codeOcr, mateCopy[mateIndex].Match, mateCopy[mateIndex].Image);
......
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<Language>简体中文</Language>
<Language>English</Language>
<PrinterName>Microsoft Print to PDF</PrinterName>
<PrintLandscape>False</PrintLandscape>
<HistoryImage>Original</HistoryImage>
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Language Name="English">
<Dialog>
<LoginWrong>The login password is incorrect.</LoginWrong>
......@@ -39,6 +39,8 @@
<filepatseerror>File read fails</filepatseerror>
<!--原文:文件格式不正确-->
<fileformaterror>Incorrect file format</fileformaterror>
<!--原文:二维码不能用于OCR定位基准-->
<OcrNotSupport2DCode>2D barcode cannot be used as OCR positioning benchmarks</OcrNotSupport2DCode>
</Dialog>
<FrmUsersLogin Text="Login" Font="Arial,24,B,">
<LblUser Text="User name" Font="Arial,11,," />
......
......@@ -37,6 +37,8 @@
<filenotexists>文件状态:改文件不存在</filenotexists>
<!--原文:文件格式不正确-->
<fileformaterror>文件格式不正确</fileformaterror>
<!--原文:-->
<OcrNotSupport2DCode>二维码不能用于OCR定位基准</OcrNotSupport2DCode>
</Dialog>
<FrmUsersLogin Text="登录" Font="微软雅黑,24,B,">
<LblUser Text="用户名:" Font="微软雅黑,11,," />
......
此文件的差异太大,无法显示。
......@@ -5,14 +5,10 @@
<level value="Info"/>
<appender-ref ref="SmartScan"/>
</logger>
<logger name="VisionLib">
<logger name="VisionLib" >
<level value="Debug"/>
<appender-ref ref="VisionLib"/>
</logger>
<root>
<level value="Debug"/>
<appender-ref ref="VisionLib"/>
</root>
<appender name="SmartScan" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\\SmartScan.log" />
<param name="Encoding" value="UTF-8"/>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!