Commit d035a2e3 刘韬

ocr框取图时扩展20%选区

1 个父辈 537f8e08
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Xml; using System.Xml;
using CameraVisionLib.Model; using CameraVisionLib.Model;
using Model; using Model;
...@@ -424,7 +425,7 @@ namespace BLL ...@@ -424,7 +425,7 @@ namespace BLL
matchCount += codeMatch.Count; matchCount += codeMatch.Count;
Bitmap bmp = CodeOcr(ocrcode[i], ocrlist[i], CurrntBitmap); Bitmap bmp = CodeOcr(mateTemp[index].Name,ocrcode[i], ocrlist[i], CurrntBitmap);
bool algro = ConfigHelper.Config.Get("UsePaddleOCR", false); bool algro = ConfigHelper.Config.Get("UsePaddleOCR", false);
string codeOcr = ""; string codeOcr = "";
if (algro) if (algro)
...@@ -476,8 +477,15 @@ namespace BLL ...@@ -476,8 +477,15 @@ namespace BLL
} }
} }
private Bitmap CodeOcr(BarcodeInfo code, MaterialCodeOCR ocr, Bitmap codeImage) private Bitmap CodeOcr(string templatename, BarcodeInfo code, MaterialCodeOCR ocr, Bitmap codeImage)
{ {
int smside = ocr.Width < ocr.Height ? ocr.Width : ocr.Height;
smside = (int)(smside * 0.2);
float OffsetX = ocr.OffsetX - smside;
float OffsetY = ocr.OffsetY - smside;
int Width = ocr.Width + smside * 2;
int Height = ocr.Height + smside * 2;
double centerX = code.Center.X; double centerX = code.Center.X;
double centerY = code.Center.Y; double centerY = code.Center.Y;
double aa = Math.Atan2(centerY, centerX); double aa = Math.Atan2(centerY, centerX);
...@@ -487,25 +495,27 @@ namespace BLL ...@@ -487,25 +495,27 @@ namespace BLL
aa = aa * Math.PI / 180; //转弧度 aa = aa * Math.PI / 180; //转弧度
double x1 = Math.Cos(aa) * cc; double x1 = Math.Cos(aa) * cc;
double y1 = Math.Sin(aa) * cc; double y1 = Math.Sin(aa) * cc;
int w = ocr.Width; int w = Width;
int h = ocr.Height; int h = Height;
Bitmap ocrRotate = new(w, h); Bitmap ocrRotate = new(w, h);
Graphics g = Graphics.FromImage(ocrRotate); Graphics g = Graphics.FromImage(ocrRotate);
float x2 = w / 2f - ocr.OffsetX - ocr.Width / 2f; float x2 = w / 2f - OffsetX - Width / 2f;
float y2 = h / 2f - ocr.OffsetY - ocr.Height / 2f; float y2 = h / 2f - OffsetY - Height / 2f;
float dx = Convert.ToSingle(x1 - x2); float dx = Convert.ToSingle(x1 - x2);
float dy = Convert.ToSingle(y1 - y2); float dy = Convert.ToSingle(y1 - y2);
g.TranslateTransform(-dx, -dy); g.TranslateTransform(-dx, -dy);
g.RotateTransform(code.Angle); g.RotateTransform(code.Angle);
RectangleF src = new(0, 0, codeImage.Width, codeImage.Height); RectangleF src = new(-smside, -smside, codeImage.Width, codeImage.Height);
g.DrawImage(codeImage, src, src, GraphicsUnit.Pixel); g.DrawImage(codeImage, src, src, GraphicsUnit.Pixel);
g.ResetTransform(); g.ResetTransform();
g.Save(); g.Save();
g.Dispose(); g.Dispose();
ocrRotate.Save(@"ocr.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 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);
return ocrRotate; return ocrRotate;
} }
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
<PrintCompletedClear>False</PrintCompletedClear> <PrintCompletedClear>False</PrintCompletedClear>
<OpenStartWork>True</OpenStartWork> <OpenStartWork>True</OpenStartWork>
<OpenMaximize>True</OpenMaximize> <OpenMaximize>True</OpenMaximize>
<DefaultPrintLabel>Print_Test</DefaultPrintLabel> <DefaultPrintLabel>test2</DefaultPrintLabel>
<EnabledIO>True</EnabledIO> <EnabledIO>false</EnabledIO>
<EnabledCamera>True</EnabledCamera> <EnabledCamera>false</EnabledCamera>
<IOIP>192.168.20.100</IOIP> <IOIP>192.168.20.100</IOIP>
<IOTouch>0</IOTouch> <IOTouch>0</IOTouch>
<IOLight>0</IOLight> <IOLight>0</IOLight>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</HttpServer> </HttpServer>
<HttpReelID> <HttpReelID>
</HttpReelID> </HttpReelID>
<DefaultMaterialName>New</DefaultMaterialName> <DefaultMaterialName>TEST4</DefaultMaterialName>
<TriggerOpenLight>True</TriggerOpenLight> <TriggerOpenLight>True</TriggerOpenLight>
<EnabledUserLogin>Flase</EnabledUserLogin> <EnabledUserLogin>Flase</EnabledUserLogin>
<OperateTimeout>60</OperateTimeout> <OperateTimeout>60</OperateTimeout>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!