惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
J
Java Code Geeks
A
About on SuperTechFans
F
Fortinet All Blogs
B
Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
博客园_首页
博客园 - 叶小钗
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
云风的 BLOG
云风的 BLOG

博客园 - wgscd

Git 无法访问 GitHub(unable to access ‘https://github.com/.../.git‘)问题解决教程 C#+Audio绘制麦克风波形 一共免费大模型API AI聊天对话界面的HTML代码。 纯JavaScript代码实现保存Canvas图片到电脑 WPF鼠标拖动改变图片透明度 Fiddler自定义规则保存图片和提示The system proxy was changed自动重连 缩放 div 浏览器语音识别-webkitSpeechRecognition HTML获取摄像头画面,拍照截图保存 JS摄像头手势识别-Handsfree.js HTML,JS 模拟聊天界面UI JS获取元素相对窗口的位置和大小 C# 判断是否安装了ffmpeg shadow-root中的元素定位方法 JS MutationObserver监听DOM元素改变 Webview2动态设置页面video的Blob进行播放 C# 文件分割和文件合并 WPF刮刮乐 JS利用浏览器进行语言识别 WPF设置默认语言地区CultureInfo VS2022推送代码 到github错误: CertGetCertificateChain trust error CERT_TRUST_IS_PARTIAL_CHAIN的解决办法 C#正则表达式匹配候选词 使用ffmpeg去除音频静音
RapidOcrNet文字识别OCR
wgscd · 2026-08-05 · via 博客园 - wgscd

nuget: RapidOcrNet NuGet Gallery | RapidOcrNet 3.0.0

测试v6(6秒) 版本的没有v5版本(1秒)的快。

另外:中文的ppocrv5_dict 或者ppocrv6_dict 需要费劲找到。这里找到:ppocrv6_dict.txt        全部:   PaddleOCR/ppocr/utils/dict

模型: RapidOCR · 模型库

using RapidOcrNet;
using System;
using System.IO;
using System.Linq;
using SkiaSharp;
using System.Diagnostics;

namespace OcrTest
{
    public class OCRService
    {
        private static readonly RapidOcr _rapidOcr = new RapidOcr();


        public string RecognizeText(string imagePath)
        {
            if (!File.Exists(imagePath))
            { 
                return "[错误] 图片不存在"; 
            }

            using var ocr = new RapidOcr();
            using var sessionOptions = RapidOcr.GetDefaultSessionOptions();   // sensible defaults: ORT_ENABLE_EXTENDED
            try 
            { 
                sessionOptions.AppendExecutionProvider_CUDA();
            }
            // NVIDIA GPU
            catch 
            {
                sessionOptions.AppendExecutionProvider_CPU();
               
            }
        
            //ocr.InitModels(RapidOcrModelSet.PPOCRv6Small);   // PP-OCRv6, balanced size/accuracy
            //ocr.InitModels(RapidOcrModelSet.PPOCRv6Medium,sessionOptions); 
            //ocr.InitModels(); // loads bundled PP-OCRv5 latin models
            ocr.InitModels(
    detPath: "models/v5/ch_PP-OCRv5_mobile_det.onnx",
    clsPath: "models/v5/ch_PP-LCNet_x0_25_textline_ori_cls_mobile.onnx",
    recPath: "models/v5/ch_PP-OCRv5_rec_mobile.onnx",
    keysPath: "models/v5/ppocrv5_ch_dict.txt");

            //OcrResult result = ocr.Detect(imagePath, RapidOcrOptions.PPOCRv6); 
            OcrResult result = ocr.Detect(imagePath, RapidOcrOptions.Default);
            Debug.Print(result.StrRes);       // full recognized text, one line per block
            foreach (var block in result.TextBlocks)
            {
                Debug.Print($"{block.Text}  (avg score: {block.CharScores!.Average():F2})");
              //  return block.Text;
            }
            if (result == null || result.TextBlocks == null || !result.TextBlocks.Any())
            {
                return "[未识别到文字]";
            }

            return string.Join(Environment.NewLine, result.TextBlocks.Select(b => b.Text));
           
        }



  



    }
}