首页 > 编程语言 >C# 使用 PaddleOCRSharp 识别 图片中的文字、 使用QRCoder生成二维码

C# 使用 PaddleOCRSharp 识别 图片中的文字、 使用QRCoder生成二维码

时间:2023-08-25 09:57:24浏览次数:51  
标签:oCRParameter C# 二维码 QRCoder PaddleOCRSharp 使用 new 识别

使用PaddleOCRSharp识别图片中的文字

  在只用PaddleOCRSharp之前用过另外一种识别:Tesseract。它识别速度是非常快的,但是准确率堪忧,而且使用的时候需要区分语言,这里权当一些经验交流,不是说Tesseract不好。

PaddleOCRSharp资料汇总:

开源工具开发者博客:https://www.cnblogs.com/raoyutian/p/15938913.html
GitHub:https://github.com/raoyutian/PaddleOCRSharp
Gitee:https://gitee.com/raoyutian/paddle-ocrsharp


  如何使用PaddleOCRSharp在GitHub源码中有一个PaddleOCRDemo项目是有完整的代码实现,里面功能比较齐全

VS版本:VS2022,使用其他版本无法加载源码
而且作者也写了一篇博客 https://www.cnblogs.com/raoyutian/p/15912470.html。

1.将源码编译成对应的.Net 版本引入到项目中

  在作者给出的示例中是直接使用的Nuget包进行的管理,我在尝试的时候没有使用成功,所以采用了引用Dll的方式。

2. 初始化PaddleOCREngine

 ```  
        private PaddleOCREngine engine;
        //自带轻量版中英文模型V4模型
        OCRModelConfig config = null;
        //OCR参数
        OCRParameter oCRParameter = new OCRParameter();
        oCRParameter.cpu_math_library_num_threads = 10;//预测并发线程数
        oCRParameter.enable_mkldnn = true;//web部署该值建议设置为0,否则出错,内存如果使用很大,建议该值也设置为0.
        oCRParameter.cls = false; //是否执行文字方向分类;默认false
        oCRParameter.det = true;//是否开启方向检测,用于检测识别180旋转
        oCRParameter.use_angle_cls = false;//是否开启方向检测,用于检测识别180旋转
        oCRParameter.det_db_score_mode = true;//是否使用多段线,即文字区域是用多段线还是用矩形,
        oCRParameter.max_side_len = 1500;
        oCRParameter.rec_img_h = 48;
        oCRParameter.rec_img_w = 320;
        oCRParameter.det_db_thresh = 0.3f;
        oCRParameter.det_db_box_thresh = 0.618f;

        //初始化OCR引擎
        engine = new PaddleOCREngine(config, oCRParameter);

        //模型配置,使用默认值
        StructureModelConfig structureModelConfig = null;
        //表格识别参数配置,使用默认值
        StructureParameter structureParameter = new StructureParameter();
        structengine = new PaddleStructureEngine(structureModelConfig, structureParameter);

3. 调用DetectText识别文字

OCRResult ocrResult = engine.DetectText(imagebyte);

4. 使用QRCoder生成二维码

        public static Bitmap GetQRCodeImage(string qrCode)
        {    //获取含水印的二维码图像对象
            QRCodeGenerator generator = new QRCodeGenerator();
            QRCodeData data = generator.CreateQrCode(qrCode, QRCodeGenerator.ECCLevel.M);    //qrCode是二维码内容,ECCLevel用于设置容错率
            QRCode code = new QRCode(data);
            //Bitmap icon = new Bitmap("水印文件路径");
            //定义二维码中央水印图标,文件路径一定要是绝对路径,如果是Web工程,可用Server.MapPath函数获取绝对路径
            //icon:由于这里没水印图片,所以用null
            Bitmap qrImage = code.GetGraphic(10, Color.Black, Color.White,null, 15, 6, true);
            //获得含水印的二维码图像信息,如不需要水印可以调用另外函数:Bitmap qrImage = code.GetGraphic(10);
            return qrImage;
        }

标签:oCRParameter,C#,二维码,QRCoder,PaddleOCRSharp,使用,new,识别
From: https://www.cnblogs.com/wofeiliangren/p/17656020.html

相关文章

  • CMake保姆级教程
    来源哔哩哔哩2.编写一个简单的CMakeLists.txt文件_哔哩哔哩_bilibiliCMake保姆级教程(上)|爱编程的大丙(subingwen.cn)......
  • windows wget与curl
     wget下载https://eternallybored.org/misc/wget/curl下载https://curl.se/download.html  ffmpet下载http://ffmpeg.org/......
  • C# 实现 国密SM4/ECB/PKCS7Padding对称加密解密
    C# 实现国密SM4/ECB/PKCS7Padding对称加密解密,为了演示方便本问使用的是VisualStudio2022来构建代码的1、新建项目,之后选择项目鼠标右键选择 管理NuGet程序包管理,输入 BouncyCastle回车添加BouncyCastle程序包 2、代码如下:CBC模式byt......
  • VisionPro C#混合编程环境搭建(基于VS2019)
    VisionPro工具分组(因为Vs2019导入VisionPro是全导入,为了方便,可以自建项进行分类)各选择项1VisionProToolEditControls2VisionProDisplayControls3VisionProShapeEditControls4VisionProSystemControls各选择项下的组件VisionProDisplayControls:CogRecor......
  • select查询优化命令::::
    MySQL优化原理可不像大家想的那样简单啊!点击关注......
  • VScode settings.json默认配置文件路径
    LinuxUbuntu:/home/${用户名}/.config/Code/User/settings.jsonWindows:C:\Users\用户名\AppData\Roaming\Code\User来源、参考:https://blog.csdn.net/cyqzy/article/details/130011314......
  • VisionPro C#混合编程实现工业相机实时图像采集
    1usingSystem;2usingSystem.Collections.Generic;3usingSystem.ComponentModel;4usingSystem.Data;5usingSystem.Drawing;6usingSystem.Linq;7usingSystem.Text;8usingSystem.Windows.Forms;9usingCognex.VisionPro;10usingC......
  • [LeetCode][198]house-robber
    ContentYouareaprofessionalrobberplanningtorobhousesalongastreet.Eachhousehasacertainamountofmoneystashed,theonlyconstraintstoppingyoufromrobbingeachofthemisthatadjacenthouseshavesecuritysystemsconnectedanditwilla......
  • SAP GUI Scripting VBA Code Snippet to Detect all IDs of the UI Elements
    '-Begin-----------------------------------------------------------------OptionExplicitDimgColl()AsStringDimjAsIntegerSubGetAll(ObjAsObject)'---------------------------------------------'-'-Recursivelycalledsubro......
  • tomcat9中设置jks证书和pfx证书
    jks证书设置server.xml<Connectorport="443"protocol="org.apache.coyote.http11.Http11NioProtocol"maxThreads="1000"connectionTimeout="30000"maxPostSize="-1"enabl......