# ocr文字纠错 **Repository Path**: cuixueyi/Ocr ## Basic Information - **Project Name**: ocr文字纠错 - **Description**: OCR 应用中,由于图像质量、目标角度、文字大小等众多因素,文字不全、文字错误等问题直接影响文字的识别质量;特别在视频的识别过程中,更需要文字纠错速度控制在视频帧率之内。故本程序意在数毫秒之内实现对文字的纠错。 - **Primary Language**: C# - **License**: Unlicense - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2024-10-17 - **Last Updated**: 2025-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 短/术语拼写校正 适用于图像OCR识别后,对不完整中文、英文或拼音文本的拼写矫正和语义对照矫正。 默认情况下,将使用内置的词库进行拼写矫正和翻译。 可根据不同应用方向修改自定义词库,以实现对特定领域或语言的拼写矫正和翻译。 限定: 1. 英文/拼音短语编辑距离(缺字、多字、错字总数)最多允许66%,正确字大于: 0.33% 2. 中文短语编辑距离(缺字、多字、错字总数)不得大于4个,错误率小于: 0.33% 测试效果: 单语种纠错平均耗时 < 1ms, 中/英/拼音三种综合纠错平均耗时 < 2ms 汉字转拼音: 2000字/1ms ## 使用方法 ### 1 字典词库 .\Liberaries\english_chinese_dictionary.txt 中英文对照词库(训练程序自动添加) .\Liberaries\frequency_dictionary_cn.txt 中文频率词库(训练程序自动添加/调整) .\Liberaries\frequency_dictionary_en.txt 英文频率词库(训练程序自动添加/调整) .\Liberaries\Specialized_Dictionary.txt 完全自主的专用词库(LiberaryModel.Specific) 新增术语:如新增术语,可之际添加到 Specialized_Dictionary.txt: 格式: human_computer_interaction 人机交互 其它字典亦相同,英文与中文之间使用空格分割。 ### 2 引用命名空间: using PhraseCorrector; ### 3 创建一个PhraseCorrector对象: IPhraseCorrector phraseCorrector = new PhraseCorrector(字典模式); 字典模式: 使用全部词库: LiberaryModel.All(基本字典 + 专用字典) 只使用多词短语: LiberaryModel.Phrase,(基本字典中的多词词汇 + 专用字典) 只使用专有词库: LiberaryModel.Specific,(只用专用字典 Specialized_Dictionary) ### 4 拼音类 #### 4.1 获取给定中文文本的拼音。 要获取拼音的中文文本。 单词的拼音。 phraseCorrector.GetPinyin(string word); #### 例子: phraseCorrector.GetPinyin("人工智能是智能学科重要的组成部分,它企图了解智能的实质,并生产出一种新的能以与人类智能相似的方式做出反应的智能机器。人工智能是十分广泛的科学,包括机器人、语言识别、图像识别、自然语言处理、专家系统、机器学习,计算机视觉等。"); 【执行结果】ren gong zhi neng shi zhi neng xue ke zhong yao de zu cheng bu fen , ta qi tu le jie zhi neng de shi zhi , bing sheng chan chu yi zhong xin de neng yi yu ren lei zhi neng xiang si de fang shi zuo chu fan ying de zhi neng ji qi 。 ren gong zhi neng shi shi fen guang fan de ke xue , bao kuo ji qi ren 、 yu yan shi bie 、 tu xiang shi bie 、 zi ran yu yan chu li 、 zhuan jia xi tong 、 ji qi xue xi , ji suan ji shi jue deng 。 #### 4.2 根据拼音获取对应的中文文本。 要转换的拼音。 返回对应的中文文本。 public ECResult GetPyText(string pinyin); #### 例子: phraseCorrector.GetPyText("zhongguojiefangjun").ToString(); 【执行结果】{ 中文汉字: 中国人民解放军, 西文拼音: zhong guo ren min jie fang jun, 错字数: 6, 相似度: 77.27% } ### 5 中文纠错 #### 5.1 纠正中文术语的拼写错误,得到在最大距离内相似度最高的修正术语。 需要纠错的中文术语。 返回一个ECResult对象,包含纠错后的英文、中文、拼音,以及器最大错误距离和相似度。 public ECResult ChinesePhraseCorrect(string phraseString); #### 例子: phraseCorrector.ChinesePhraseCorrect("中国人民军"); 【执行结果】{ 中文汉字: 中国人民解放军, 西文拼音: chinese people's liberation army|zhong guo ren min jie fang jun, 错字数: 2, 相似度: 71.43% } #### .2 检查并纠正英语短语的拼写错误。 需要进行拼写检查的英语短语。 返回一个ECResult对象,其中包含了翻译后的中文、英文及拼音属性,以及距离和相似度。 public ECResult EnglishPhraseCorrect(string text); #### 例子: phraseCorrector.EnglisgPhraseCorrect("chinesepeopleslibarmy"); 【执行结果】{ 中文汉字: 中国人民解放军, 西文拼音: chinese people's liberation army, 错字数: 11, 相似度: 65.62% } ### 6 中文/西文/拼音组合纠错 #### 6.1 通过提供的中文、英文或拼音关键字进行中英文匹配。 包含中文关键字的源对象。 包含英文/拼音关键字的源对象。 返回一个新的ECResult对象,包含匹配结果。 public ECResult ChineseEnglishPinyinMache(string chinese, string letters); #### 例子: phraseCorrector.ChineseEnglishPinyinMache( "中国民放军", "chese lib army"); 【执行结果】{ 中文汉字: 中国人民解放军, 西文拼音: chinese people's liberation army, 错字数: 2, 相似度: 71.43% } #### 6.2 通过提供的中文、英文或拼音字符串行警接续后进行中英文匹配。 包含中文关键字的源对象。 包含英文/拼音关键字的源对象。 返回一个新的ECResult对象,包含匹配结果。 public ECResult WordLineMache(string line); #### 例子: phraseCorrector.WordLineMache("人artificial lligence3201智能"); 【执行结果】{ 中文汉字: 人工智能, 西文拼音: artificial intelligence, 数字: 3201, 错字数: 5, 相似度: 78.26% } ### 7. paddleOcr词组拼写检查 自动识别英文/拼英。 #### 7.1 paddleOcr原文 var result = OcrSplitJoint.SplitJoint( new OcrPaddleResult( [ new OcrRegion() { Text= "zhongguorenminjiefang", Score= 0.91689205F , Rect= new RotatedRect(){ Angle= 5.194429F, Center= new Point2f(623.8811f, 343.3074f), Size= new Size2f { Width= 197.18686f, Height= 39.383053f } } }, new OcrRegion(){ Text= "3403", Score=0.885835052F , Rect= new RotatedRect(){ Angle= 2.683775F, Center= new Point2f(X:246.43352F, Y:299.9188F), Size= new Size2f { Width= 108.89606f, Height= 50.89724f } } }, new OcrRegion() { Text= "人工能", Score= 0.75535476F , Rect= new RotatedRect(){ Angle= 90F, Center= new Point2f(481.5f, 330f), Size= new Size2f { Width= 36f, Height= 83f } } } ])); #### 7.2 paddleOcr中文 中文汉字:人工智能 西文拼音:zhongguorenminjiefangjun 数字:3403