当前位置: 首页 > news >正文

西安阎良区建设局网站东莞建工集团

西安阎良区建设局网站,东莞建工集团,淄博市沂源县城乡建设局网站,我想网站建设多少钱一、前言 通过查看网络资料以及书籍资料,发现大多数OCR识别功能都是基于Python语言开发的,对于习惯使用C# 开发语言的程序猿们,岂不是一件很苦恼的事!当然想学习Python,掌握多一项技能也并不是坏事!为了方…

一、前言

通过查看网络资料以及书籍资料,发现大多数OCR识别功能都是基于Python语言开发的,对于习惯使用C# 开发语言的程序猿们,岂不是一件很苦恼的事!当然想学习Python,掌握多一项技能也并不是坏事!为了方便使用,想使用C# 的往下看(或需要使用当作工作辅助也行,资源下载在最后有链接)。

二、开发要求

1、图形处理库Clipper、Emgu.CV
2、高性能推理引擎 Microsoft.ML.OnnxRuntime
3、借用PaddleOCR模型
4、现有功能,选择照片识别、截图识别,选择PDF文件识别

三、部分代码

using Emgu.CV;
using OcrDemo.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace OcrDemo
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private string fileFilter = "所有文件 (*.*)|*.*|bmp|*.bmp|jpg|*.jpg|jpeg|*.jpeg|png|*.png";private Bitmap bmp;  private string outPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "output");private Stopwatch stopwatch = new Stopwatch();private string filePath = "";private int threadNum = 4;private OcrLite ocrEngin;private void Form1_Load(object sender, EventArgs e){try{if (!Directory.Exists(outPath)){Directory.CreateDirectory(outPath);}splitContainer1.SplitterDistance = (int)(splitContainer1.Width * 0.5);splitContainer2.SplitterDistance = (int)(splitContainer2.Width * 0.5);string appPath = AppDomain.CurrentDomain.BaseDirectory;string appDir = Directory.GetParent(appPath).FullName;}catch (Exception ex){SetMessge(ex.Message);}}private void SetMessge(string info, int infoType = 0){//info = DataHelper.DateFormat(DateTime.Now) + "" + info + "\n";info =  info + "\n";if (this.InvokeRequired){// 如果需要跨线程调用,则使用 Invoke 方法this.Invoke(new Action(() =>{rTB_Message.AppendText(info);// 滚动文本框以使光标所在位置可见//rTB_ResultInfo.ScrollToCaret();// 选中插入点rTB_Message.Focus();}));}else{// 如果在 UI 线程中,则直接更新控件rTB_Message.AppendText(info);// 滚动文本框以使光标所在位置可见//rTB_ResultInfo.ScrollToCaret();// 选中插入点rTB_Message.Focus();}}private void tool_bt_select_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() == DialogResult.OK){Application.DoEvents();filePath = ofd.FileName;var imagebyte = File.ReadAllBytes(filePath);bmp = new Bitmap(new MemoryStream(imagebyte));pictureBox1.Image = bmp;rTB_Message.Clear();if (bmp == null) return;stopwatch.Restart();OcrResult ocrResult = ocrEngin.Detect(filePath, padding, imgResize, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);stopwatch.Stop();SetMessge(ocrResult.StrRes);SetMessge("------------------------------");//SetMessge(ocrResult.ToString());SetMessge($"--------------耗时: {stopwatch.ElapsedMilliseconds} 毫秒----------------");pictureBox2.Image = ocrResult.BoxImg.ToBitmap();}}private void tool_bt_screenshot_Click(object sender, EventArgs e){this.Hide();System.Threading.Thread.Sleep(200);Application.DoEvents();ScreenCapturer.ScreenCapturerTool screenCapturer = new ScreenCapturer.ScreenCapturerTool();if (screenCapturer.ShowDialog() == DialogResult.OK){bmp = (Bitmap)screenCapturer.Image;string newFiles = outPath+"\\" + DataHelper.GetTimestamp() + ".jpg";bmp.Save(newFiles, ImageFormat.Jpeg);pictureBox1.Image = bmp;try{stopwatch.Restart();OcrResult ocrResult = ocrEngin.Detect(newFiles, padding, imgResize, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);stopwatch.Stop();SetMessge(ocrResult.StrRes);SetMessge($"--------------耗时: {stopwatch.ElapsedMilliseconds} 毫秒----------------");//SetMessge(ocrResult.ToString());pictureBox2.Image = ocrResult.BoxImg.ToBitmap();}catch (Exception ex){SetMessge(ex.Message);}}this.Show();}private void tool_bt_PDF_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "所有文件 (*.*)|*.*|PDF|*.pdf";if (ofd.ShowDialog() == DialogResult.OK){string pdfPath = ofd.FileName;// 1. 解析PDF获取页面图像using (var document = PdfDocument.Load(pdfPath)){string firstFiles = "";stopwatch.Restart();for (int pageIndex = 0; pageIndex < document.PageCount; pageIndex++){// 渲染PDF页面为图像using (var image = document.Render(pageIndex, 400, 800, false)){string newFiles = outPath + "\\" + DataHelper.GetTimestamp() + ".jpg";if (pageIndex == 0){firstFiles = newFiles;}image.Save(newFiles, ImageFormat.Jpeg);OcrResult ocrResult = ocrEngin.Detect(newFiles, padding, imgResize, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);stopwatch.Stop();SetMessge(ocrResult.StrRes);}}if (firstFiles.Length > 0){var imagebyte = File.ReadAllBytes(firstFiles);pictureBox1.Image = new Bitmap(new MemoryStream(imagebyte));}//SetMessge(ocrResult.ToString());SetMessge($"--------------耗时: {stopwatch.ElapsedMilliseconds} 毫秒----------------");}}}}
}

四、效果展示

C#之OCR识别

(图一为屏幕截图识别,图二为动车票信息识别)

五、资源下载

链接:https://download.csdn.net/download/weixin_42148410/90827048

http://www.dtcms.com/a/590185.html

相关文章:

  • 南昌网站建设赣icp南昌搜索引擎优化的作用是什么
  • 济南传承网站建设公司iis关闭网站
  • 【STL——常用算数生成与集成算法】
  • 滨江建设交易门户网站VR网站建设价格
  • 网站开发项目实训装饰工程造价
  • 长沙麓谷建设发展有限公司网站phpcms 手机网站模板
  • 微网站如何做宣传搜索引擎搜索器
  • 科技网站设计模板页
  • 甘肃省城乡和建设厅网站外贸开发软件有哪些
  • 机器学习周报二十一
  • 第三次作业 网站搭建
  • Gorm的使用记录
  • 手工木雕网站建设策划书计算机专业主要学什么内容
  • 蒙古文政务网站群建设工作方案c 做网站性能怎么样
  • 海口专业网站建设最简单的wordpress主题
  • 厦门企业做网站怎样加入网站
  • 门户网站网站开发北京公司注册费用
  • 网站数据库制作seo高级优化技巧
  • 俄语网站建设注意事项thinkphp和wordpress区别
  • STM32F103学习笔记-16-RCC(第4节)-STM32 标准外设库函数命名规则总览(以stm32f10x_rcc.c/h为例)
  • 第7章 nestjs服务端开发:通用业务框架设计
  • 低价网站建设联系方式企业网站后端模板
  • 嵌入式Linux——“大扳手”与“小螺丝”:为什么不该用信号量(Semaphore)去模拟“完成量”(Completion)
  • 哪个网站教做ppt网站优化主要工作有那些内容
  • 都江堰做网站糖果网站建设目的
  • 网站怎么建设以及维护网站维护能自己做吗
  • 湖南网站建设制作陈锦良厦门建设局
  • 做网站有哪些好处现在建设网站落后了
  • 汉中专业网站建设价格梨树县交通建设网站
  • 代码随想录 Q85.摆动序列