diff --git a/LibReadTetraExcel/LibReadTetraExcel.csproj b/LibReadTetraExcel/LibReadTetraExcel.csproj
index 186cfbb..9c8f5e5 100644
--- a/LibReadTetraExcel/LibReadTetraExcel.csproj
+++ b/LibReadTetraExcel/LibReadTetraExcel.csproj
@@ -1,5 +1,6 @@
+
Debug
@@ -12,6 +13,8 @@
v4.7.2
512
true
+
+
true
@@ -49,14 +52,84 @@
prompt
+
+ ..\packages\BouncyCastle.Cryptography.2.7.0-beta.98\lib\net461\BouncyCastle.Cryptography.dll
+
+
+ ..\packages\Enums.NET.5.0.0\lib\net461\Enums.NET.dll
+
+
+ ..\packages\ExtendedNumerics.BigDecimal.3003.0.0.346\lib\net472\ExtendedNumerics.BigDecimal.dll
+
+
+ ..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll
+
+
+ ..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll
+
+
+ ..\packages\Microsoft.Bcl.Cryptography.10.0.1\lib\net462\Microsoft.Bcl.Cryptography.dll
+
+
+ ..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll
+
+
+ ..\packages\NPOI.2.7.5\lib\net472\NPOI.Core.dll
+
+
+ ..\packages\NPOI.2.7.5\lib\net472\NPOI.OOXML.dll
+
+
+ ..\packages\NPOI.2.7.5\lib\net472\NPOI.OpenXml4Net.dll
+
+
+ ..\packages\NPOI.2.7.5\lib\net472\NPOI.OpenXmlFormats.dll
+
+
+ ..\packages\NSax.1.0.2\lib\net472\NSax.dll
+
+
+ ..\packages\SixLabors.Fonts.1.0.1\lib\netstandard2.0\SixLabors.Fonts.dll
+
+
+ ..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll
+
+
+
+
+ ..\packages\System.Formats.Asn1.10.0.1\lib\net462\System.Formats.Asn1.dll
+
+
+ ..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll
+
+
+
+ ..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll
+
+
+ ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll
+
+
+
+ ..\packages\System.Security.Cryptography.Xml.10.0.1\lib\net462\System.Security.Cryptography.Xml.dll
+
+
+ ..\packages\System.Text.Encoding.CodePages.10.0.1\lib\net462\System.Text.Encoding.CodePages.dll
+
+
+ ..\packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll
+
+
+ ..\packages\ZString.2.6.0\lib\netstandard2.0\ZString.dll
+
@@ -68,5 +141,17 @@
LibDataBase
+
+
+
+
+
+
+ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
+
+
+
+
+
\ No newline at end of file
diff --git a/LibReadTetraExcel/app.config b/LibReadTetraExcel/app.config
new file mode 100644
index 0000000..43849b3
--- /dev/null
+++ b/LibReadTetraExcel/app.config
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LibReadTetraExcel/packages.config b/LibReadTetraExcel/packages.config
new file mode 100644
index 0000000..bd1fbc5
--- /dev/null
+++ b/LibReadTetraExcel/packages.config
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TetraPackOCR/App.config b/TetraPackOCR/App.config
index b82c6d1..b41bf09 100644
--- a/TetraPackOCR/App.config
+++ b/TetraPackOCR/App.config
@@ -47,7 +47,7 @@
-
+
diff --git a/TetraPackOCR/Form1.cs b/TetraPackOCR/Form1.cs
index 5313ef2..b359e85 100644
--- a/TetraPackOCR/Form1.cs
+++ b/TetraPackOCR/Form1.cs
@@ -563,30 +563,9 @@ namespace TetraPackOCR
try
{
//模型初始化
- OCRModelConfig config = new OCRModelConfig(); //创建一个模型参数设置对象
- string rootPath = System.IO.Path.GetDirectoryName(typeof(OCRModelConfig).Assembly.Location); //程序的根目录
- config.det_infer = rootPath + @"\Data\OCRModel\det_infer"; //文字检测模型路径
- config.cls_infer = rootPath + @"\Data\OCRModel\cls_infer"; //文本角度模型路径
- config.rec_infer = rootPath + @"\Data\OCRModel\rec_infer"; //文字内容识别模型路径
- //以上三个模型参数的文件路径只需要写到存放的文件夹名称
- //对于字典来说需要写全加上后缀
- config.keys = rootPath + @"\Data\OCRModel\keys\ppocr_keys.txt"; //词典路径
-
- //OCR参数设置
- OCRParameter OcrParameter = new OCRParameter(); //创建一个检测参数设置对象
-
- OcrParameter.cpu_math_library_num_threads = 8;//预测并发线程数
- OcrParameter.enable_mkldnn = true;//web部署该值建议设置为0,否则出错,内存如果使用很大,建议该值也设置为0.
- OcrParameter.cls = true; //是否执行文字方向分类;默认false
- OcrParameter.det = true;//是否开启方向检测,用于检测识别180旋转
- OcrParameter.rec = true;
- OcrParameter.use_angle_cls = true;//是否开启方向检测,用于检测识别180旋转
- OcrParameter.det_db_score_mode = true;//是否使用多段线,即文字区域是用多段线还是用矩形,
- OcrParameter.det_db_unclip_ratio = 1.6f;
- OcrParameter.max_side_len = 4600;
-
+ OCRModelConfig config = null;
//初始化OCR
- Engine = new PaddleOCREngine(config, OcrParameter);
+ Engine = new PaddleOCREngine(config, "");
log.Info("OCR模型初始化完成");
}
catch (Exception ex)
@@ -1341,67 +1320,91 @@ namespace TetraPackOCR
NoticePLCCompleteOCR();
return;
}
- Mat hsv = new Mat();
- Cv2.CvtColor(bgr, hsv, ColorConversionCodes.BGR2HSV); // 1. 转 HSV
- Mat[] channels = Cv2.Split(hsv); // 2. 拆通道
- Mat h = channels[0]; // Hue 0-180
- Mat s = channels[1]; // Saturation 0-255
- Mat v = channels[2]; // Value 0-255
+ bool matchOK = false;
+ OCRTextResult rgbResult = null;
+ List pointRGB = null;
+ rgbResult = OCRBytes(bgr.ToBytes());
+ if (rgbResult == null)
+ {
+ log.Error("彩色通道,OCR字符识别失败");
+ NoticePLCCompleteOCR();
+ return;
+ }
+ txt_readOcrResultShow.Text = rgbResult.text;
+ log.Info("彩色通道字符读取结果:" + rgbResult.text);
+ matchOK = rgbResult.match;
+ pointRGB = rgbResult.points;
+ Mat hsv = null;
OCRTextResult hResult = null;
OCRTextResult sResult = null;
OCRTextResult vResult = null;
- bool matchOK = false;
List pointS = null;
List pointH = null;
List pointV = null;
- sResult = OCRBytes(s.ImEncode(".png"));
- if (sResult == null)
+ if (!matchOK)
{
- log.Error("s通道,OCR字符识别失败");
- NoticePLCCompleteOCR();
- return;
- }
- txt_readOcrResultShow.Text = sResult.text;
- log.Info("s通道字符读取结果:" + sResult.text);
- matchOK = sResult.match;
- pointS = sResult.points;
+ hsv = new Mat();
+ Cv2.CvtColor(bgr, hsv, ColorConversionCodes.BGR2HSV); // 1. 转 HSV
+ Mat[] channels = Cv2.Split(hsv); // 2. 拆通道
+ Mat h = channels[0]; // Hue 0-180
+ Mat s = channels[1]; // Saturation 0-255
+ Mat v = channels[2]; // Value 0-255
- if (!matchOK)
- {
- hResult = OCRBytes(h.ImEncode(".png"));
- if (hResult == null)
+ sResult = OCRBytes(s.ImEncode(".png"));
+ if (sResult == null)
{
- log.Error("h通道,OCR字符识别失败");
+ log.Error("s通道,OCR字符识别失败");
NoticePLCCompleteOCR();
return;
}
- txt_readOcrResultShow.Text += "\n" + hResult.text;
- log.Info("h通道字符读取结果:" + hResult.text);
- matchOK = hResult.match;
- pointH = hResult.points;
- }
- if (!matchOK)
- {
- vResult = OCRBytes(v.ImEncode(".png"));
- if (vResult == null)
+ txt_readOcrResultShow.Text = "\n" + sResult.text;
+ log.Info("s通道字符读取结果:" + sResult.text);
+ matchOK = sResult.match;
+ pointS = sResult.points;
+
+ if (!matchOK)
{
- log.Error("v通道,OCR字符识别失败");
- NoticePLCCompleteOCR();
- return;
+ hResult = OCRBytes(h.ImEncode(".png"));
+ if (hResult == null)
+ {
+ log.Error("h通道,OCR字符识别失败");
+ NoticePLCCompleteOCR();
+ return;
+ }
+ txt_readOcrResultShow.Text += "\n" + hResult.text;
+ log.Info("h通道字符读取结果:" + hResult.text);
+ matchOK = hResult.match;
+ pointH = hResult.points;
+ }
+ if (!matchOK)
+ {
+ vResult = OCRBytes(v.ImEncode(".png"));
+ if (vResult == null)
+ {
+ log.Error("v通道,OCR字符识别失败");
+ NoticePLCCompleteOCR();
+ return;
+ }
+ txt_readOcrResultShow.Text += "\n" + vResult.text;
+ log.Info("v通道字符读取结果:" + vResult.text);
+ matchOK = vResult.match;
+ pointV = vResult.points;
}
- txt_readOcrResultShow.Text += "\n" + vResult.text;
- log.Info("v通道字符读取结果:" + vResult.text);
- matchOK = vResult.match;
- pointV = vResult.points;
}
+
byte[] ocrimagebyte = File.ReadAllBytes(file.FileName);
Bitmap Bmp = new Bitmap(new MemoryStream(ocrimagebyte));
- if ((pointS != null && pointS.Count > 0) || (pointH != null && pointH.Count > 0) || (pointV != null && pointV.Count > 0))
+ if ((pointRGB != null && pointRGB.Count > 0) || (pointS != null && pointS.Count > 0) || (pointH != null && pointH.Count > 0) || (pointV != null && pointV.Count > 0))
{
using (Graphics g = Graphics.FromImage(Bmp))
{
+ if (pointRGB != null && pointRGB.Count > 0)
+ {
+ foreach (var item in pointRGB)
+ g.DrawPolygon(new Pen(Brushes.Red, 2), item.Select(x => new PointF() { X = x.X, Y = x.Y }).ToArray());
+ }
if (pointS != null && pointS.Count > 0)
{
foreach (var item in pointS)
@@ -1556,6 +1559,7 @@ namespace TetraPackOCR
{
readOCR[i] = readOCR[i].Replace("_", "");
readOCR[i] = readOCR[i].Replace(" ", "");
+ readOCR[i] = readOCR[i].Replace(".", "");
}
MatchCollection matchResults;
diff --git a/TetraPackOCR/TetraPackOCR.csproj b/TetraPackOCR/TetraPackOCR.csproj
index 632ab97..827ace9 100644
--- a/TetraPackOCR/TetraPackOCR.csproj
+++ b/TetraPackOCR/TetraPackOCR.csproj
@@ -1,7 +1,7 @@
+
-
Debug
@@ -128,17 +128,17 @@
..\packages\Enums.NET.5.0.0\lib\net461\Enums.NET.dll
-
- ..\packages\EPPlus.8.2.1\lib\net462\EPPlus.dll
+
+ ..\packages\EPPlus.8.4.0\lib\net462\EPPlus.dll
-
- ..\packages\EPPlus.Interfaces.8.1.0\lib\net462\EPPlus.Interfaces.dll
+
+ ..\packages\EPPlus.Interfaces.8.4.0\lib\net462\EPPlus.Interfaces.dll
-
- ..\packages\EPPlus.System.Drawing.8.1.0\lib\net462\EPPlus.System.Drawing.dll
+
+ ..\packages\EPPlus.System.Drawing.8.4.0\lib\net462\EPPlus.System.Drawing.dll
-
- ..\packages\ExtendedNumerics.BigDecimal.3001.1.0.233\lib\net472\ExtendedNumerics.BigDecimal.dll
+
+ ..\packages\ExtendedNumerics.BigDecimal.3003.0.0.346\lib\net472\ExtendedNumerics.BigDecimal.dll
..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll
@@ -153,8 +153,8 @@
..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll
-
- ..\packages\Microsoft.Bcl.Cryptography.10.0.0-rc.2.25502.107\lib\net462\Microsoft.Bcl.Cryptography.dll
+
+ ..\packages\Microsoft.Bcl.Cryptography.10.0.1\lib\net462\Microsoft.Bcl.Cryptography.dll
..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll
@@ -183,8 +183,8 @@
..\packages\OpenCvSharp4.Extensions.4.11.0.20250507\lib\netstandard2.0\OpenCvSharp.Extensions.dll
-
- ..\packages\PaddleOCRSharp.5.1.0\lib\net47\PaddleOCRSharp.dll
+
+ ..\packages\PaddleOCRSharp.6.0.0\lib\net47\PaddleOCRSharp.dll
@@ -206,10 +206,10 @@
- ..\packages\System.Drawing.Common.10.0.0-rc.2.25502.107\lib\net462\System.Drawing.Common.dll
+ ..\packages\System.Drawing.Common.10.0.1\lib\net462\System.Drawing.Common.dll
-
- ..\packages\System.Formats.Asn1.10.0.0-rc.2.25502.107\lib\net462\System.Formats.Asn1.dll
+
+ ..\packages\System.Formats.Asn1.10.0.1\lib\net462\System.Formats.Asn1.dll
..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
@@ -238,11 +238,11 @@
-
- ..\packages\System.Security.Cryptography.Xml.10.0.0-rc.2.25502.107\lib\net462\System.Security.Cryptography.Xml.dll
+
+ ..\packages\System.Security.Cryptography.Xml.10.0.1\lib\net462\System.Security.Cryptography.Xml.dll
-
- ..\packages\System.Text.Encoding.CodePages.10.0.0-rc.2.25502.107\lib\net462\System.Text.Encoding.CodePages.dll
+
+ ..\packages\System.Text.Encoding.CodePages.10.0.1\lib\net462\System.Text.Encoding.CodePages.dll
@@ -340,13 +340,13 @@
这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
-
-
-
+
+
+
-
-
+
+
\ No newline at end of file
diff --git a/TetraPackOCR/packages.config b/TetraPackOCR/packages.config
index 3fd4c87..7ed510b 100644
--- a/TetraPackOCR/packages.config
+++ b/TetraPackOCR/packages.config
@@ -2,12 +2,12 @@
-
-
-
-
+
+
+
+
-
+
@@ -15,24 +15,24 @@
-
-
+
+
-
+
-
-
+
+
-
-
+
+