Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

添加.Net C# 项目

benjaminwan367fa5b0ba39
diff --git a/dotnet/BaiPiaoOcrOnnxCs/.gitignore b/dotnet/BaiPiaoOcrOnnxCs/.gitignore
new file mode 100755
index 0000000..b50b465
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/.gitignore
@@ -0,0 +1,164 @@
+/.svn/entries
+.svn
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+# Enable nuget packages restore when building
+!packages/
+packages/*
+!packages/repositories.config
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+#Visual Studio LightSwitch
+_Pvt_Extensions/
+GeneratedArtifacts/
+ServiceConfiguration.cscfg
+ModelManifest.xml
+generated.parameters.xml
+## TODO: Comment the next line if you want version controls the generated client .xap file
+*.Client.xap
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+# =========================
+# Windows detritus
+# =========================
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+# VisualStudioCode
+.vs
diff --git a/dotnet/BaiPiaoOcrOnnxCs/BaiPiaoOcrOnnxCs.sln b/dotnet/BaiPiaoOcrOnnxCs/BaiPiaoOcrOnnxCs.sln
new file mode 100755
index 0000000..7c866ed
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/BaiPiaoOcrOnnxCs.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.1340
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OcrOnnxForm", "OcrOnnxForm\OcrOnnxForm.csproj", "{43A96152-8891-4505-8389-32276F3A9422}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OcrLib", "OcrLib\OcrLib.csproj", "{AB10D356-2D95-4460-96CA-9A7129AD0A76}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {43A96152-8891-4505-8389-32276F3A9422}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {43A96152-8891-4505-8389-32276F3A9422}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {43A96152-8891-4505-8389-32276F3A9422}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {43A96152-8891-4505-8389-32276F3A9422}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AB10D356-2D95-4460-96CA-9A7129AD0A76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AB10D356-2D95-4460-96CA-9A7129AD0A76}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AB10D356-2D95-4460-96CA-9A7129AD0A76}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AB10D356-2D95-4460-96CA-9A7129AD0A76}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {6B47A7DB-6FE4-4943-9806-6D54D2BEC392}
+ EndGlobalSection
+EndGlobal
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/AngleNet.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/AngleNet.cs
new file mode 100755
index 0000000..1893351
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/AngleNet.cs
@@ -0,0 +1,171 @@
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using Emgu.CV.Structure;
+using Microsoft.ML.OnnxRuntime;
+using Microsoft.ML.OnnxRuntime.Tensors;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+
+namespace OcrLiteLib
+{
+ class AngleNet
+ {
+ private readonly float[] MeanValues = { 127.5F, 127.5F, 127.5F };
+ private readonly float[] NormValues = { 1.0F / 127.5F, 1.0F / 127.5F, 1.0F / 127.5F };
+ private const int angleDstWidth = 192;
+ private const int angleDstHeight = 48;
+ private const int angleCols = 2;
+ private InferenceSession angleNet;
+ private List<string> inputNames;
+
+ public AngleNet() { }
+
+ ~AngleNet()
+ {
+ angleNet.Dispose();
+ }
+
+ public void InitModel(string path, int numThread)
+ {
+ try
+ {
+ SessionOptions op = new SessionOptions();
+ op.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_EXTENDED;
+ op.InterOpNumThreads = numThread;
+ op.IntraOpNumThreads = numThread;
+ angleNet = new InferenceSession(path);
+ inputNames = angleNet.InputMetadata.Keys.ToList();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ throw ex;
+ }
+ }
+
+ public List<Angle> GetAngles(List<Mat> partImgs, bool doAngle, bool mostAngle)
+ {
+ List<Angle> angles = new List<Angle>();
+ if (doAngle)
+ {
+ for (int i = 0; i < partImgs.Count; i++)
+ {
+ var startTicks = DateTime.Now.Ticks;
+ var angle = GetAngle(partImgs[i]);
+ var endTicks = DateTime.Now.Ticks;
+ var angleTime = (endTicks - startTicks) / 10000F;
+ angle.Time = angleTime;
+ angles.Add(angle);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < partImgs.Count; i++)
+ {
+ var angle = new Angle();
+ angle.Index = -1;
+ angle.Score = 0F;
+ angles.Add(angle);
+ }
+ }
+ //Most Possible AngleIndex
+ if (doAngle && mostAngle)
+ {
+ List<int> angleIndexes = new List<int>();
+ angles.ForEach(x => angleIndexes.Add(x.Index));
+
+ double sum = angleIndexes.Sum();
+ double halfPercent = angles.Count / 2.0f;
+ int mostAngleIndex;
+ if (sum < halfPercent)
+ {//all angle set to 0
+ mostAngleIndex = 0;
+ }
+ else
+ {//all angle set to 1
+ mostAngleIndex = 1;
+ }
+ Console.WriteLine($"Set All Angle to mostAngleIndex({mostAngleIndex})");
+ for (int i = 0; i < angles.Count; ++i)
+ {
+ Angle angle = angles[i];
+ angle.Index = mostAngleIndex;
+ angles[i] = angle;
+ }
+ }
+ return angles;
+ }
+
+ private Angle GetAngle(Mat src)
+ {
+ Angle angle = new Angle();
+ Mat angleImg = new Mat();
+ CvInvoke.Resize(src, angleImg, new Size(angleDstWidth, angleDstHeight));
+ Tensor<float> inputTensors = OcrUtils.SubstractMeanNormalize(angleImg, MeanValues, NormValues);
+ var inputs = new List<NamedOnnxValue>
+ {
+ NamedOnnxValue.CreateFromTensor(inputNames[0], inputTensors)
+ };
+ try
+ {
+ using (IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results = angleNet.Run(inputs))
+ {
+ var resultsArray = results.ToArray();
+ Console.WriteLine(resultsArray);
+ float[] outputData = resultsArray[0].AsEnumerable<float>().ToArray();
+ return ScoreToAngle(outputData, angleCols);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ //throw ex;
+ }
+ return angle;
+
+ }
+
+ private Angle ScoreToAngle(float[] srcData, int angleCols)
+ {
+ Angle angle = new Angle();
+ int angleIndex = 0;
+ float maxValue = -1000.0F;
+ for (int i = 0; i < angleCols; i++)
+ {
+ if (i == 0) maxValue = srcData[i];
+ else if (srcData[i] > maxValue)
+ {
+ angleIndex = i;
+ maxValue = srcData[i];
+ }
+ }
+ angle.Index = angleIndex;
+ angle.Score = maxValue;
+ return angle;
+ }
+
+ private Mat AdjustTargetImg(Mat src, int dstWidth, int dstHeight)
+ {
+ Mat srcResize = new Mat();
+ float scale = (float)dstHeight / (float)src.Rows;
+ int angleWidth = (int)((float)src.Cols * scale);
+ CvInvoke.Resize(src, srcResize, new Size(angleWidth, dstHeight));
+ Mat srcFit = new Mat(dstHeight, dstWidth, DepthType.Cv8U, 3);
+ //srcFit.SetTo(new MCvScalar(255,255,255));
+ if (angleWidth < dstWidth)
+ {
+ CvInvoke.CopyMakeBorder(srcResize, srcFit, 0, 0, 0, dstWidth - angleWidth, BorderType.Isolated, new MCvScalar(255, 255, 255));
+ }
+ else
+ {
+ Rectangle rect = new Rectangle(0, 0, dstWidth, dstHeight);
+ Mat partAngle = new Mat(srcResize, rect);
+ partAngle.CopyTo(srcFit);
+ }
+ return srcFit;
+ }
+
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/CrnnNet.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/CrnnNet.cs
new file mode 100755
index 0000000..76c0ba4
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/CrnnNet.cs
@@ -0,0 +1,149 @@
+using Emgu.CV;
+using Microsoft.ML.OnnxRuntime;
+using Microsoft.ML.OnnxRuntime.Tensors;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace OcrLiteLib
+{
+ class CrnnNet
+ {
+ private readonly float[] MeanValues = { 127.5F, 127.5F, 127.5F };
+ private readonly float[] NormValues = { 1.0F / 127.5F, 1.0F / 127.5F, 1.0F / 127.5F };
+ private const int crnnDstHeight = 32;
+ private const int crnnCols = 6625;
+
+ private InferenceSession crnnNet;
+ private List<string> keys;
+ private List<string> inputNames;
+
+ public CrnnNet() { }
+
+ ~CrnnNet()
+ {
+ crnnNet.Dispose();
+ }
+
+ public void InitModel(string path, string keysPath, int numThread)
+ {
+ try
+ {
+ SessionOptions op = new SessionOptions();
+ op.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_EXTENDED;
+ op.InterOpNumThreads = numThread;
+ op.IntraOpNumThreads = numThread;
+ crnnNet = new InferenceSession(path, op);
+ inputNames = crnnNet.InputMetadata.Keys.ToList();
+ keys = InitKeys(keysPath);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ throw ex;
+ }
+ }
+ private List<string> InitKeys(string path)
+ {
+ StreamReader sr = new StreamReader(path, Encoding.UTF8);
+ List<string> keys = new List<string>();
+ keys.Add("#");
+ String line;
+ while ((line = sr.ReadLine()) != null)
+ {
+ //Console.WriteLine(line.ToString());
+ keys.Add(line);
+ }
+ keys.Add(" ");
+ Console.WriteLine($"keys Size = {keys.Count}");
+ return keys;
+ }
+
+ public List<TextLine> GetTextLines(List<Mat> partImgs)
+ {
+ List<TextLine> textLines = new List<TextLine>();
+ for (int i = 0; i < partImgs.Count; i++)
+ {
+ var startTicks = DateTime.Now.Ticks;
+ var textLine = GetTextLine(partImgs[i]);
+ var endTicks = DateTime.Now.Ticks;
+ var crnnTime = (endTicks - startTicks) / 10000F;
+ textLine.Time = crnnTime;
+ textLines.Add(textLine);
+ }
+ return textLines;
+ }
+
+ private TextLine GetTextLine(Mat src)
+ {
+ TextLine textLine = new TextLine();
+
+ float scale = (float)crnnDstHeight / (float)src.Rows;
+ int dstWidth = (int)((float)src.Cols * scale);
+
+ Mat srcResize = new Mat();
+ CvInvoke.Resize(src, srcResize, new Size(dstWidth, crnnDstHeight));
+ Tensor<float> inputTensors = OcrUtils.SubstractMeanNormalize(srcResize, MeanValues, NormValues);
+ var inputs = new List<NamedOnnxValue>
+ {
+ NamedOnnxValue.CreateFromTensor(inputNames[0], inputTensors)
+ };
+ try
+ {
+ using (IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results = crnnNet.Run(inputs))
+ {
+ var resultsArray = results.ToArray();
+ var dimensions = resultsArray[0].AsTensor<float>().Dimensions;
+ float[] outputData = resultsArray[0].AsEnumerable<float>().ToArray();
+
+ return ScoreToTextLine(outputData, dimensions[1], dimensions[2]);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ //throw ex;
+ }
+
+ return textLine;
+ }
+
+ private TextLine ScoreToTextLine(float[] srcData, int h, int w)
+ {
+ StringBuilder sb = new StringBuilder();
+ TextLine textLine = new TextLine();
+
+ int lastIndex = 0;
+ List<float> scores = new List<float>();
+
+ for (int i = 0; i < h; i++)
+ {
+ int maxIndex = 0;
+ float maxValue = -1000F;
+ for (int j = 0; j < w; j++)
+ {
+ int idx = i * w + j;
+ if (srcData[idx] > maxValue)
+ {
+ maxIndex = j;
+ maxValue = srcData[idx];
+ }
+ }
+
+ if (maxIndex > 0 && maxIndex < keys.Count && (!(i > 0 && maxIndex == lastIndex)))
+ {
+ scores.Add(maxValue);
+ sb.Append(keys[maxIndex]);
+ }
+ lastIndex = maxIndex;
+ }
+ textLine.Text = sb.ToString();
+ textLine.CharScores = scores;
+ return textLine;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/DbNet.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/DbNet.cs
new file mode 100755
index 0000000..9122547
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/DbNet.cs
@@ -0,0 +1,400 @@
+using ClipperLib;
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using Emgu.CV.Structure;
+using Emgu.CV.Util;
+using Microsoft.ML.OnnxRuntime;
+using Microsoft.ML.OnnxRuntime.Tensors;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+
+namespace OcrLiteLib
+{
+ class DbNet
+ {
+ private readonly float[] MeanValues = { 0.485F * 255F, 0.456F * 255F, 0.406F * 255F };
+ private readonly float[] NormValues = { 1.0F / 0.229F / 255.0F, 1.0F / 0.224F / 255.0F, 1.0F / 0.225F / 255.0F };
+
+ private InferenceSession dbNet;
+
+ private List<string> inputNames;
+
+ public DbNet() { }
+
+ ~DbNet()
+ {
+ dbNet.Dispose();
+ }
+
+ public void InitModel(string path, int numThread)
+ {
+ try
+ {
+ SessionOptions op = new SessionOptions();
+ op.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_EXTENDED;
+ op.InterOpNumThreads = numThread;
+ op.IntraOpNumThreads = numThread;
+ dbNet = new InferenceSession(path, op);
+ inputNames = dbNet.InputMetadata.Keys.ToList();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ throw ex;
+ }
+ }
+
+ public List<TextBox> GetTextBoxes(Mat src, ScaleParam scale, float boxScoreThresh, float boxThresh, float unClipRatio)
+ {
+ Mat srcResize = new Mat();
+ CvInvoke.Resize(src, srcResize, new Size(scale.DstWidth, scale.DstHeight));
+ Tensor<float> inputTensors = OcrUtils.SubstractMeanNormalize(srcResize, MeanValues, NormValues);
+ var inputs = new List<NamedOnnxValue>
+ {
+ NamedOnnxValue.CreateFromTensor(inputNames[0], inputTensors)
+ };
+ try
+ {
+ using (IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results = dbNet.Run(inputs))
+ {
+ var resultsArray = results.ToArray();
+ Console.WriteLine(resultsArray);
+ var textBoxes = GetTextBoxes(resultsArray, srcResize.Rows, srcResize.Cols, scale, boxScoreThresh, boxThresh, unClipRatio);
+ return textBoxes;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ }
+ return null;
+ }
+
+ private static List<TextBox> GetTextBoxes(DisposableNamedOnnxValue[] outputTensor, int rows, int cols, ScaleParam s, float boxScoreThresh, float boxThresh, float unClipRatio)
+ {
+ float maxSideThresh = 3.0f;//长边门限
+ List<TextBox> rsBoxes = new List<TextBox>();
+ //-----Data preparation-----
+ float[] predData = outputTensor[0].AsEnumerable<float>().ToArray();
+ List<byte> cbufData = new List<byte>();
+ foreach (float data in predData)
+ {
+ var val = data * 255;
+ cbufData.Add(Convert.ToByte(val));
+ }
+ Mat predMat = new Mat(rows, cols, DepthType.Cv32F, 1);
+ predMat.SetTo(predData);
+
+ Mat cbufMat = new Mat(rows, cols, DepthType.Cv8U, 1);
+ cbufMat.SetTo(cbufData.ToArray());
+
+ //-----boxThresh-----
+ Mat thresholdMat = new Mat();
+ CvInvoke.Threshold(cbufMat, thresholdMat, boxThresh * 255.0, 255.0, ThresholdType.Binary);
+
+ //-----dilate-----
+ Mat dilateMat = new Mat();
+ Mat dilateElement = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2, 2), new Point(-1, -1));
+ CvInvoke.Dilate(thresholdMat, dilateMat, dilateElement, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(128, 128, 128));
+
+ VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
+
+ CvInvoke.FindContours(dilateMat, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
+
+ for (int i = 0; i < contours.Size; i++)
+ {
+ if (contours[i].Size <= 2)
+ {
+ continue;
+ }
+ float maxSide = 0;
+ List<PointF> minBox = GetMiniBox(contours[i], out maxSide);
+ if (maxSide < maxSideThresh)
+ {
+ continue;
+ }
+ double score = GetScore(contours[i], predMat);
+ if (score < boxScoreThresh)
+ {
+ continue;
+ }
+ List<Point> clipBox = Unclip(minBox, unClipRatio);
+ if (clipBox == null)
+ {
+ continue;
+ }
+
+ List<PointF> clipMinBox = GetMiniBox(clipBox, out maxSide);
+ if (maxSide < maxSideThresh + 2)
+ {
+ continue;
+ }
+ List<Point> finalPoints = new List<Point>();
+ foreach (var item in clipMinBox)
+ {
+ int x = (int)(item.X / s.ScaleWidth);
+ int ptx = Math.Min(Math.Max(x, 0), s.SrcWidth);
+
+ int y = (int)(item.Y / s.ScaleHeight);
+ int pty = Math.Min(Math.Max(y, 0), s.SrcHeight);
+ Point dstPt = new Point(ptx, pty);
+ finalPoints.Add(dstPt);
+ }
+
+ TextBox textBox = new TextBox();
+ textBox.Score = (float)score;
+ textBox.Points = finalPoints;
+ rsBoxes.Add(textBox);
+ }
+ rsBoxes.Reverse();
+ return rsBoxes;
+ }
+
+ private static List<PointF> GetMiniBox(List<Point> contours, out float minEdgeSize)
+ {
+ VectorOfPoint vop = new VectorOfPoint();
+ vop.Push(contours.ToArray<Point>());
+ return GetMiniBox(vop, out minEdgeSize);
+ }
+
+ private static List<PointF> GetMiniBox(VectorOfPoint contours, out float minEdgeSize)
+ {
+ List<PointF> box = new List<PointF>();
+ RotatedRect rrect = CvInvoke.MinAreaRect(contours);
+ PointF[] points = CvInvoke.BoxPoints(rrect);
+ minEdgeSize = Math.Min(rrect.Size.Width, rrect.Size.Height);
+
+ List<PointF> thePoints = new List<PointF>(points);
+ thePoints.Sort(CompareByX);
+
+ int index_1 = 0, index_2 = 1, index_3 = 2, index_4 = 3;
+ if (thePoints[1].Y > thePoints[0].Y)
+ {
+ index_1 = 0;
+ index_4 = 1;
+ }
+ else
+ {
+ index_1 = 1;
+ index_4 = 0;
+ }
+
+ if (thePoints[3].Y > thePoints[2].Y)
+ {
+ index_2 = 2;
+ index_3 = 3;
+ }
+ else
+ {
+ index_2 = 3;
+ index_3 = 2;
+ }
+
+ box.Add(thePoints[index_1]);
+ box.Add(thePoints[index_2]);
+ box.Add(thePoints[index_3]);
+ box.Add(thePoints[index_4]);
+
+ return box;
+ }
+
+ public static int CompareByX(PointF left, PointF right)
+ {
+ if (left == null && right == null)
+ {
+ return 1;
+ }
+
+ if (left == null)
+ {
+ return 0;
+ }
+
+ if (right == null)
+ {
+ return 1;
+ }
+
+ if (left.X > right.X)
+ {
+ return 1;
+ }
+
+ if (left.X == right.X)
+ {
+ return 0;
+ }
+
+ return -1;
+ }
+
+ private static double GetScore(VectorOfPoint contours, Mat fMapMat)
+ {
+ short xmin = 9999;
+ short xmax = 0;
+ short ymin = 9999;
+ short ymax = 0;
+
+ try
+ {
+ foreach (Point point in contours.ToArray())
+ {
+ if (point.X < xmin)
+ {
+ //var xx = nd[point.X];
+ xmin = (short)point.X;
+ }
+
+ if (point.X > xmax)
+ {
+ xmax = (short)point.X;
+ }
+
+ if (point.Y < ymin)
+ {
+ ymin = (short)point.Y;
+ }
+
+ if (point.Y > ymax)
+ {
+ ymax = (short)point.Y;
+ }
+ }
+
+ int roiWidth = xmax - xmin + 1;
+ int roiHeight = ymax - ymin + 1;
+
+ Image<Gray, float> bitmap = fMapMat.ToImage<Gray, float>();
+ Image<Gray, float> roiBitmap = new Image<Gray, float>(roiWidth, roiHeight);
+ float[,,] dataFloat = bitmap.Data;
+ float[,,] data = roiBitmap.Data;
+
+ for (int j = ymin; j < ymin + roiHeight; j++)
+ {
+ for (int i = xmin; i < xmin + roiWidth; i++)
+ {
+ try
+ {
+ data[j - ymin, i - xmin, 0] = dataFloat[j, i, 0];
+ }
+ catch (Exception ex2)
+ {
+ Console.WriteLine(ex2.Message);
+ }
+ }
+ }
+
+ Mat mask = Mat.Zeros(roiHeight, roiWidth, DepthType.Cv8U, 1);
+ List<Point> pts = new List<Point>();
+ foreach (Point point in contours.ToArray())
+ {
+ pts.Add(new Point(point.X - xmin, point.Y - ymin));
+ }
+
+ using (VectorOfPoint vp = new VectorOfPoint(pts.ToArray<Point>()))
+ using (VectorOfVectorOfPoint vvp = new VectorOfVectorOfPoint(vp))
+ {
+ CvInvoke.FillPoly(mask, vvp, new MCvScalar(1));
+ }
+
+ return CvInvoke.Mean(roiBitmap, mask).V0;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ }
+
+ return 0;
+ }
+
+ private static List<Point> Unclip(List<PointF> box, float unclip_ratio)
+ {
+ RotatedRect clipRect = CvInvoke.MinAreaRect(box.ToArray());
+ if (clipRect.Size.Height < 1.001 && clipRect.Size.Width < 1.001)
+ {
+ return null;
+ }
+
+ List<IntPoint> theCliperPts = new List<IntPoint>();
+ foreach (PointF pt in box)
+ {
+ IntPoint a1 = new IntPoint((int)pt.X, (int)pt.Y);
+ theCliperPts.Add(a1);
+ }
+
+ float area = Math.Abs(SignedPolygonArea(box.ToArray<PointF>()));
+ double length = LengthOfPoints(box);
+ double distance = area * unclip_ratio / length;
+
+ ClipperOffset co = new ClipperOffset();
+ co.AddPath(theCliperPts, JoinType.jtRound, EndType.etClosedPolygon);
+ List<List<IntPoint>> solution = new List<List<IntPoint>>();
+ co.Execute(ref solution, distance);
+ if (solution.Count == 0)
+ {
+ return null;
+ }
+
+ List<Point> retPts = new List<Point>();
+ foreach (IntPoint ip in solution[0])
+ {
+ retPts.Add(new Point((int)ip.X, (int)ip.Y));
+ }
+
+ return retPts;
+ }
+
+ private static float SignedPolygonArea(PointF[] Points)
+ {
+ // Add the first point to the end.
+ int num_points = Points.Length;
+ PointF[] pts = new PointF[num_points + 1];
+ Points.CopyTo(pts, 0);
+ pts[num_points] = Points[0];
+
+ // Get the areas.
+ float area = 0;
+ for (int i = 0; i < num_points; i++)
+ {
+ area +=
+ (pts[i + 1].X - pts[i].X) *
+ (pts[i + 1].Y + pts[i].Y) / 2;
+ }
+
+ return area;
+ }
+
+ private static double LengthOfPoints(List<PointF> box)
+ {
+ double length = 0;
+
+ PointF pt = box[0];
+ double x0 = pt.X;
+ double y0 = pt.Y;
+ double x1 = 0, y1 = 0, dx = 0, dy = 0;
+ box.Add(pt);
+
+ int count = box.Count;
+ for (int idx = 1; idx < count; idx++)
+ {
+ PointF pts = box[idx];
+ x1 = pts.X;
+ y1 = pts.Y;
+ dx = x1 - x0;
+ dy = y1 - y0;
+
+ length += Math.Sqrt(dx * dx + dy * dy);
+
+ x0 = x1;
+ y0 = y1;
+ }
+
+ box.RemoveAt(count - 1);
+ return length;
+ }
+
+ }
+}
+
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLib.csproj b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLib.csproj
new file mode 100755
index 0000000..6922b26
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLib.csproj
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.props" Condition="Exists('..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.props')" />
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{AB10D356-2D95-4460-96CA-9A7129AD0A76}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>OcrLib</RootNamespace>
+ <AssemblyName>OcrLib</AssemblyName>
+ <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <Deterministic>true</Deterministic>
+ <NuGetPackageImportStamp>
+ </NuGetPackageImportStamp>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <PlatformTarget>x64</PlatformTarget>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="clipper_library, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\clipper_library.6.2.1\lib\net40\clipper_library.dll</HintPath>
+ </Reference>
+ <Reference Include="Emgu.CV.Platform.NetStandard, Version=4.4.0.4099, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
+ <HintPath>..\packages\Emgu.CV.4.4.0.4099\lib\netstandard2.0\Emgu.CV.Platform.NetStandard.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.ML.OnnxRuntime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=f27f157f0a5b7bb6, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.ML.OnnxRuntime.Managed.1.6.0\lib\netstandard1.1\Microsoft.ML.OnnxRuntime.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
+ </Reference>
+ <Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Core" />
+ <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Drawing.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Drawing.Primitives.4.3.0\lib\net45\System.Drawing.Primitives.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.IO.Compression.FileSystem" />
+ <Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Numerics" />
+ <Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath>
+ <Private>True</Private>
+ <Private>True</Private>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AngleNet.cs" />
+ <Compile Include="CrnnNet.cs" />
+ <Compile Include="DbNet.cs" />
+ <Compile Include="OcrLite.cs" />
+ <Compile Include="OcrResult.cs" />
+ <Compile Include="OcrUtils.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ScaleParam.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="..\packages\Emgu.CV.runtime.windows.4.4.0.4099\build\Emgu.CV.runtime.windows.targets" Condition="Exists('..\packages\Emgu.CV.runtime.windows.4.4.0.4099\build\Emgu.CV.runtime.windows.targets')" />
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+ <PropertyGroup>
+ <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+ </PropertyGroup>
+ <Error Condition="!Exists('..\packages\Emgu.CV.runtime.windows.4.4.0.4099\build\Emgu.CV.runtime.windows.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Emgu.CV.runtime.windows.4.4.0.4099\build\Emgu.CV.runtime.windows.targets'))" />
+ <Error Condition="!Exists('..\packages\Microsoft.ML.OnnxRuntime.Managed.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.Managed.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.OnnxRuntime.Managed.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.Managed.targets'))" />
+ <Error Condition="!Exists('..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.props'))" />
+ <Error Condition="!Exists('..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.targets'))" />
+ </Target>
+ <Import Project="..\packages\Microsoft.ML.OnnxRuntime.Managed.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.Managed.targets" Condition="Exists('..\packages\Microsoft.ML.OnnxRuntime.Managed.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.Managed.targets')" />
+ <Import Project="..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.targets" Condition="Exists('..\packages\Microsoft.ML.OnnxRuntime.1.6.0\build\netstandard1.1\Microsoft.ML.OnnxRuntime.targets')" />
+</Project>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLite.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLite.cs
new file mode 100755
index 0000000..ed13d61
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrLite.cs
@@ -0,0 +1,153 @@
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Text;
+
+namespace OcrLiteLib
+{
+ public class OcrLite
+ {
+ public bool isPartImg { get; set; }
+ public bool isDebugImg { get; set; }
+ private DbNet dbNet;
+ private AngleNet angleNet;
+ private CrnnNet crnnNet;
+
+ public OcrLite()
+ {
+ dbNet = new DbNet();
+ angleNet = new AngleNet();
+ crnnNet = new CrnnNet();
+ }
+
+ public void InitModels(string detPath, string clsPath, string recPath, string keysPath, int numThread)
+ {
+ try
+ {
+ dbNet.InitModel(detPath, numThread);
+ angleNet.InitModel(clsPath, numThread);
+ crnnNet.InitModel(recPath, keysPath, numThread);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message + ex.StackTrace);
+ throw ex;
+ }
+ }
+
+ public OcrResult Detect(string img, int padding, int maxSideLen, float boxScoreThresh, float boxThresh,
+ float unClipRatio, bool doAngle, bool mostAngle)
+ {
+ Mat originSrc = CvInvoke.Imread(img, ImreadModes.Color);//default : BGR
+ int originMaxSide = Math.Max(originSrc.Cols, originSrc.Rows);
+
+ int resize;
+ if (maxSideLen <= 0 || maxSideLen > originMaxSide)
+ {
+ resize = originMaxSide;
+ }
+ else
+ {
+ resize = maxSideLen;
+ }
+ resize += 2 * padding;
+ Rectangle paddingRect = new Rectangle(padding, padding, originSrc.Cols, originSrc.Rows);
+ Mat paddingSrc = OcrUtils.MakePadding(originSrc, padding);
+
+ ScaleParam scale = ScaleParam.GetScaleParam(paddingSrc, resize);
+
+ return DetectOnce(paddingSrc, paddingRect, scale, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);
+ }
+
+ private OcrResult DetectOnce(Mat src, Rectangle originRect, ScaleParam scale, float boxScoreThresh, float boxThresh,
+ float unClipRatio, bool doAngle, bool mostAngle)
+ {
+ Mat textBoxPaddingImg = src.Clone();
+ int thickness = OcrUtils.GetThickness(src);
+ Console.WriteLine("=====Start detect=====");
+ var startTicks = DateTime.Now.Ticks;
+
+ Console.WriteLine("---------- step: dbNet getTextBoxes ----------");
+ var textBoxes = dbNet.GetTextBoxes(src, scale, boxScoreThresh, boxThresh, unClipRatio);
+ var dbNetTime = (DateTime.Now.Ticks - startTicks) / 10000F;
+
+ Console.WriteLine($"TextBoxesSize({textBoxes.Count})");
+ textBoxes.ForEach(x => Console.WriteLine(x));
+ //Console.WriteLine($"dbNetTime({dbNetTime}ms)");
+
+ Console.WriteLine("---------- step: drawTextBoxes ----------");
+ OcrUtils.DrawTextBoxes(textBoxPaddingImg, textBoxes, thickness);
+ //CvInvoke.Imshow("ResultPadding", textBoxPaddingImg);
+
+ //---------- getPartImages ----------
+ List<Mat> partImages = OcrUtils.GetPartImages(src, textBoxes);
+ if (isPartImg)
+ {
+ for (int i = 0; i < partImages.Count; i++)
+ {
+ CvInvoke.Imshow($"PartImg({i})", partImages[i]);
+ }
+ }
+
+ Console.WriteLine("---------- step: angleNet getAngles ----------");
+ List<Angle> angles = angleNet.GetAngles(partImages, doAngle, mostAngle);
+ //angles.ForEach(x => Console.WriteLine(x));
+
+ //Rotate partImgs
+ for (int i = 0; i < partImages.Count; ++i)
+ {
+ if (angles[i].Index == 1)
+ {
+ partImages[i] = OcrUtils.MatRotateClockWise180(partImages[i]);
+ }
+ if (isDebugImg)
+ {
+ CvInvoke.Imshow($"DebugImg({i})", partImages[i]);
+ }
+ }
+
+ Console.WriteLine("---------- step: crnnNet getTextLines ----------");
+ List<TextLine> textLines = crnnNet.GetTextLines(partImages);
+ //textLines.ForEach(x => Console.WriteLine(x));
+
+ List<TextBlock> textBlocks = new List<TextBlock>();
+ for (int i = 0; i < textLines.Count; ++i)
+ {
+ TextBlock textBlock = new TextBlock();
+ textBlock.BoxPoints = textBoxes[i].Points;
+ textBlock.BoxScore = textBoxes[i].Score;
+ textBlock.AngleIndex = angles[i].Index;
+ textBlock.AngleScore = angles[i].Score;
+ textBlock.AngleTime = angles[i].Time;
+ textBlock.Text = textLines[i].Text;
+ textBlock.CharScores = textLines[i].CharScores;
+ textBlock.CrnnTime = textLines[i].Time;
+ textBlock.BlockTime = angles[i].Time + textLines[i].Time;
+ textBlocks.Add(textBlock);
+ }
+ //textBlocks.ForEach(x => Console.WriteLine(x));
+
+ var endTicks = DateTime.Now.Ticks;
+ var fullDetectTime = (endTicks - startTicks) / 10000F;
+ //Console.WriteLine($"fullDetectTime({fullDetectTime}ms)");
+
+ //cropped to original size
+ Mat boxImg = new Mat(textBoxPaddingImg, originRect);
+
+ StringBuilder strRes = new StringBuilder();
+ textBlocks.ForEach(x => strRes.AppendLine(x.Text));
+
+ OcrResult ocrResult = new OcrResult();
+ ocrResult.TextBlocks = textBlocks;
+ ocrResult.DbNetTime = dbNetTime;
+ ocrResult.BoxImg = boxImg;
+ ocrResult.DetectTime = fullDetectTime;
+ ocrResult.StrRes = strRes.ToString();
+
+ return ocrResult;
+ }
+
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrResult.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrResult.cs
new file mode 100755
index 0000000..cf2f9cf
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrResult.cs
@@ -0,0 +1,90 @@
+using Emgu.CV;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Text;
+
+namespace OcrLiteLib
+{
+ public sealed class TextBox
+ {
+ public List<Point> Points { get; set; }
+ public float Score { get; set; }
+ public override string ToString()
+ {
+ return $"TextBox[score({Score}),[x: {Points[0].X}, y: {Points[0].Y}], [x: {Points[1].X}, y: {Points[1].Y}], [x: {Points[2].X}, y: {Points[2].Y}], [x: {Points[3].X}, y: {Points[3].Y}]]";
+ }
+ }
+
+ public sealed class Angle
+ {
+ public int Index { get; set; }
+ public float Score { get; set; }
+ public float Time { get; set; }
+ public override string ToString()
+ {
+ string header = Index >= 0 ? "Angle" : "AngleDisabled";
+ return $"{header}[Index({Index}), Score({Score}), Time({Time}ms)]";
+ }
+ }
+ public sealed class TextLine
+ {
+ public string Text { get; set; }
+ public List<float> CharScores { get; set; }
+ public float Time { get; set; }
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ CharScores.ForEach(x => sb.Append($"{x},"));
+ return $"TextLine[Text({Text}),CharScores({sb.ToString()}),Time({Time}ms)]";
+ }
+ }
+ public sealed class TextBlock
+ {
+ public List<Point> BoxPoints { get; set; }
+ public float BoxScore { get; set; }
+ public int AngleIndex { get; set; }
+ public float AngleScore { get; set; }
+ public float AngleTime { get; set; }
+ public string Text { get; set; }
+ public List<float> CharScores { get; set; }
+ public float CrnnTime { get; set; }
+ public float BlockTime { get; set; }
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.AppendLine("├─TextBlock");
+ string textBox = $"│ ├──TextBox[score({BoxScore}),[x: {BoxPoints[0].X}, y: {BoxPoints[0].Y}], [x: {BoxPoints[1].X}, y: {BoxPoints[1].Y}], [x: {BoxPoints[2].X}, y: {BoxPoints[2].Y}], [x: {BoxPoints[3].X}, y: {BoxPoints[3].Y}]]";
+ sb.AppendLine(textBox);
+ string header = AngleIndex >= 0 ? "Angle" : "AngleDisabled";
+ string angle = $"│ ├──{header}[Index({AngleIndex}), Score({AngleScore}), Time({AngleTime}ms)]";
+ sb.AppendLine(angle);
+ StringBuilder sbScores = new StringBuilder();
+ CharScores.ForEach(x => sbScores.Append($"{x},"));
+ string textLine = $"│ ├──TextLine[Text({Text}),CharScores({sbScores.ToString()}),Time({CrnnTime}ms)]";
+ sb.AppendLine(textLine);
+ sb.AppendLine($"│ └──BlockTime({BlockTime}ms)");
+ return sb.ToString();
+ }
+ }
+ public sealed class OcrResult
+ {
+ public List<TextBlock> TextBlocks { get; set; }
+ public float DbNetTime { get; set; }
+ public Mat BoxImg { get; set; }
+ public float DetectTime { get; set; }
+ public string StrRes { get; set; }
+
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.AppendLine("OcrResult");
+ TextBlocks.ForEach(x => sb.Append(x));
+ sb.AppendLine($"├─DbNetTime({DbNetTime}ms)");
+ sb.AppendLine($"├─DetectTime({DetectTime}ms)");
+ sb.AppendLine($"└─StrRes({StrRes})");
+ return sb.ToString();
+ }
+
+ }
+}
+
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrUtils.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrUtils.cs
new file mode 100755
index 0000000..ce2367b
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/OcrUtils.cs
@@ -0,0 +1,168 @@
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using Emgu.CV.Structure;
+using Microsoft.ML.OnnxRuntime.Tensors;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+
+namespace OcrLiteLib
+{
+ class OcrUtils
+ {
+ public static Tensor<float> SubstractMeanNormalize(Mat src, float[] meanVals, float[] normVals)
+ {
+ int cols = src.Cols;
+ int rows = src.Rows;
+ int channels = src.NumberOfChannels;
+ Image<Rgb, byte> srcImg = src.ToImage<Rgb, byte>();
+ byte[,,] imgData = srcImg.Data;
+ Tensor<float> inputTensor = new DenseTensor<float>(new[] { 1, channels, rows, cols });
+ for (int r = 0; r < rows; r++)
+ {
+ for (int c = 0; c < cols; c++)
+ {
+ for (int ch = 0; ch < channels; ch++)
+ {
+ var value = imgData[r, c, ch];
+ float data = (float)(value * normVals[ch] - meanVals[ch] * normVals[ch]);
+ inputTensor[0, ch, r, c] = data;
+ }
+ }
+ }
+ return inputTensor;
+ }
+
+ public static Mat MakePadding(Mat src, int padding)
+ {
+ if (padding <= 0) return src;
+ MCvScalar paddingScalar = new MCvScalar(255, 255, 255);
+ Mat paddingSrc = new Mat();
+ CvInvoke.CopyMakeBorder(src, paddingSrc, padding, padding, padding, padding, BorderType.Isolated, paddingScalar);
+ return paddingSrc;
+ }
+
+ public static int GetThickness(Mat boxImg)
+ {
+ int minSize = boxImg.Cols > boxImg.Rows ? boxImg.Rows : boxImg.Cols;
+ int thickness = minSize / 1000 + 2;
+ return thickness;
+ }
+
+ public static void DrawTextBox(Mat boxImg, List<Point> box, int thickness)
+ {
+ if (box == null || box.Count == 0)
+ {
+ return;
+ }
+ var color = new MCvScalar(0, 0, 255);//B(0) G(0) R(255)
+ CvInvoke.Line(boxImg, box[0], box[1], color, thickness);
+ CvInvoke.Line(boxImg, box[1], box[2], color, thickness);
+ CvInvoke.Line(boxImg, box[2], box[3], color, thickness);
+ CvInvoke.Line(boxImg, box[3], box[0], color, thickness);
+ }
+
+ public static void DrawTextBoxes(Mat src, List<TextBox> textBoxes, int thickness)
+ {
+ for (int i = 0; i < textBoxes.Count; i++)
+ {
+ TextBox t = textBoxes[i];
+ DrawTextBox(src, t.Points, thickness);
+ }
+ }
+
+ public static List<Mat> GetPartImages(Mat src, List<TextBox> textBoxes)
+ {
+ List<Mat> partImages = new List<Mat>();
+ for (int i = 0; i < textBoxes.Count; ++i)
+ {
+ Mat partImg = GetRotateCropImage(src, textBoxes[i].Points);
+ //Mat partImg = new Mat();
+ //GetRoiFromBox(src, partImg, textBoxes[i].Points);
+ partImages.Add(partImg);
+ }
+ return partImages;
+ }
+
+ public static Mat GetRotateCropImage(Mat src, List<Point> box)
+ {
+ Mat image = new Mat();
+ src.CopyTo(image);
+ List<Point> points = new List<Point>();
+ points.AddRange(box);
+
+ int[] collectX = { box[0].X, box[1].X, box[2].X, box[3].X };
+ int[] collectY = { box[0].Y, box[1].Y, box[2].Y, box[3].Y };
+ int left = collectX.Min();
+ int right = collectX.Max();
+ int top = collectY.Min();
+ int bottom = collectY.Max();
+
+ Rectangle rect = new Rectangle(left, top, right - left, bottom - top);
+ Mat imgCrop = new Mat(image, rect);
+
+ for (int i = 0; i < points.Count; i++)
+ {
+ var pt = points[i];
+ pt.X -= left;
+ pt.Y -= top;
+ points[i] = pt;
+ }
+
+ int imgCropWidth = (int)(Math.Sqrt(Math.Pow(points[0].X - points[1].X, 2) +
+ Math.Pow(points[0].Y - points[1].Y, 2)));
+ int imgCropHeight = (int)(Math.Sqrt(Math.Pow(points[0].X - points[3].X, 2) +
+ Math.Pow(points[0].Y - points[3].Y, 2)));
+
+ var ptsDst0 = new PointF(0, 0);
+ var ptsDst1 = new PointF(imgCropWidth, 0);
+ var ptsDst2 = new PointF(imgCropWidth, imgCropHeight);
+ var ptsDst3 = new PointF(0, imgCropHeight);
+
+ PointF[] ptsDst = { ptsDst0, ptsDst1, ptsDst2, ptsDst3 };
+
+
+ var ptsSrc0 = new PointF(points[0].X, points[0].Y);
+ var ptsSrc1 = new PointF(points[1].X, points[1].Y);
+ var ptsSrc2 = new PointF(points[2].X, points[2].Y);
+ var ptsSrc3 = new PointF(points[3].X, points[3].Y);
+
+ PointF[] ptsSrc = { ptsSrc0, ptsSrc1, ptsSrc2, ptsSrc3 };
+
+ Mat M = CvInvoke.GetPerspectiveTransform(ptsSrc, ptsDst);
+
+ Mat partImg = new Mat();
+ CvInvoke.WarpPerspective(imgCrop, partImg, M,
+ new Size(imgCropWidth, imgCropHeight), Inter.Nearest, Warp.Default,
+ BorderType.Replicate);
+
+ if (partImg.Rows >= partImg.Cols * 1.5)
+ {
+ Mat srcCopy = new Mat();
+ CvInvoke.Transpose(partImg, srcCopy);
+ CvInvoke.Flip(srcCopy, srcCopy, 0);
+ return srcCopy;
+ }
+ else
+ {
+ return partImg;
+ }
+ }
+
+ public static Mat MatRotateClockWise180(Mat src)
+ {
+ CvInvoke.Flip(src, src, FlipType.Vertical);
+ CvInvoke.Flip(src, src, FlipType.Horizontal);
+ return src;
+ }
+
+ public static Mat MatRotateClockWise90(Mat src)
+ {
+ CvInvoke.Rotate(src, src, RotateFlags.Rotate90CounterClockwise);
+ return src;
+ }
+
+ }
+}
+
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/Properties/AssemblyInfo.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/Properties/AssemblyInfo.cs
new file mode 100755
index 0000000..592e61b
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("OcrLib")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("OcrLib")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("ab10d356-2d95-4460-96ca-9a7129ad0a76")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/ScaleParam.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/ScaleParam.cs
new file mode 100755
index 0000000..2812ab8
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/ScaleParam.cs
@@ -0,0 +1,75 @@
+using Emgu.CV;
+using System;
+
+namespace OcrLiteLib
+{
+ class ScaleParam
+ {
+ int srcWidth;
+ int srcHeight;
+ int dstWidth;
+ int dstHeight;
+ float scaleWidth;
+ float scaleHeight;
+
+ public int SrcWidth { get => srcWidth; set => srcWidth = value; }
+ public int SrcHeight { get => srcHeight; set => srcHeight = value; }
+ public int DstWidth { get => dstWidth; set => dstWidth = value; }
+ public int DstHeight { get => dstHeight; set => dstHeight = value; }
+ public float ScaleWidth { get => scaleWidth; set => scaleWidth = value; }
+ public float ScaleHeight { get => scaleHeight; set => scaleHeight = value; }
+
+ public ScaleParam(int srcWidth, int srcHeight, int dstWidth, int dstHeight, float scaleWidth, float scaleHeight)
+ {
+ this.srcWidth = srcWidth;
+ this.srcHeight = srcHeight;
+ this.dstWidth = dstWidth;
+ this.dstHeight = dstHeight;
+ this.scaleWidth = scaleWidth;
+ this.scaleHeight = scaleHeight;
+ }
+
+ public override string ToString()
+ {
+ return $"sw:{this.srcWidth},sh:{this.srcHeight},dw:{this.dstWidth},dh:{this.dstHeight},{this.scaleWidth},{this.scaleHeight}";
+ }
+
+ public static ScaleParam GetScaleParam(Mat src, int dstSize)
+ {
+ int srcWidth, srcHeight, dstWidth, dstHeight;
+ srcWidth = src.Cols;
+ dstWidth = src.Cols;
+ srcHeight = src.Rows;
+ dstHeight = src.Rows;
+
+ float scale = 1.0F;
+ if (dstWidth > dstHeight)
+ {
+ scale = (float)dstSize / (float)dstWidth;
+ dstWidth = dstSize;
+ dstHeight = (int)((float)dstHeight * scale);
+ }
+ else
+ {
+ scale = (float)dstSize / (float)dstHeight;
+ dstHeight = dstSize;
+ dstWidth = (int)((float)dstWidth * scale);
+ }
+ if (dstWidth % 32 != 0)
+ {
+ dstWidth = (dstWidth / 32 - 1) * 32;
+ dstWidth = Math.Max(dstWidth, 32);
+ }
+ if (dstHeight % 32 != 0)
+ {
+ dstHeight = (dstHeight / 32 - 1) * 32;
+ dstHeight = Math.Max(dstHeight, 32);
+ }
+ float scaleWidth = (float)dstWidth / (float)srcWidth;
+ float scaleHeight = (float)dstHeight / (float)srcHeight;
+ return new ScaleParam(srcWidth, srcHeight, dstWidth, dstHeight, scaleWidth, scaleHeight);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrLib/packages.config b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/packages.config
new file mode 100755
index 0000000..312a881
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrLib/packages.config
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="clipper_library" version="6.2.1" targetFramework="net461" />
+ <package id="Emgu.CV" version="4.4.0.4099" targetFramework="net461" />
+ <package id="Emgu.CV.runtime.windows" version="4.4.0.4099" targetFramework="net461" />
+ <package id="Microsoft.ML.OnnxRuntime" version="1.6.0" targetFramework="net461" />
+ <package id="Microsoft.ML.OnnxRuntime.Managed" version="1.6.0" targetFramework="net461" />
+ <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
+ <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
+ <package id="System.AppContext" version="4.3.0" targetFramework="net461" />
+ <package id="System.Buffers" version="4.4.0" targetFramework="net461" />
+ <package id="System.Collections" version="4.3.0" targetFramework="net461" />
+ <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
+ <package id="System.Console" version="4.3.0" targetFramework="net461" />
+ <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
+ <package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
+ <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" />
+ <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" />
+ <package id="System.Drawing.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Globalization" version="4.3.0" targetFramework="net461" />
+ <package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" />
+ <package id="System.IO" version="4.3.0" targetFramework="net461" />
+ <package id="System.IO.Compression" version="4.3.0" targetFramework="net461" />
+ <package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
+ <package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" />
+ <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Linq" version="4.3.0" targetFramework="net461" />
+ <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" />
+ <package id="System.Memory" version="4.5.3" targetFramework="net461" />
+ <package id="System.Net.Http" version="4.3.0" targetFramework="net461" />
+ <package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" />
+ <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" />
+ <package id="System.ObjectModel" version="4.3.0" targetFramework="net461" />
+ <package id="System.Reflection" version="4.3.0" targetFramework="net461" />
+ <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" />
+ <package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime" version="4.3.1" targetFramework="net461" />
+ <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
+ <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
+ <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
+ <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
+ <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
+ <package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" />
+ <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" />
+ <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" />
+ <package id="System.Threading" version="4.3.0" targetFramework="net461" />
+ <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" />
+ <package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" />
+ <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" />
+ <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" />
+</packages>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/App.config b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/App.config
new file mode 100755
index 0000000..731f6de
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+ </startup>
+</configuration>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.Designer.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.Designer.cs
new file mode 100755
index 0000000..2207ebd
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.Designer.cs
@@ -0,0 +1,659 @@
+namespace BaiPiaoOcrOnnxCs
+{
+ partial class FormOcr
+ {
+ /// <summary>
+ /// 必需的设计器变量。
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// 清理所有正在使用的资源。
+ /// </summary>
+ /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows 窗体设计器生成的代码
+
+ /// <summary>
+ /// 设计器支持所需的方法 - 不要修改
+ /// 使用代码编辑器修改此方法的内容。
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.label8 = new System.Windows.Forms.Label();
+ this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
+ this.modelsTextBox = new System.Windows.Forms.TextBox();
+ this.label9 = new System.Windows.Forms.Label();
+ this.modelsBtn = new System.Windows.Forms.Button();
+ this.pathTextBox = new System.Windows.Forms.TextBox();
+ this.openBtn = new System.Windows.Forms.Button();
+ this.label1 = new System.Windows.Forms.Label();
+ this.numThreadNumeric = new System.Windows.Forms.NumericUpDown();
+ this.label6 = new System.Windows.Forms.Label();
+ this.detNameTextBox = new System.Windows.Forms.TextBox();
+ this.label10 = new System.Windows.Forms.Label();
+ this.clsNameTextBox = new System.Windows.Forms.TextBox();
+ this.label11 = new System.Windows.Forms.Label();
+ this.recNameTextBox = new System.Windows.Forms.TextBox();
+ this.label12 = new System.Windows.Forms.Label();
+ this.keysNameTextBox = new System.Windows.Forms.TextBox();
+ this.label5 = new System.Windows.Forms.Label();
+ this.boxThreshNumeric = new System.Windows.Forms.NumericUpDown();
+ this.label7 = new System.Windows.Forms.Label();
+ this.unClipRatioNumeric = new System.Windows.Forms.NumericUpDown();
+ this.doAngleCheckBox = new System.Windows.Forms.CheckBox();
+ this.mostAngleCheckBox = new System.Windows.Forms.CheckBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.imgResizeNumeric = new System.Windows.Forms.NumericUpDown();
+ this.label3 = new System.Windows.Forms.Label();
+ this.paddingNumeric = new System.Windows.Forms.NumericUpDown();
+ this.label2 = new System.Windows.Forms.Label();
+ this.boxScoreThreshNumeric = new System.Windows.Forms.NumericUpDown();
+ this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.strRestTextBox = new System.Windows.Forms.TextBox();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ this.partImgCheckBox = new System.Windows.Forms.CheckBox();
+ this.debugCheckBox = new System.Windows.Forms.CheckBox();
+ this.detectBtn = new System.Windows.Forms.Button();
+ this.initBtn = new System.Windows.Forms.Button();
+ this.ocrResultTextBox = new System.Windows.Forms.TextBox();
+ this.tableLayoutPanel2.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numThreadNumeric)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.boxThreshNumeric)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.unClipRatioNumeric)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.imgResizeNumeric)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.paddingNumeric)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.boxScoreThreshNumeric)).BeginInit();
+ this.tableLayoutPanel3.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.tableLayoutPanel1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // label8
+ //
+ this.label8.AutoSize = true;
+ this.label8.Location = new System.Drawing.Point(3, 180);
+ this.label8.Name = "label8";
+ this.label8.Size = new System.Drawing.Size(47, 12);
+ this.label8.TabIndex = 8;
+ this.label8.Text = "ImgFile";
+ //
+ // tableLayoutPanel2
+ //
+ this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.tableLayoutPanel2.ColumnCount = 3;
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80F));
+ this.tableLayoutPanel2.Controls.Add(this.modelsTextBox, 1, 0);
+ this.tableLayoutPanel2.Controls.Add(this.label9, 0, 0);
+ this.tableLayoutPanel2.Controls.Add(this.modelsBtn, 2, 0);
+ this.tableLayoutPanel2.Controls.Add(this.label8, 0, 6);
+ this.tableLayoutPanel2.Controls.Add(this.pathTextBox, 1, 6);
+ this.tableLayoutPanel2.Controls.Add(this.openBtn, 2, 6);
+ this.tableLayoutPanel2.Controls.Add(this.label1, 0, 5);
+ this.tableLayoutPanel2.Controls.Add(this.numThreadNumeric, 1, 5);
+ this.tableLayoutPanel2.Controls.Add(this.label6, 0, 1);
+ this.tableLayoutPanel2.Controls.Add(this.detNameTextBox, 1, 1);
+ this.tableLayoutPanel2.Controls.Add(this.label10, 0, 2);
+ this.tableLayoutPanel2.Controls.Add(this.clsNameTextBox, 1, 2);
+ this.tableLayoutPanel2.Controls.Add(this.label11, 0, 3);
+ this.tableLayoutPanel2.Controls.Add(this.recNameTextBox, 1, 3);
+ this.tableLayoutPanel2.Controls.Add(this.label12, 0, 4);
+ this.tableLayoutPanel2.Controls.Add(this.keysNameTextBox, 1, 4);
+ this.tableLayoutPanel2.Location = new System.Drawing.Point(14, 12);
+ this.tableLayoutPanel2.Name = "tableLayoutPanel2";
+ this.tableLayoutPanel2.RowCount = 7;
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel2.Size = new System.Drawing.Size(675, 211);
+ this.tableLayoutPanel2.TabIndex = 14;
+ //
+ // modelsTextBox
+ //
+ this.modelsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.modelsTextBox.Location = new System.Drawing.Point(103, 3);
+ this.modelsTextBox.Name = "modelsTextBox";
+ this.modelsTextBox.Size = new System.Drawing.Size(489, 21);
+ this.modelsTextBox.TabIndex = 1;
+ //
+ // label9
+ //
+ this.label9.AutoSize = true;
+ this.label9.Location = new System.Drawing.Point(3, 0);
+ this.label9.Name = "label9";
+ this.label9.Size = new System.Drawing.Size(41, 12);
+ this.label9.TabIndex = 9;
+ this.label9.Text = "Models";
+ //
+ // modelsBtn
+ //
+ this.modelsBtn.Location = new System.Drawing.Point(598, 3);
+ this.modelsBtn.Name = "modelsBtn";
+ this.modelsBtn.Size = new System.Drawing.Size(74, 23);
+ this.modelsBtn.TabIndex = 2;
+ this.modelsBtn.Text = "Models";
+ this.modelsBtn.UseVisualStyleBackColor = true;
+ this.modelsBtn.Click += new System.EventHandler(this.modelsBtn_Click);
+ //
+ // pathTextBox
+ //
+ this.pathTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.pathTextBox.Location = new System.Drawing.Point(103, 183);
+ this.pathTextBox.Name = "pathTextBox";
+ this.pathTextBox.Size = new System.Drawing.Size(489, 21);
+ this.pathTextBox.TabIndex = 6;
+ //
+ // openBtn
+ //
+ this.openBtn.Location = new System.Drawing.Point(598, 183);
+ this.openBtn.Name = "openBtn";
+ this.openBtn.Size = new System.Drawing.Size(74, 23);
+ this.openBtn.TabIndex = 0;
+ this.openBtn.Text = "Open";
+ this.openBtn.UseVisualStyleBackColor = true;
+ this.openBtn.Click += new System.EventHandler(this.openBtn_Click);
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(3, 150);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(59, 12);
+ this.label1.TabIndex = 3;
+ this.label1.Text = "numThread";
+ //
+ // numThreadNumeric
+ //
+ this.numThreadNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.numThreadNumeric.Location = new System.Drawing.Point(103, 153);
+ this.numThreadNumeric.Maximum = new decimal(new int[] {
+ 128,
+ 0,
+ 0,
+ 0});
+ this.numThreadNumeric.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.numThreadNumeric.Name = "numThreadNumeric";
+ this.numThreadNumeric.Size = new System.Drawing.Size(489, 21);
+ this.numThreadNumeric.TabIndex = 4;
+ this.numThreadNumeric.Value = new decimal(new int[] {
+ 4,
+ 0,
+ 0,
+ 0});
+ //
+ // label6
+ //
+ this.label6.AutoSize = true;
+ this.label6.Location = new System.Drawing.Point(3, 30);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(23, 12);
+ this.label6.TabIndex = 11;
+ this.label6.Text = "det";
+ //
+ // detNameTextBox
+ //
+ this.detNameTextBox.Location = new System.Drawing.Point(103, 33);
+ this.detNameTextBox.Name = "detNameTextBox";
+ this.detNameTextBox.Size = new System.Drawing.Size(489, 21);
+ this.detNameTextBox.TabIndex = 12;
+ this.detNameTextBox.Text = "ch_ppocr_server_v2.0_det_infer.onnx";
+ //
+ // label10
+ //
+ this.label10.AutoSize = true;
+ this.label10.Location = new System.Drawing.Point(3, 60);
+ this.label10.Name = "label10";
+ this.label10.Size = new System.Drawing.Size(23, 12);
+ this.label10.TabIndex = 13;
+ this.label10.Text = "cls";
+ //
+ // clsNameTextBox
+ //
+ this.clsNameTextBox.Location = new System.Drawing.Point(103, 63);
+ this.clsNameTextBox.Name = "clsNameTextBox";
+ this.clsNameTextBox.Size = new System.Drawing.Size(489, 21);
+ this.clsNameTextBox.TabIndex = 14;
+ this.clsNameTextBox.Text = "ch_ppocr_mobile_v2.0_cls_infer.onnx";
+ //
+ // label11
+ //
+ this.label11.AutoSize = true;
+ this.label11.Location = new System.Drawing.Point(3, 90);
+ this.label11.Name = "label11";
+ this.label11.Size = new System.Drawing.Size(23, 12);
+ this.label11.TabIndex = 15;
+ this.label11.Text = "rec";
+ //
+ // recNameTextBox
+ //
+ this.recNameTextBox.Location = new System.Drawing.Point(103, 93);
+ this.recNameTextBox.Name = "recNameTextBox";
+ this.recNameTextBox.Size = new System.Drawing.Size(489, 21);
+ this.recNameTextBox.TabIndex = 16;
+ this.recNameTextBox.Text = "ch_ppocr_server_v2.0_rec_infer.onnx";
+ //
+ // label12
+ //
+ this.label12.AutoSize = true;
+ this.label12.Location = new System.Drawing.Point(3, 120);
+ this.label12.Name = "label12";
+ this.label12.Size = new System.Drawing.Size(29, 12);
+ this.label12.TabIndex = 17;
+ this.label12.Text = "keys";
+ //
+ // keysNameTextBox
+ //
+ this.keysNameTextBox.Location = new System.Drawing.Point(103, 123);
+ this.keysNameTextBox.Name = "keysNameTextBox";
+ this.keysNameTextBox.Size = new System.Drawing.Size(489, 21);
+ this.keysNameTextBox.TabIndex = 18;
+ this.keysNameTextBox.Text = "ppocr_keys_v1.txt";
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(5, 98);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(59, 12);
+ this.label5.TabIndex = 14;
+ this.label5.Text = "boxThresh";
+ //
+ // boxThreshNumeric
+ //
+ this.boxThreshNumeric.DecimalPlaces = 3;
+ this.boxThreshNumeric.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 65536});
+ this.boxThreshNumeric.Location = new System.Drawing.Point(87, 101);
+ this.boxThreshNumeric.Maximum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.boxThreshNumeric.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.boxThreshNumeric.Name = "boxThreshNumeric";
+ this.boxThreshNumeric.Size = new System.Drawing.Size(74, 21);
+ this.boxThreshNumeric.TabIndex = 15;
+ this.boxThreshNumeric.Value = new decimal(new int[] {
+ 3,
+ 0,
+ 0,
+ 65536});
+ //
+ // label7
+ //
+ this.label7.AutoSize = true;
+ this.label7.Location = new System.Drawing.Point(5, 130);
+ this.label7.Name = "label7";
+ this.label7.Size = new System.Drawing.Size(71, 12);
+ this.label7.TabIndex = 21;
+ this.label7.Text = "unClipRatio";
+ //
+ // unClipRatioNumeric
+ //
+ this.unClipRatioNumeric.DecimalPlaces = 1;
+ this.unClipRatioNumeric.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 65536});
+ this.unClipRatioNumeric.Location = new System.Drawing.Point(87, 133);
+ this.unClipRatioNumeric.Maximum = new decimal(new int[] {
+ 10,
+ 0,
+ 0,
+ 0});
+ this.unClipRatioNumeric.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 65536});
+ this.unClipRatioNumeric.Name = "unClipRatioNumeric";
+ this.unClipRatioNumeric.Size = new System.Drawing.Size(74, 21);
+ this.unClipRatioNumeric.TabIndex = 22;
+ this.unClipRatioNumeric.Value = new decimal(new int[] {
+ 15,
+ 0,
+ 0,
+ 65536});
+ //
+ // doAngleCheckBox
+ //
+ this.doAngleCheckBox.AutoSize = true;
+ this.doAngleCheckBox.Checked = true;
+ this.doAngleCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.doAngleCheckBox.Location = new System.Drawing.Point(5, 165);
+ this.doAngleCheckBox.Name = "doAngleCheckBox";
+ this.doAngleCheckBox.Size = new System.Drawing.Size(66, 16);
+ this.doAngleCheckBox.TabIndex = 26;
+ this.doAngleCheckBox.Text = "doAngle";
+ this.doAngleCheckBox.UseVisualStyleBackColor = true;
+ //
+ // mostAngleCheckBox
+ //
+ this.mostAngleCheckBox.AutoSize = true;
+ this.mostAngleCheckBox.Location = new System.Drawing.Point(87, 165);
+ this.mostAngleCheckBox.Name = "mostAngleCheckBox";
+ this.mostAngleCheckBox.Size = new System.Drawing.Size(78, 16);
+ this.mostAngleCheckBox.TabIndex = 27;
+ this.mostAngleCheckBox.Text = "mostAngle";
+ this.mostAngleCheckBox.UseVisualStyleBackColor = true;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(5, 66);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(71, 24);
+ this.label4.TabIndex = 12;
+ this.label4.Text = "boxScoreThresh";
+ //
+ // imgResizeNumeric
+ //
+ this.imgResizeNumeric.Location = new System.Drawing.Point(87, 37);
+ this.imgResizeNumeric.Maximum = new decimal(new int[] {
+ 99999,
+ 0,
+ 0,
+ 0});
+ this.imgResizeNumeric.Name = "imgResizeNumeric";
+ this.imgResizeNumeric.Size = new System.Drawing.Size(74, 21);
+ this.imgResizeNumeric.TabIndex = 10;
+ this.imgResizeNumeric.Value = new decimal(new int[] {
+ 1024,
+ 0,
+ 0,
+ 0});
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(5, 34);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(65, 12);
+ this.label3.TabIndex = 9;
+ this.label3.Text = "maxSideLen";
+ //
+ // paddingNumeric
+ //
+ this.paddingNumeric.Location = new System.Drawing.Point(87, 5);
+ this.paddingNumeric.Maximum = new decimal(new int[] {
+ 200,
+ 0,
+ 0,
+ 0});
+ this.paddingNumeric.Name = "paddingNumeric";
+ this.paddingNumeric.Size = new System.Drawing.Size(74, 21);
+ this.paddingNumeric.TabIndex = 7;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(5, 2);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(47, 12);
+ this.label2.TabIndex = 6;
+ this.label2.Text = "padding";
+ //
+ // boxScoreThreshNumeric
+ //
+ this.boxScoreThreshNumeric.DecimalPlaces = 3;
+ this.boxScoreThreshNumeric.Increment = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 65536});
+ this.boxScoreThreshNumeric.Location = new System.Drawing.Point(87, 69);
+ this.boxScoreThreshNumeric.Maximum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.boxScoreThreshNumeric.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 131072});
+ this.boxScoreThreshNumeric.Name = "boxScoreThreshNumeric";
+ this.boxScoreThreshNumeric.Size = new System.Drawing.Size(74, 21);
+ this.boxScoreThreshNumeric.TabIndex = 13;
+ this.boxScoreThreshNumeric.Value = new decimal(new int[] {
+ 7,
+ 0,
+ 0,
+ 65536});
+ //
+ // tableLayoutPanel3
+ //
+ this.tableLayoutPanel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.tableLayoutPanel3.ColumnCount = 3;
+ this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 170F));
+ this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel3.Controls.Add(this.pictureBox, 1, 0);
+ this.tableLayoutPanel3.Controls.Add(this.strRestTextBox, 2, 0);
+ this.tableLayoutPanel3.Controls.Add(this.tableLayoutPanel1, 0, 0);
+ this.tableLayoutPanel3.Location = new System.Drawing.Point(14, 229);
+ this.tableLayoutPanel3.Name = "tableLayoutPanel3";
+ this.tableLayoutPanel3.RowCount = 1;
+ this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel3.Size = new System.Drawing.Size(757, 268);
+ this.tableLayoutPanel3.TabIndex = 16;
+ //
+ // pictureBox
+ //
+ this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.pictureBox.Location = new System.Drawing.Point(173, 3);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(287, 260);
+ this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
+ this.pictureBox.TabIndex = 3;
+ this.pictureBox.TabStop = false;
+ //
+ // strRestTextBox
+ //
+ this.strRestTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.strRestTextBox.Location = new System.Drawing.Point(466, 3);
+ this.strRestTextBox.Multiline = true;
+ this.strRestTextBox.Name = "strRestTextBox";
+ this.strRestTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
+ this.strRestTextBox.Size = new System.Drawing.Size(288, 260);
+ this.strRestTextBox.TabIndex = 0;
+ //
+ // tableLayoutPanel1
+ //
+ this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Outset;
+ this.tableLayoutPanel1.ColumnCount = 2;
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 94F));
+ this.tableLayoutPanel1.Controls.Add(this.boxScoreThreshNumeric, 1, 2);
+ this.tableLayoutPanel1.Controls.Add(this.label4, 0, 2);
+ this.tableLayoutPanel1.Controls.Add(this.imgResizeNumeric, 1, 1);
+ this.tableLayoutPanel1.Controls.Add(this.label3, 0, 1);
+ this.tableLayoutPanel1.Controls.Add(this.paddingNumeric, 1, 0);
+ this.tableLayoutPanel1.Controls.Add(this.label2, 0, 0);
+ this.tableLayoutPanel1.Controls.Add(this.label5, 0, 3);
+ this.tableLayoutPanel1.Controls.Add(this.boxThreshNumeric, 1, 3);
+ this.tableLayoutPanel1.Controls.Add(this.label7, 0, 4);
+ this.tableLayoutPanel1.Controls.Add(this.unClipRatioNumeric, 1, 4);
+ this.tableLayoutPanel1.Controls.Add(this.doAngleCheckBox, 0, 5);
+ this.tableLayoutPanel1.Controls.Add(this.mostAngleCheckBox, 1, 5);
+ this.tableLayoutPanel1.Controls.Add(this.partImgCheckBox, 0, 6);
+ this.tableLayoutPanel1.Controls.Add(this.debugCheckBox, 1, 6);
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
+ this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+ this.tableLayoutPanel1.RowCount = 8;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(164, 260);
+ this.tableLayoutPanel1.TabIndex = 2;
+ //
+ // partImgCheckBox
+ //
+ this.partImgCheckBox.AutoSize = true;
+ this.partImgCheckBox.Location = new System.Drawing.Point(5, 197);
+ this.partImgCheckBox.Name = "partImgCheckBox";
+ this.partImgCheckBox.Size = new System.Drawing.Size(66, 16);
+ this.partImgCheckBox.TabIndex = 28;
+ this.partImgCheckBox.Text = "PartImg";
+ this.partImgCheckBox.UseVisualStyleBackColor = true;
+ this.partImgCheckBox.CheckedChanged += new System.EventHandler(this.partImgCheckBox_CheckedChanged);
+ //
+ // debugCheckBox
+ //
+ this.debugCheckBox.AutoSize = true;
+ this.debugCheckBox.Location = new System.Drawing.Point(87, 197);
+ this.debugCheckBox.Name = "debugCheckBox";
+ this.debugCheckBox.Size = new System.Drawing.Size(72, 16);
+ this.debugCheckBox.TabIndex = 29;
+ this.debugCheckBox.Text = "DebugImg";
+ this.debugCheckBox.UseVisualStyleBackColor = true;
+ this.debugCheckBox.CheckedChanged += new System.EventHandler(this.debugCheckBox_CheckedChanged);
+ //
+ // detectBtn
+ //
+ this.detectBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.detectBtn.Location = new System.Drawing.Point(697, 12);
+ this.detectBtn.Name = "detectBtn";
+ this.detectBtn.Size = new System.Drawing.Size(74, 114);
+ this.detectBtn.TabIndex = 12;
+ this.detectBtn.Text = "Detect";
+ this.detectBtn.UseVisualStyleBackColor = true;
+ this.detectBtn.Click += new System.EventHandler(this.detectBtn_Click);
+ //
+ // initBtn
+ //
+ this.initBtn.Location = new System.Drawing.Point(697, 132);
+ this.initBtn.Name = "initBtn";
+ this.initBtn.Size = new System.Drawing.Size(74, 91);
+ this.initBtn.TabIndex = 15;
+ this.initBtn.Text = "重新初始化";
+ this.initBtn.UseVisualStyleBackColor = true;
+ this.initBtn.Click += new System.EventHandler(this.initBtn_Click);
+ //
+ // ocrResultTextBox
+ //
+ this.ocrResultTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.ocrResultTextBox.Font = new System.Drawing.Font("宋体", 9F);
+ this.ocrResultTextBox.Location = new System.Drawing.Point(14, 503);
+ this.ocrResultTextBox.Multiline = true;
+ this.ocrResultTextBox.Name = "ocrResultTextBox";
+ this.ocrResultTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
+ this.ocrResultTextBox.Size = new System.Drawing.Size(757, 246);
+ this.ocrResultTextBox.TabIndex = 13;
+ //
+ // FormOcr
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(784, 761);
+ this.Controls.Add(this.tableLayoutPanel2);
+ this.Controls.Add(this.tableLayoutPanel3);
+ this.Controls.Add(this.detectBtn);
+ this.Controls.Add(this.initBtn);
+ this.Controls.Add(this.ocrResultTextBox);
+ this.Name = "FormOcr";
+ this.Text = "BaiPiaoOcrOnnxCs v1.0.0";
+ this.Load += new System.EventHandler(this.Form1_Load);
+ this.tableLayoutPanel2.ResumeLayout(false);
+ this.tableLayoutPanel2.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numThreadNumeric)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.boxThreshNumeric)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.unClipRatioNumeric)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.imgResizeNumeric)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.paddingNumeric)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.boxScoreThreshNumeric)).EndInit();
+ this.tableLayoutPanel3.ResumeLayout(false);
+ this.tableLayoutPanel3.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.tableLayoutPanel1.ResumeLayout(false);
+ this.tableLayoutPanel1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label label8;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
+ private System.Windows.Forms.TextBox modelsTextBox;
+ private System.Windows.Forms.Label label9;
+ private System.Windows.Forms.Button modelsBtn;
+ private System.Windows.Forms.TextBox pathTextBox;
+ private System.Windows.Forms.Button openBtn;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.NumericUpDown numThreadNumeric;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.TextBox detNameTextBox;
+ private System.Windows.Forms.Label label10;
+ private System.Windows.Forms.TextBox clsNameTextBox;
+ private System.Windows.Forms.Label label11;
+ private System.Windows.Forms.TextBox recNameTextBox;
+ private System.Windows.Forms.Label label12;
+ private System.Windows.Forms.TextBox keysNameTextBox;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.NumericUpDown boxThreshNumeric;
+ private System.Windows.Forms.Label label7;
+ private System.Windows.Forms.NumericUpDown unClipRatioNumeric;
+ private System.Windows.Forms.CheckBox doAngleCheckBox;
+ private System.Windows.Forms.CheckBox mostAngleCheckBox;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.NumericUpDown imgResizeNumeric;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.NumericUpDown paddingNumeric;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.NumericUpDown boxScoreThreshNumeric;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
+ private System.Windows.Forms.PictureBox pictureBox;
+ private System.Windows.Forms.TextBox strRestTextBox;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+ private System.Windows.Forms.CheckBox partImgCheckBox;
+ private System.Windows.Forms.CheckBox debugCheckBox;
+ private System.Windows.Forms.Button detectBtn;
+ private System.Windows.Forms.Button initBtn;
+ private System.Windows.Forms.TextBox ocrResultTextBox;
+ }
+}
+
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.cs
new file mode 100755
index 0000000..67be44f
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.cs
@@ -0,0 +1,168 @@
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using OcrLiteLib;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BaiPiaoOcrOnnxCs
+{
+ public partial class FormOcr : Form
+ {
+ private OcrLite ocrEngin;
+
+ public FormOcr()
+ {
+ InitializeComponent();
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ string appPath = AppDomain.CurrentDomain.BaseDirectory;
+ string appDir = Directory.GetParent(appPath).FullName;
+ string modelsDir = appPath + "models";
+ modelsTextBox.Text = modelsDir;
+ string detPath = modelsDir + "\\" + detNameTextBox.Text;
+ string clsPath = modelsDir + "\\" + clsNameTextBox.Text;
+ string recPath = modelsDir + "\\" + recNameTextBox.Text;
+ string keysPath = modelsDir + "\\" + keysNameTextBox.Text;
+ bool isDetExists = File.Exists(detPath);
+ if (!isDetExists)
+ {
+ MessageBox.Show("模型文件不存在:" + detPath);
+ }
+ bool isClsExists = File.Exists(clsPath);
+ if (!isClsExists)
+ {
+ MessageBox.Show("模型文件不存在:" + clsPath);
+ }
+ bool isRecExists = File.Exists(recPath);
+ if (!isRecExists)
+ {
+ MessageBox.Show("模型文件不存在:" + recPath);
+ }
+ bool isKeysExists = File.Exists(recPath);
+ if (!isKeysExists)
+ {
+ MessageBox.Show("Keys文件不存在:" + keysPath);
+ }
+ if (isDetExists && isClsExists && isRecExists && isKeysExists)
+ {
+ ocrEngin = new OcrLite();
+ ocrEngin.InitModels(detPath, clsPath, recPath, keysPath, (int)numThreadNumeric.Value);
+ }
+ else
+ {
+ MessageBox.Show("初始化失败,请确认模型文件夹和文件后,重新初始化!");
+ }
+ }
+
+ private void initBtn_Click(object sender, EventArgs e)
+ {
+ string modelsDir = modelsTextBox.Text;
+ string detPath = modelsDir + "\\" + detNameTextBox.Text;
+ string clsPath = modelsDir + "\\" + clsNameTextBox.Text;
+ string recPath = modelsDir + "\\" + recNameTextBox.Text;
+ string keysPath = modelsDir + "\\" + keysNameTextBox.Text;
+ bool isDetExists = File.Exists(detPath);
+ if (!isDetExists)
+ {
+ MessageBox.Show("模型文件不存在:" + detPath);
+ }
+ bool isClsExists = File.Exists(clsPath);
+ if (!isClsExists)
+ {
+ MessageBox.Show("模型文件不存在:" + clsPath);
+ }
+ bool isRecExists = File.Exists(recPath);
+ if (!isRecExists)
+ {
+ MessageBox.Show("模型文件不存在:" + recPath);
+ }
+ bool isKeysExists = File.Exists(recPath);
+ if (!isKeysExists)
+ {
+ MessageBox.Show("Keys文件不存在:" + keysPath);
+ }
+ if (isDetExists && isClsExists && isRecExists && isKeysExists)
+ {
+ ocrEngin = new OcrLite();
+ ocrEngin.InitModels(detPath, clsPath, recPath, keysPath, (int)numThreadNumeric.Value);
+ }
+ else
+ {
+ MessageBox.Show("初始化失败,请确认模型文件夹和文件后,重新初始化!");
+ }
+ }
+
+ private void openBtn_Click(object sender, EventArgs e)
+ {
+ using (var dlg = new OpenFileDialog())
+ {
+ dlg.Multiselect = false;
+ dlg.Filter = "(*.JPG,*.PNG,*.JPEG,*.BMP,*.GIF)|*.JPG;*.PNG;*.JPEG;*.BMP;*.GIF|All files(*.*)|*.*";
+ if (dlg.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(dlg.FileName))
+ {
+ pathTextBox.Text = dlg.FileName;
+ Mat src = CvInvoke.Imread(dlg.FileName, ImreadModes.Color);
+ pictureBox.Image = src.ToBitmap();
+ }
+ }
+ }
+
+ private void modelsBtn_Click(object sender, EventArgs e)
+ {
+ using (var dlg = new FolderBrowserDialog())
+ {
+ dlg.SelectedPath = Environment.CurrentDirectory + "\\models";
+ if (dlg.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(dlg.SelectedPath))
+ {
+ modelsTextBox.Text = dlg.SelectedPath;
+ }
+ }
+ }
+
+ private void detectBtn_Click(object sender, EventArgs e)
+ {
+ if (ocrEngin == null)
+ {
+ MessageBox.Show("未初始化,无法执行!");
+ return;
+ }
+ string targetImg = pathTextBox.Text;
+ if (!File.Exists(targetImg))
+ {
+ MessageBox.Show("目标图片不存在,请用Open按钮打开");
+ return;
+ }
+ int padding = (int)paddingNumeric.Value;
+ int imgResize = (int)imgResizeNumeric.Value;
+ float boxScoreThresh = (float)boxScoreThreshNumeric.Value;
+ float boxThresh = (float)boxThreshNumeric.Value;
+ float unClipRatio = (float)unClipRatioNumeric.Value;
+ bool doAngle = doAngleCheckBox.Checked;
+ bool mostAngle = mostAngleCheckBox.Checked;
+ OcrResult ocrResult = ocrEngin.Detect(pathTextBox.Text, padding, imgResize, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);
+ ocrResultTextBox.Text = ocrResult.ToString();
+ strRestTextBox.Text = ocrResult.StrRes;
+ pictureBox.Image = ocrResult.BoxImg.ToBitmap();
+ }
+
+ private void partImgCheckBox_CheckedChanged(object sender, EventArgs e)
+ {
+ ocrEngin.isPartImg = partImgCheckBox.Checked;
+ }
+
+ private void debugCheckBox_CheckedChanged(object sender, EventArgs e)
+ {
+ ocrEngin.isDebugImg = debugCheckBox.Checked;
+ }
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.resx b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.resx
new file mode 100755
index 0000000..1af7de1
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/FormOcr.resx
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/OcrOnnxForm.csproj b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/OcrOnnxForm.csproj
new file mode 100755
index 0000000..ac1436f
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/OcrOnnxForm.csproj
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{43A96152-8891-4505-8389-32276F3A9422}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <RootNamespace>BaiPiaoOcrOnnxCs</RootNamespace>
+ <AssemblyName>BaiPiaoOcrOnnxCs</AssemblyName>
+ <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>x64</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Emgu.CV.Bitmap, Version=4.4.0.4099, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
+ <HintPath>..\packages\Emgu.CV.Bitmap.4.4.0.4099\lib\netstandard2.0\Emgu.CV.Bitmap.dll</HintPath>
+ </Reference>
+ <Reference Include="Emgu.CV.Platform.NetStandard, Version=4.4.0.4099, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
+ <HintPath>..\packages\Emgu.CV.4.4.0.4099\lib\netstandard2.0\Emgu.CV.Platform.NetStandard.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Drawing.Common, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Drawing.Common.4.7.0\lib\net461\System.Drawing.Common.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Drawing.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Drawing.Primitives.4.3.0\lib\net45\System.Drawing.Primitives.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Deployment" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="FormOcr.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="FormOcr.Designer.cs">
+ <DependentUpon>FormOcr.cs</DependentUpon>
+ </Compile>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <EmbeddedResource Include="FormOcr.resx">
+ <DependentUpon>FormOcr.cs</DependentUpon>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <None Include="packages.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\OcrLib\OcrLib.csproj">
+ <Project>{ab10d356-2d95-4460-96ca-9a7129ad0a76}</Project>
+ <Name>OcrLib</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Program.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Program.cs
new file mode 100755
index 0000000..ce7a252
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Program.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BaiPiaoOcrOnnxCs
+{
+ static class Program
+ {
+ /// <summary>
+ /// 应用程序的主入口点。
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new FormOcr());
+ }
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/AssemblyInfo.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/AssemblyInfo.cs
new file mode 100755
index 0000000..52d5ff4
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("BaiPiaoOcrOnnxCs")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("BaiPiaoOcrOnnxCs")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("43a96152-8891-4505-8389-32276f3a9422")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.Designer.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.Designer.cs
new file mode 100755
index 0000000..1c21f86
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.Designer.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// 此代码由工具生成。
+// 运行时版本: 4.0.30319.42000
+//
+// 对此文件的更改可能导致不正确的行为,如果
+// 重新生成代码,则所做更改将丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace BaiPiaoOcrOnnxCs.Properties
+{
+
+
+ /// <summary>
+ /// 强类型资源类,用于查找本地化字符串等。
+ /// </summary>
+ // 此类是由 StronglyTypedResourceBuilder
+ // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+ // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+ // (以 /str 作为命令选项),或重新生成 VS 项目。
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources
+ {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources()
+ {
+ }
+
+ /// <summary>
+ /// 返回此类使用的缓存 ResourceManager 实例。
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager
+ {
+ get
+ {
+ if ((resourceMan == null))
+ {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BaiPiaoOcrOnnxCs.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// 覆盖当前线程的 CurrentUICulture 属性
+ /// 使用此强类型的资源类的资源查找。
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture
+ {
+ get
+ {
+ return resourceCulture;
+ }
+ set
+ {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.resx b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.resx
new file mode 100755
index 0000000..af7dbeb
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.Designer.cs b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.Designer.cs
new file mode 100755
index 0000000..92d9030
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace BaiPiaoOcrOnnxCs.Properties
+{
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+ {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default
+ {
+ get
+ {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.settings b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.settings
new file mode 100755
index 0000000..3964565
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile>
diff --git a/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/packages.config b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/packages.config
new file mode 100755
index 0000000..3bc4f5a
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/OcrOnnxForm/packages.config
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Emgu.CV" version="4.4.0.4099" targetFramework="net461" />
+ <package id="Emgu.CV.Bitmap" version="4.4.0.4099" targetFramework="net461" />
+ <package id="System.Drawing.Common" version="4.7.0" targetFramework="net461" />
+ <package id="System.Drawing.Primitives" version="4.3.0" targetFramework="net461" />
+ <package id="System.Runtime" version="4.3.1" targetFramework="net461" />
+ <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
+</packages>
\ No newline at end of file
diff --git a/dotnet/BaiPiaoOcrOnnxCs/README.md b/dotnet/BaiPiaoOcrOnnxCs/README.md
new file mode 100644
index 0000000..fe96a64
--- /dev/null
+++ b/dotnet/BaiPiaoOcrOnnxCs/README.md
@@ -0,0 +1,36 @@
+# BaiPiaoOcrOnnxCs
+
+### 介绍
+* 本项目为Windows平台C# WinForm范例。
+* 依赖的包:Emgu.CV、MicroSoft.ML.OnnxRuntime、clipper_library
+
+### Demo下载(win、mac、linux)
+编译好的demo文件比较大,可以到Q群共享内下载
+
+### 编译环境
+1. Windows 10 x64
+2. Visual Studio 2017或以上
+
+### 编译说明
+1. Vs2017打开BaiPiaoOcrOnnxCs.sln。
+2. 解决方案资源管理器->OcrLib->右键->管理NuGet程序包->浏览->搜索->安装
+* 注意:Emgu.CV要选作者是“Emgu Corporation”
+* Emgu.CV 4.4.0.4099
+* Emgu.CV.runtime.windows 4.4.0.4099
+* MicroSoft.ML.OnnxRuntime 1.6.0
+* clipper_library 6.2.1
+3. 解决方案资源管理器->OcrLiteOnnxForm->右键->管理NuGet程序包->浏览->搜索->安装
+* 注意:Emgu.CV要选作者是“Emgu Corporation”
+* Emgu.CV 4.4.0.4099
+* Emgu.CV.Bitmap 4.4.0.4099
+4. 确保:OcrLiteOnnxForm设为启动项目
+5. 确保:OcrLiteOnnxForm->右键->属性->生成->平台目标:x64
+6. 确保:OcrLiteLib->右键->属性->生成->平台目标:x64
+7. 生成解决方案
+8. 把models文件夹复制到```\BaiPiaoOcrOnnxCs\OcrOnnxForm\bin\Debug(或Release)```
+* [模型下载地址](https://github.com/znsoftm/BaiPiaoOCR/tree/main/models)
+9. 运行
+
+### 其它
+* 修改模型路径,模型名称,线程数,必须“重新初始化”才能生效
+* 输入参数说明请参考[BaiPiaoOcrOnnx项目](https://github.com/znsoftm/BaiPiaoOCR/tree/main/cpp/BaiPiaoOcrOnnx)
\ No newline at end of file
diff --git a/dotnet/README.md b/dotnet/README.md
new file mode 100644
index 0000000..82c26ee
--- /dev/null
+++ b/dotnet/README.md
@@ -0,0 +1,5 @@
+# .Net版BaiPiaoOcr范例
+
+#### 介绍
+本目录存放.Net相关demo项目
+* BaiPiaoOcrOnnxCs项目是Windows平台C# WinForm范例,采用onnxruntime为推理框架