Tesseract OCR使用介绍
#Tesseract OCR使用介绍
##目录
[TOC]
##下载地址及介绍
- 官网介绍:http://code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3
- Github源码连接: https://github.com/tesseract-ocr
- 开源贡献者主页 https://kevintechnology.com/
##安装 Tesseract
- 语言包查看 https://www.macports.org/ports.php?by=name&substr=tesseract-
- 支持Windows、linux、macOS
1 |
1、安装 tesseract和语言包 |
- Homebrew 是一个包管理器,如果没装的话,在终端执行
1 |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
##使用 Tesseract
- 使用命令行进行图像识别
- imagename 就是要识别的图片文件的名称,outputbase 就是识别结果输出文件的名称。
- lang 就是要识别的语言代码,例如英语为 eng、简体中文为 chi_sim 等等。可以同时识别多种语言,使用 “+” 相连,例如 eng+chi_sim。缺省时识别英语。
1、格式信息如下
1 |
tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...] |
2、示例: 识别image图片并将结果保存在out.txt文件中
1 |
tesseract image.png out -l chi_sim |
3、pagesegmode 为识别的具体模式,具体包含以下模式:
1 |
• 0 = Orientation and script detection (OSD) only. |
##训练样本
- 训练工具 https://github.com/tesseract-ocr/tesseract/wiki/AddOns
- 使用教程 https://github.com/tesseract-ocr/tesseract/wiki/Training-Tesseract
- 提高识别率 https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality
- 清理文本背景 http://www.fmwconcepts.com/imagemagick/textcleaner/index.php
- 提取文本区域 http://www.danvk.org/2015/01/07/finding-blocks-of-text-in-an-image-using-python-opencv-and-numpy.html
- 以jTessBoxEditor为例
1 |
> 1、收集文本信息的图片 |
###1、Make Box Files
- 使用 Tesseract 识别,生成 box 文件:
- 确保 tif 和 box 文件同名且位于同一目录下,用 jTessBoxEditor 打开 tif 文件),或者直接用文本编辑器编辑。
1 |
tesseract hz.font.exp0.tif hz.font.exp0 -l chi_sim -psm 10 batch.nochop makebox |
###2、Run Tesseract for Training
- 使用修改正确后的 box 文件,对 Tesseract 进行训练,生成 .tr 文件:
1 |
tesseract hz.font.exp0.tif hz.font.exp0 -psm 10 nobatch box.train |
###3、Compute the Character Set
- 生成字符集的文本
1 |
unicharset_extractor hz.font.exp0.box hz.font.exp1.box After 3.03 |
正确的格式应该如下:
1 |
110 |
###4、font_properties (new in 3.01)
- 定义字体特征文件,Tesseract-OCR 3.01 以上的版本在训练之前需要创建一个名称为 font_properties 的字体特征文件。font_properties 不含有 BOM 头,文件内容格式如下:
1 |
<fontname> <italic> <bold> <fixed> <serif> <fraktur> |
- 其中 fontname 为字体名称,必须与 [lang].[fontname].exp[num].box 中的名称保持一致。 、 、 、、 的取值为 1 或 0,表示字体是否具有这些属性。
- 这里就是普通字体,不倾斜不加粗,所以新建一个名为 font_properties 的文件,内容为: font 0 0 0 0 0
###5、Clustering
- 修改 Clustering 过程生成的 4 个文件(inttemp、pffmtable、normproto、shapetable)
1 |
shapeclustering -F font_properties -U unicharset hz.font.exp0.tr hz.font.exp1.tr ... mftraining -F font_properties -U unicharset -O hz.unicharset hz.font.exp0.tr hz.font.exp1.tr ... cntraining hz.font.exp0.tr hz.font.exp1.tr ... |
combine_tessdata hz.
1 |
###7、use example * 使用训练的文件进行识别 |
tesseract test.png out -l hz
1 |
##脚本运行 |
#!/bin/sh
read -p “输入你语言:” lang
echo ${lang}
read -p “输入你的字体:” font
echo ${font}
echo “完整文件名为:”
echo ${lang}.${font}.exp0.tif
echo “开始。。。”
echo ${font} 0 0 0 0 0 >font_properties
#tesseract ${lang}.${font}.exp0.tif $(lang).$(font).exp0 -l chi_sim -psm 10 batch.nochop makebox
#read -p “继续生产tr文件?”
tesseract ${lang}.${font}.exp0.tif ${lang}.${font}.exp0 -psm 10 nobatch box.train
unicharset_extractor ${lang}.${font}.exp0.box
shapeclustering -F font_properties -U unicharset ${lang}.${font}.exp0.tr
mftraining -F font_properties -U unicharset -O unicharset ${lang}.${font}.exp0.tr
cntraining ${lang}.${font}.exp0.tr
echo “开始重命名文件”
mv inttemp ${font}.inttemp
mv normproto ${font}.normproto
mv pffmtable ${font}.pffmtable
mv shapetable ${font}.shapetable
mv unicharset ${font}.unicharset
echo “生成最终文件”
combine_tessdata ${font}.
echo “完成”`
Tesseract OCR使用介绍的更多相关文章
- Python下Tesseract Ocr引擎及安装介绍
1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/tesseract,目前最新的源码 ...
- Tesseract——OCR图像识别 入门篇
Tesseract——OCR图像识别 入门篇 最近给了我一个任务,让我研究图像识别,从我们项目的screenshot中识别文字信息,so我开始了学习,与大家分享下. 我看到目前OCR技术有很多,最主要 ...
- Tesseract Ocr引擎
Tesseract Ocr引擎 1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/t ...
- tesseract ocr文字识别Android实例程序和训练工具全部源代码
tesseract ocr是一个开源的文字识别引擎,Android系统中也可以使用.可以识别50多种语言,通过自己训练识别库的方式,可以大大提高识别的准确率. 为了节省大家的学习时间,现将自己近期的学 ...
- 开源图片文字识别引擎——Tesseract OCR
Tessseract为一款开源.免费的OCR引擎,能够支持中文十分难得.虽然其识别效果不是很理想,但是对于要求不高的中小型项目来说,已经足够用了. 文字识别可应用于许多领域,如阅读.翻译.文献资料的检 ...
- Tesseract OCR简单实用介绍
做字符识别,不能不了解google的Tesseract-OCR,但是如何在自己的工程中使用其API倒是语焉不详,官网上倒是很详尽地也很啰嗦地介绍如何重新编译生成适合自己平台的lib和dll,经过近些天 ...
- selenium使用笔记(二)——Tesseract OCR
在自动化测试过程中我们经常会遇到需要输入验证码的情况,而现在一般以图片验证码居多.通常我们处理这种情况应该用最简单的方式,让开发给个万能验证码或者直接将验证码这个环节跳过.之前在技术交流群里也跟朋友讨 ...
- Tesseract–OCR 库原理探索
一,简介: Tesseract is probably the most accurate open source OCR engine available. Combined with the Le ...
- alfresco install in linux, and integrated with tesseract ocr
本文描述在Linux系统上安装Alfresco的步骤: 1. 下载安装文件:alfresco-community-5.0.d-installer-linux-x64.bin 2. 增加执行权限并执行: ...
随机推荐
- idea中maven项目依赖jar一直标红线
网上maven仓库中无法下载某些jar包,这时候就需要手动下载,并导入maven, 导入命令demo: mvn install:install-file -DgroupId=javax.media - ...
- 代码验证ncut和谱聚类的系数
W = rand(30); W = W+W'; I = cell(3,1); I{1} = 1:10; I{2} = 11:20; I{3} = 21:30; vol = -ones(3,1); fo ...
- 爬虫笔记(十三)——lxml库的使用
HTML示例代码: text = ''' <div> <ul> <li class="item-0"><a href="link ...
- 吴裕雄--天生自然C语言开发: 输入 & 输出
#include <stdio.h> int main() { ; printf("Number = %d", testInteger); ; } #include & ...
- openfire配置好文
http://www.th7.cn/db/mysql/201406/59838.shtml 下载地址:Openfire 3.8.2 Release
- LGOJ3804 【模板】后缀自动机
题目链接: link 题目大意 给定一个只包含小写字母的字符串\(S\), 请你求出 \(S\) 的所有出现次数不为 \(1\) 的子串的出现次数乘上该子串长度的最大值. Solution 预处理出每 ...
- open 管道用法|Getopt::Long
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my ($number,$in,$out); GetOptions( " ...
- 从二叉搜索树到AVL树再到红黑树 B树
这几种树都属于数据结构中较为复杂的,在平时面试中,经常会问理解用法,但一般不会问具体的实现,所以今天来梳理一下这几种树之间的区别与联系,感谢知乎用户@Cailiang,这篇文章参考了他的专栏. 二叉查 ...
- centos7 ModuleNotFoundError: No module named 'users'
centos7下运行django项目时ModuleNotFoundError: No module named 'users' 由于我的项目目录是下面这样: 因为找不到users的路径 所以在mana ...
- [LC] 437. Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...