tessract-ocr文本识别系统网页搭建【PHP】

2023-11-15

tessract-ocr文本识别系统网页搭建

下面是我搭的网站:

OCR文本识别系统


在安装后tesstact-ocr后,我找到了一个利用php调用ocr接口的方法,在github上有这样一个项目:

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

这个就是用php封装了一下命令行的ocr接口

我利用composer把源码下载下来,然后编写了一个简单的ocr识别网站

利用一下命令进行下载:

composer requir thiagoalessio/tesseract_ocr


下面展示各个函数具体用法

Tesseract OCR for PHP

A wrapper to work with Tesseract OCR inside PHP.

Total Downloads Build Status Code Climate Test Coverage

Installation

First of all, make sure you have Tesseract OCR installed. (v3.03 or greater)

As a composer dependency

{
    "require": {
        "thiagoalessio/tesseract_ocr": "1.0.0-RC"
    }
}

Usage

Basic usage

Given the following image (text.png):

The quick brown fox jumps over the lazy dog

And the following code:

<?php
echo (new TesseractOCR('text.png'))
    ->run();

The output would be:

The quick brown fox
jumps over the lazy
dog.

Other languages

Given the following image (german.png):

grüßen - Google Translate said it means "to greet" in German

And the following code:

<?php
echo (new TesseractOCR('german.png'))
    ->run();

The output would be:

griifien

Which is not good, but defining a language:

<?php
echo (new TesseractOCR('german.png'))
    ->lang('deu')
    ->run();

Will produce:

grüßen

Multiple languages

Given the following image (multi-languages.png):

The phrase "I each apple sushi", with mixed English, Japanese and Portuguese

And the following code ....

<?php
echo (new TesseractOCR('multi-languages.png'))
    ->lang('eng', 'jpn', 'por')
    ->run();

The output would be:

I eat 寿司 de maçã

Inducing recognition

Given the following image (8055.png):

Number 8055

And the following code ....

<?php
echo (new TesseractOCR('8055.png'))
    ->whitelist(range('A', 'Z'))
    ->run();

The output would be:

BOSS

API

->executable('/path/to/tesseract')

Define a custom location of the tesseract executable, if by any reason it is not present in the $PATH.

->tessdataDir('/path')

Specify a custom location for the tessdata directory.

->userWords('/path/to/user-words.txt')

Specify the location of user words file.

This is a plain text file containing a list of words that you want to be considered as a normal dictionary words by tesseract.

Useful when dealing with contents that contain technical terminology, jargon, etc.

Example of a user words file:

$ cat /path/to/user-words.txt
foo
bar

->userPatterns('/path/to/user-patterns.txt')

Specify the location of user patterns file.

If the contents you are dealing with have known patterns, this option can help a lot tesseract's recognition accuracy.

Example of a user patterns file:

$ cat /path/to/user-patterns.txt'
1-\d\d\d-GOOG-441
www.\n\\\*.com

->lang('lang1', 'lang2', 'lang3')

Define one or more languages to be used during the recognition. A complete list of available languages can be found athttps://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages

Tip from @daijiale: Use the combination ->lang('chi_sim', 'chi_tra') for proper recognition of Chinese.

->psm(6)

Specify the Page Segmentation Mode, which instructs tesseract how to interpret the given image.

Possible psm values are:

 0 = Orientation and script detection (OSD) only.
 1 = Automatic page segmentation with OSD.
 2 = Automatic page segmentation, but no OSD, or OCR.
 3 = Fully automatic page segmentation, but no OSD. (Default)
 4 = Assume a single column of text of variable sizes.
 5 = Assume a single uniform block of vertically aligned text.
 6 = Assume a single uniform block of text.
 7 = Treat the image as a single text line.
 8 = Treat the image as a single word.
 9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.

->config('configvar', 'value')

Tesseract offers incredible control to the user through its 660 configuration vars.

You can see the complete list by running the following command:

$ tesseract --print-parameters
Tesseract parameters:
... long list with all parameters ...

->whitelist(range('a', 'z'), range(0, 9), '-_@')

This is a shortcut for ->config('tessedit_char_whitelist', 'abcdef....').

Where to get help

  • #tesseract-ocr-for-php on freenode IRC

License

Apache License 2.0.


下面就是编一个php网页了:


我用了bootstrap,和表单进行文件上传,

下面直接上代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>OCR文本识别系统</title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>


<style type="text/css">
  .form{
    position:absolute;
    left:600px;
    top:100px 

  }
  .image{
    position:absolute;
    left:10px;
    top:60px 
  }
  .retext{
    position:absolute;
    top:370px 
  }

  .body{
    background-image: url("./img/background.jpg");
  }
  .text{
    text-align: center;       
  }
</style>
</head>

<body class = "body">
<?php// $file_path = './img/text.png'?>
<nav class="navbar navbar-inverse" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.php">OCR文本识别系统</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <!--<ul class="nav navbar-nav">
        <li class="active"><a href="#">系统介绍</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
-->
      <!--<form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      -->
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">系统介绍</a></li>
        <li><a href="#">实验室介绍</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">参考资源 <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="https://github.com/thiagoalessio/tesseract-ocr-for-php">tesseract-ocr-for-php</a></li>
            <li><a href="http://getbootstrap.com/">Bootstrap</a></li>
            <li><a href="http://www.w3school.com.cn/">W3School</a></li>
            <li class="divider"></li>
            <li><a href="https://github.com/tesseract-ocr/tesseract">tesseract-ocr</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>





<div class = "form">
  <form  action="" method="post" enctype="multipart/form-data">
    <label for="file">上传图片:</label>
      <input type="file" name="file" id="file" /> 
      <br />
      <p>请选择语言类型(可多选):</p> 
      <div class="checkbox">
        <label>
         <input type="checkbox" value="English" name ="mrbook[]" >
         English
        </label>
      </div>
      <div class="checkbox">
       <label>
        <input type="checkbox" value="中文" name ="mrbook[]">
        中文
       </label>
     </div>

     <div class="checkbox">
     <label>
       <input type="checkbox" value="Deutsch" name ="mrbook[]">
       Deutsch
     </label>
     </div>
     <div class="checkbox">
       <label>
       <input type="checkbox" value="한국의" name ="mrbook[]">
         한국의
       </label>
     </div>
      <input type="submit" name="submit" class="btn btn-success" value="Submit" />
</form>
</div>


<?php

    if(!empty($_FILES['file']))
    {
        $file_path = sprintf("./upload/%s",$_FILES['file']['name']);
        if(!move_uploaded_file($_FILES["file"]["tmp_name"],
            $file_path))
            echo $_FILES["file"]["error"];
        for($i=0 ;$i<count($_POST[mrbook]);$i++)
            if(strcmp($_POST[mrbook][$i],"English") == 0)
                $lan_type = sprintf("%s %s",$lan_type,"eng");
            else if(strcmp($_POST[mrbook][$i],"中文") == 0)
                $lan_type = sprintf("%s %s",$lan_type,"chi_sim");

    }


    require '../vendor/autoload.php';
    $ocr = new \TesseractOCR($file_path);
    $string = $ocr ->lang($lan_type) ->run();

?>
<div class = "image">
   <p>
    <img src=<?php if(!empty($file_path)) echo $file_path; else echo './img/180.jpg';?> width="440" height="300" />
   </p>
</div>

<div class = "retext" style ="width :100%">
<p>识别结果:</p>
<textarea class="form-control" rows="10"><?php echo $string; ?></textarea>
</div>



<!--
<p>
<img src="./img/text.png" width="128" height="128" />
</p>
-->
<?php
/*require '../vendor/autoload.php';
$ocr = new \TesseractOCR('./img/text.png');
$string = $ocr->run();
echo $string;
 */
?>


</body>
</html>


以后还会再优化,代码很简单,不再赘述。
写的不太好,请指出不足^.^!


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

tessract-ocr文本识别系统网页搭建【PHP】 的相关文章

  • 使用 yaml 路由描述时如何在运行时获取 Symfony2 中的路由名称?

    在这里你可以找到我的n关于 Symfony2 的第一个问题 我正在与一个分页捆绑 https github com makerlabs PagerBundle wiki使用中提供的路由名称routing yml文件 从我的角度来看 这种方法
  • Yii2 无效调用:设置只读属性

    我有一个Post具有多对多关系的模型Tags 在 Post 模型中定义 public function getTags return this gt hasMany Tags className id gt tag id gt viaTab
  • 单元测试和静态方法

    阅读并学习单元测试 试图理解以下帖子 http misko hevery com 2008 12 15 static methods are death to testability 这解释了静态函数调用的困难 我不太清楚这个问题 我一直认
  • 突出显示单词并提取其附近文本的函数

    我有一个文本例如 Etiam porta semmalesuada magna mollis euismod 整数取数 ante venenatis dapibus posuere velit aliquet 埃蒂亚姆 门塔 塞姆 male
  • yii2 更新后返回上一页

    更新记录后如何将用户重定向到上一页 这是典型的场景 用户在索引页面中过滤结果或对记录进行分页 然后找到想要编辑的记录并单击编辑按钮 他们更新该记录的数据 一旦单击 更新 按钮 他们将被重定向到索引视图 但具有先前选择的过滤器 页面 更新后我
  • 选择 mysql 枚举的 php 函数

    因此 我创建了一个函数 它将从数据库中的枚举字段中提取值
  • 无法在 PHP 中使用 SFTP

    我正在用 PHP 编写一个简单的 SFTP 客户端 因为我们需要通过 n 个远程服务器以编程方式检索文件 我正在使用 PECL SSH2 扩展 不过 我遇到了障碍 php net 上的文档建议您可以这样做 stream fopen ssh2
  • imagecreatefrompng(和 imagecreatefromstring)导致不可恢复的致命错误

    当我尝试在不正确的 png 图像上使用 php gd 函数时 出现致命的 PHP 错误 这似乎是某种错误 因为根据函数文档 imagecreatefrompng 例如 return resource an image resource id
  • 使用 cURL 解释 PHP 中的令牌返回

    我无法解释从该服务器获得的响应 当用户尝试访问我的服务器上的页面时 此 PHP 首先运行以查看它们是否具有有效的令牌 通过我未在此处显示的上一个登录页面 ch curl init searchURL http example com isT
  • 如何使用 Shopify API 将商品添加到购物车

    我正在使用 Shopify API 开发自定义网络应用程序 这里的想法是使用应用程序作为独家店面 只需向 Shopify API 发出请求 我已在我的 Shopify 帐户中设置了一个私人应用程序来执行此操作 我从 api 提取产品没有问题
  • 提交表单时显示警告框

    所以我有这两页 pageOne php and pageTwo php 表格在pageOne php
  • 获取特定 $_POST 数组的值

    name qty foreach POST as items gt value check qty gt 1 echo key gt value br 如何仅显示其值为 qty1 gt value qty2 gt value gt 0 的项
  • 无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件

    我尝试使用 codeigniter 框架发送邮件 但它会引发错误 无法使用 PHP mail 发送电子邮件 您的服务器可能未配置为使用此方法发送邮件 From prakash t lt email protected cdn cgi l e
  • 如何在Redis中正确存储图片?

    决定将图像存储在Redis中 如何正确执行 现在我这样做 redis gt set image path here is the base64 image code 我不确定这是否正常 将图片存储在Redis中是完全可以的 Redis 键和
  • 证明字符串算法[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • xampp openssl 调用 openssl_pkey_new() 时出错;

    所以我试图让 openssl 在我的 Windows 安装的 xampp 1 7 3 上工作 它是用 OpenSSL 0 9 8l 构建的 这只是我第二次在 amp 安装上安装 openssl 但第一次进展顺利 这是在同一台机器上的 wam
  • 使用 google 检查 url,安全 = 活动

    如何检查 url 是否被 google 显示 Example https www google com search q redtubex xxx safe active Code input http www example com in
  • 限制传出 PHP+curl 请求的速率

    有没有办法限制 有延迟 向外部服务器发出 PHP curl 请求的速率 以便每秒只有 n 个请求 PHP 在 Fastcgi 模式下使用 因此无法使用睡眠 是的 有curl 多重处理程序 您可以使用 OOP 方式以 OOP 方式完成此操作这
  • 删除 cookie php

    我正在尝试创建一个带有登录系统的平台 并将用户名和密码存储在cookie中 以使用户即使关闭浏览器然后再次输入也能保持登录状态 我设法保存了cookie 但我不知道如何制作注销按钮 这是代码 function logout body app
  • 如何对“2-1”这样的字符串进行数学计算以产生“1”?

    我只是想知道 PHP 是否有一个函数可以接受像这样的字符串2 1并产生它的算术结果 或者我必须手动执行此操作explode 获取算术运算符左侧和右侧的值 我知道这个问题很老了 但我昨晚在寻找不太相关的东西时遇到了它 而且这里的每个答案都很糟

随机推荐

  • nodejs高大上的部署方式-PM2

    如果直接通过node app来启动 如果报错了可能直接停在整个运行 supervisor感觉只是拿来用作开发环境的 再网上找到pm2 目前似乎最常见的线上部署nodejs项目的有forever pm2这两种 使用场合 supervisor是
  • 旋转链表——快慢指针法的实践

    一 题目 给你一个链表的头节点 head 旋转链表 将链表每个节点向右移动 k 个位置 示例1 输入 1 gt 2 gt 3 gt 4 gt 5 gt NULL k 2 输出 4 gt 5 gt 1 gt 2 gt 3 gt NULL 解释
  • matlab灵敏度分析操作,灵敏度分析 使用MATLAB编写.doc

    灵敏度分析 使用MATLAB编写 实验二 线性规划的灵敏度分析 实验目的 1 线性规划求解的单纯形法的灵敏度分析的编程实现 2 掌握使用matlab Lingo Excel的规划求解功能求解 并利用 敏感性报告 进行分析 二 实验内容 课本
  • wazuh中的规则编写以及日志分析

    目录 什么是wazuh 如何搭建wazuh 实验环境 wazuh的规则 配置代理 wazuh中的配置了解 ssh的暴力破解 用户自定义规则 SQL注入的检测 什么是wazuh Wazuh是一个免费 开源和企业级的安全监控解决方案 用于威胁检
  • 【2223sW2】LOG2

    写在前面 好好学习 走出宿舍 走向毕设 一些心路历程记录 很少有代码出现 因为鬼知道哪条代码到时候变成毕设的一部分了咧 还是不要给自己的查重挖坑罢了 23 3 2 检验FFT 早上师兄帮忙看了一眼我画的丑图 说样子应该是对的 增加了检查的精
  • D3DXMESHOPT_ATTRSORT

    Mesh的顶点和索引能够被重组以便能更有效的渲染mesh 当我们这样做时 我们说我们优化了一个mesh 我们可以使用下面的方法来进行优化 HRESULT ID3DXMesh OptimizeInplace DWORD Flags CONST
  • DbVisualizer数据库管理工具

    一款数据库管理工具 推荐使用 安装包及破解方法见盘附件 百度云盘 http pan baidu com share link shareid 253466598 uk 1629211176
  • 【Unity3D日常开发】Unity3D中比较string字符串的常用方法

    推荐阅读 CSDN主页 GitHub开源地址 Unity3D插件分享 简书地址 我的个人博客 大家好 我是佛系工程师 恬静的小魔龙 不定时更新Unity开发技巧 觉得有用记得一键三连哦 一 前言 字符串string的比较有很多方法 比如 E
  • vlc实现PC与树莓派的视频流传输

    目录 一 使用vlc实现PC与树莓派之间的视频流传输 一 Windows 二 树莓派 二 树莓派与Windows系统之间的聊天 三 非堵塞方式传输图像 视频文件 一 使用vlc实现PC与树莓派之间的视频流传输 一 Windows 安装下载v
  • opencv双目视觉标定,激光结构光提取,指定特征点获取世界坐标

    双目视觉标定 激光结构光提取 指定特征点获取世界坐标 标定方面 校正 结构光提取 二维点转换为三维点 总结 这学期在做双目视觉方面的事情 因为没人带 自己一个人踩了很多坑 因此在这写一点自己的总结心得 标定方面 首先标定主要就是为了确定左右
  • Qt5下串口编程中“QIODevice::write (QSerialPort): device not open”问题的分析处理总结

    一 实现功能说明 在主窗口中先配置好串口并 打开串口 在菜单中点击 测量 子窗口 进入子窗口画面 点击子窗口的 测量 按钮 实现读取传感器指令的数据发送 二 程序说明 主窗口 1 MainWidget h 定义类MainWidget 构造函
  • 数据库行锁

    数据库行锁 仅作为笔记 码字不易 转载请标明出处 文章目录 数据库行锁 前言 一 数据库行锁 前言 仅作为笔记 一 数据库行锁 两阶段锁 在 InnoDB 事务中 锁是在需要的时候才加上的 但并 是 需要 就立刻释放 而是要等到事务结束时才
  • Mongdb查询 - 比较运算符、逻辑运算符、$type、游标

    目录 一 比较运算符 Mongo查询条件和SQL查询对照表 比较运算符示例 二 逻辑操作符 逻辑操作符示例 not用法 and用法 eq用法 or用法 三 type操作符 四 文档游标 基本操作 游标的执行顺序 limit skip sor
  • CGAL的编译与配置

    CGAL的编译与配置 网上已经有一些配置的步骤 但是在具体配置过程中 发现有很多问题 折腾了两天后终于配置成功 在此做更详细的记录 准备 CGAL CGAL4 7和CGAL4 9的库 分别编译成功了 BOOST boost1 59的版本 C
  • 2022经典前端面试题大全 h5 +cs +js

    一 页面布局 三栏布局 题目 假设高度已知 请写出三栏布局 其中左栏 右栏宽度各为 300px 中间自适应 解答 可以有很多种布局方式 这里列出五种 float布局 absolute布局 flex布局 table布局 grid布局 代码如下
  • mybatis设计大接口的坑以及做法

    先说一些注意事项 1 注 mybatis一个mapper java文件只能对应一个mapper xml文件 所以不能一个mapper java对应两个xml 一个默认的 一个自己拓展的 2 注 如果表中有字段是text selectByEx
  • 可视化笔记1--matplotlib 常见图形绘制1

    可视化笔记1 matplotlib 常见图形绘制1 最近需要使用python实现部分数据的可视化 于是简单学习了下matplotlib绘图功能 基本包括 散点图 折线图 条形图 直方图 饼状图 箱形图等几种常用图形的绘制方式 相应学习笔记分
  • 解决谷歌浏览器无法自动播放HTML文件的声音和视频问题的方法

    首先 先检测一下浏览器是否能支持自动播放 点击下方链接进行检测 https video dev github io can autoplay 本人检测的谷歌浏览器结果是 结果显示 谷歌浏览器不能支持有声自动播放视频和音频 包括内联的视频 但
  • 密码学研究重点

    密码学涵盖了认证 数字签名以及更多基本的安全功能 密码学涉及领域及其宽广 包括计算机安全 高等数学 经济学 量子物理学 民法和刑法 统计学 芯片设计 软件优化 政治 用户界面设计等 0x01 密码学重要性 密码学本身没有价值 必须作为一个系
  • tessract-ocr文本识别系统网页搭建【PHP】

    tessract ocr文本识别系统网页搭建 下面是我搭的网站 OCR文本识别系统 在安装后tesstact ocr后 我找到了一个利用php调用ocr接口的方法 在github上有这样一个项目 https github com thiag