PHP图片文字识别

软件下载安装地址:https://jingyan.baidu.com/article/219f4bf788addfde442d38fe.html

下载traineddata 
前往:https://github.com/tesseract-ocr/tesseract/wiki/Data-Files 
下载Data Files for Version 4.00 (November 29, 2016)以及 
Updated Data Files for Version 4.00 (September 15, 2017)

转自:https://blog.csdn.net/weixin_41905562/article/details/81040118

2、php辅助包:

https://github.com/ShuiPingYang/tesseract-ocr-for-php

3、语言包:

https://github.com/tesseract-ocr/tesseract/wiki/Data-Files#data-files-for-version-400-november-29-2016

识别效果还是不错的,直接看例子: 
这是我要识别的图片: 
PHP图片文字识别_第1张图片
识别输出为: 

当 打 开 一 个 终 端 的 时 候 , 该 终 端 最 初 会 抒 行 一 组 命 令 来 定 义 诸 如 提 示 文 本 . 颜 色 等 各 类 设 置 。
这 组 命 令 来 自 位 于 用 户 home 目 录 中 的 -bashre 脚 本 文 件 (-/bashre)。Bash 还 维 护 了 一 个 历 史 记 录 
文 件 -/bash_history, 用 于 保 存 用 户 运 行 过 的 命 令 。- 是 一 种 简 写 , 代 表 用 户 home 目 录 的 路 径 。 
在 Bash 中 , 每 个 命 令 或 是 命 令 序 列 是 通 过 使 用 分 号 或 换 行 符 来 分 隔 的 。 比 如 :[Finished in 3.1s]

则里面还是有些错误,所以会用到训练库那个软件,暂时还没有尝试。 
想要尝试的朋友可以看看: 
https://www.cnblogs.com/cnlian/p/5765871.html

交流论坛: 
https://gitter.im/thiagoalessio/tesseract-ocr-for-php 
摊主的代码老牛比了,贴一个上来: 
前提是你的项目下面已经:

composer require thiagoalessio/tesseract_ocr
  •  
  1. require_once __DIR__ . '/vendor/autoload.php';

  2.  
  3. use thiagoalessio\TesseractOCR\TesseractOCR;

  4.  
  5. # saving image locally

  6. #这个是网上的图片,我第一次看到下面这种用法。

  7. $imageUrl = 'https://files.gitter.im/thiagoalessio/tesseract-ocr-for-php/gFLb/deretan.png';

  8. $imageTempName = tempnam(sys_get_temp_dir(), 'image-from-kartaterazu');

  9. file_put_contents($imageTempName, file_get_contents($imageUrl));

  10.  
  11. # recognizing it

  12. $ocr = new TesseractOCR($imageTempName);

  13. $ocr->psm(4);

  14. echo $ocr->run(), PHP_EOL;

你可能感兴趣的:(PHP)