赞
踩
目录
using Emgu.CV;
using Emgu.CV.CvEnum;
using OcrLiteLib;
using System;
using System.IO;
using System.Windows.Forms;
namespace OcrLiteOnnxCs
{
public partial class FormOcrLite : Form
{
private OcrLite ocrEngin;
public FormOcrLite()
{
InitializeComponent();
}
private void FormOcrLite_Load(object sender, EventArgs e)
{
string appPath = AppDomain.CurrentDomain.BaseDirectory;
string appDir = Directory.GetParent(appPath).FullName;
string modelsDir = appPath + "models";
modelsTextBox.Text = modelsDir;
ocrEngin = new OcrLite(modelsDir,(int) numThreadNumeric.Value);
}
private void initBtn_Click(object sender, EventArgs e)
{
ocrEngin = new OcrLite(modelsTextBox.Text, (int) numThreadNumeric.Value);
}
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)
{
int padding = (int)paddingNumeric.Value;
int imgResize = (int)imgResizeNumeric.Value;
float boxScoreThresh = (float)boxScoreThreshNumeric.Value;
float boxThresh = (float)boxThreshNumeric.Value;
float minArea = (float)minAreaNumeric.Value;
float unClipRatio = (float)unClipRatioNumeric.Value;
bool doAngle = doAngleCheckBox.Checked;
bool mostAngle = mostAngleCheckBox.Checked;
OcrResult ocrResult = ocrEngin.Detect(pathTextBox.Text, padding, imgResize, boxScoreThresh, boxThresh, minArea, 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;
}
}
}
- using Emgu.CV;
- using Emgu.CV.CvEnum;
- using OcrLiteLib;
- using System;
- using System.IO;
- using System.Windows.Forms;
-
- namespace OcrLiteOnnxCs
- {
- public partial class FormOcrLite : Form
- {
- private OcrLite ocrEngin;
-
- public FormOcrLite()
- {
- InitializeComponent();
- }
-
- private void FormOcrLite_Load(object sender, EventArgs e)
- {
- string appPath = AppDomain.CurrentDomain.BaseDirectory;
- string appDir = Directory.GetParent(appPath).FullName;
- string modelsDir = appPath + "models";
- modelsTextBox.Text = modelsDir;
- ocrEngin = new OcrLite(modelsDir,(int) numThreadNumeric.Value);
- }
-
- private void initBtn_Click(object sender, EventArgs e)
- {
- ocrEngin = new OcrLite(modelsTextBox.Text, (int) numThreadNumeric.Value);
- }
-
- 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)
- {
- int padding = (int)paddingNumeric.Value;
- int imgResize = (int)imgResizeNumeric.Value;
- float boxScoreThresh = (float)boxScoreThreshNumeric.Value;
- float boxThresh = (float)boxThreshNumeric.Value;
- float minArea = (float)minAreaNumeric.Value;
- float unClipRatio = (float)unClipRatioNumeric.Value;
- bool doAngle = doAngleCheckBox.Checked;
- bool mostAngle = mostAngleCheckBox.Checked;
- OcrResult ocrResult = ocrEngin.Detect(pathTextBox.Text, padding, imgResize, boxScoreThresh, boxThresh, minArea, 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;
- }
- }
- }
1. Vs2017打开OcrLiteOnnxCs.sln。
2. 解决方案资源管理器->OcrLiteLib->右键->管理NuGet程序包->浏览->搜索->安装
* 注意:Emgu.CV要选作者是“Emgu Corporation”
* Emgu.CV 4.4.0.4099
* Emgu.CV.runtime.windows 4.4.0.4099
* MicroSoft.ML.OnnxRuntime 1.5.2
* 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. 生成解决方案
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。