当前位置:   article > 正文

tessract-ocr文本识别系统网页搭建php_进一步完善及操作流程详解_php tesseractocr

php tesseractocr

项目github源代码:

https://github.com/chudongfang/my_work_git/tree/master/ocr_php

1.首先,安装tessract-ocr,确保3.03版本以上

ubuntu 

sudo apt-get install tesseract-ocr
centos

yum install tesseract.i686

2.由于要调用php库,安装php管理依赖的工具comporser

3.从comporser中得到   tesseract-ocr-for-php

     执行命令;

comporser requir thiagoalessio/tesseract_ocr
确保版本最新!:1.0.0-RC


4.调用其进行进行网页编写

网页地址:115.159.205.168/ocr_php/public/index.php

index.php

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>OCR文本识别系统</title>
  6. <!-- 新 Bootstrap 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  8. <!-- 可选的Bootstrap主题文件(一般不用引入) -->
  9. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
  10. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  11. <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
  12. <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
  13. <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  14. <style type="text/css">
  15. .form{
  16. position:absolute;
  17. left:600px;
  18. top:100px
  19. }
  20. .image{
  21. position:absolute;
  22. left:10px;
  23. top:60px
  24. }
  25. .retext{
  26. position:absolute;
  27. top:370px
  28. }
  29. .body{
  30. background-image: url("./img/background.jpg");
  31. }
  32. .text{
  33. text-align: center;
  34. }
  35. </style>
  36. </head>
  37. <body class = "body">
  38. <?php //$file_path = './img/180.jpg'?>
  39. <nav class="navbar navbar-inverse" role="navigation">
  40. <div class="container-fluid">
  41. <!-- Brand and toggle get grouped for better mobile display -->
  42. <div class="navbar-header">
  43. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
  44. <span class="sr-only">Toggle navigation</span>
  45. <span class="icon-bar"></span>
  46. <span class="icon-bar"></span>
  47. <span class="icon-bar"></span>
  48. </button>
  49. <a class="navbar-brand" href="index.php">OCR文本识别系统</a>
  50. </div>
  51. <!-- Collect the nav links, forms, and other content for toggling -->
  52. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  53. <!--<ul class="nav navbar-nav">
  54. <li class="active"><a href="#">系统介绍</a></li>
  55. <li class="dropdown">
  56. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
  57. <ul class="dropdown-menu" role="menu">
  58. <li><a href="#">Action</a></li>
  59. <li><a href="#">Another action</a></li>
  60. <li><a href="#">Something else here</a></li>
  61. <li class="divider"></li>
  62. <li><a href="#">Separated link</a></li>
  63. <li class="divider"></li>
  64. <li><a href="#">One more separated link</a></li>
  65. </ul>
  66. </li>
  67. </ul>
  68. -->
  69. <!--<form class="navbar-form navbar-left" role="search">
  70. <div class="form-group">
  71. <input type="text" class="form-control" placeholder="Search">
  72. </div>
  73. <button type="submit" class="btn btn-default">Submit</button>
  74. </form>
  75. -->
  76. <ul class="nav navbar-nav navbar-right">
  77. <li><a href="./introduce1.php">系统介绍</a></li>
  78. <li><a href="#">实验室介绍</a></li>
  79. <li class="dropdown">
  80. <a href="#" class="dropdown-toggle" data-toggle="dropdown">参考资源 <span class="caret"></span></a>
  81. <ul class="dropdown-menu" role="menu">
  82. <li><a href="https://github.com/thiagoalessio/tesseract-ocr-for-php">tesseract-ocr-for-php</a></li>
  83. <li><a href="http://getbootstrap.com/">Bootstrap</a></li>
  84. <li><a href="http://www.w3school.com.cn/">W3School</a></li>
  85. <li class="divider"></li>
  86. <li><a href="https://github.com/tesseract-ocr/tesseract">tesseract-ocr</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div><!-- /.navbar-collapse -->
  91. </div><!-- /.container-fluid -->
  92. </nav>
  93. <div class = "form">
  94. <form action="" method="post" enctype="multipart/form-data">
  95. <label for="file">上传图片:</label>
  96. <input type="file" name="file" id="file" />
  97. <br />
  98. <p>请选择语言类型(可多选):</p>
  99. <div class="checkbox">
  100. <label>
  101. <input type="checkbox" value="English" name ="mrbook[]" >
  102. English
  103. </label>
  104. </div>
  105. <div class="checkbox">
  106. <label>
  107. <input type="checkbox" value="中文" name ="mrbook[]">
  108. 中文
  109. </label>
  110. </div>
  111. <div class="checkbox">
  112. <label>
  113. <input type="checkbox" value="Deutsch" name ="mrbook[]">
  114. Deutsch
  115. </label>
  116. </div>
  117. <div class="checkbox">
  118. <label>
  119. <input type="checkbox" value="한국의" name ="mrbook[]">
  120. 한국의
  121. </label>
  122. </div>
  123. <input type="submit" name="submit" class="btn btn-success" value="Submit" />
  124. </form>
  125. </div>
  126. <?php
  127. if(!empty($_FILES['file']))
  128. {
  129. $file_path = sprintf("./upload/%s",$_FILES['file']['name']);
  130. if(!move_uploaded_file($_FILES["file"]["tmp_name"],
  131. $file_path))
  132. echo $_FILES["file"]["error"];
  133. for($i=0 ;$i<count($_POST[mrbook]);$i++)
  134. if(strcmp($_POST[mrbook][$i],"English") == 0)
  135. $lan_type = sprintf("%s %s",$lan_type,"eng");
  136. else if(strcmp($_POST[mrbook][$i],"中文") == 0)
  137. $lan_type = sprintf("%s %s",$lan_type,"chi_sim");
  138. }
  139. require '../vendor/autoload.php';
  140. $ocr = new \TesseractOCR($file_path);
  141. $string = $ocr ->lang($lan_type) ->run();
  142. ?>
  143. <div class = "image">
  144. <p>
  145. <img src=<?php
  146. if(!empty($file_path)) echo $file_path;
  147. else echo './img/180.jpg'; ?>
  148. width="440" height="300" />
  149. </p>
  150. </div>
  151. <div class = "retext" style ="width :100%">
  152. <p>识别结果:</p>
  153. <textarea class="form-control" rows="10"><?php echo $string; ?></textarea>
  154. </div>
  155. </body>
  156. </html>



introduce1.php

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>OCR文本识别系统</title>
  6. <!-- 新 Bootstrap 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  8. <!-- 可选的Bootstrap主题文件(一般不用引入) -->
  9. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
  10. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  11. <link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
  12. <link type="text/css" rel="stylesheet" href="./css/carousel.css">
  13. <script type="text/javascript" src="./js/jquery.js"></script>
  14. <script type="text/javascript" src="./js/carousel.js"></script>
  15. <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
  16. <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
  17. <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  18. <style type="text/css">
  19. .form{
  20. position:absolute;
  21. left:600px;
  22. top:100px
  23. }
  24. .image{
  25. position:absolute;
  26. left:10px;
  27. top:60px
  28. }
  29. .retext{
  30. position:absolute;
  31. top:370px
  32. }
  33. .image_show{
  34. margin-left: auto;
  35. margin-right: auto;
  36. //margin-left:100px;
  37. }
  38. .body{
  39. background-image: url("");
  40. }
  41. .text{
  42. text-align: center;
  43. }
  44. </style>
  45. </head>
  46. <body class = "body">
  47. <nav class="navbar navbar-inverse" role="navigation">
  48. <div class="container-fluid">
  49. <!-- Brand and toggle get grouped for better mobile display -->
  50. <div class="navbar-header">
  51. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
  52. <span class="sr-only">Toggle navigation</span>
  53. <span class="icon-bar"></span>
  54. <span class="icon-bar"></span>
  55. <span class="icon-bar"></span>
  56. </button>
  57. <a class="navbar-brand" href="index.php">OCR文本识别系统</a>
  58. </div>
  59. <!-- Collect the nav links, forms, and other content for toggling -->
  60. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  61. <!--<ul class="nav navbar-nav">
  62. <li class="active"><a href="#">系统介绍</a></li>
  63. <li class="dropdown">
  64. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
  65. <ul class="dropdown-menu" role="menu">
  66. <li><a href="#">Action</a></li>
  67. <li><a href="#">Another action</a></li>
  68. <li><a href="#">Something else here</a></li>
  69. <li class="divider"></li>
  70. <li><a href="#">Separated link</a></li>
  71. <li class="divider"></li>
  72. <li><a href="#">One more separated link</a></li>
  73. </ul>
  74. </li>
  75. </ul>
  76. -->
  77. <!--<form class="navbar-form navbar-left" role="search">
  78. <div class="form-group">
  79. <input type="text" class="form-control" placeholder="Search">
  80. </div>
  81. <button type="submit" class="btn btn-default">Submit</button>
  82. </form>
  83. -->
  84. <ul class="nav navbar-nav navbar-right">
  85. <li><a href="#">系统介绍</a></li>
  86. <li><a href="#">实验室介绍</a></li>
  87. <li class="dropdown">
  88. <a href="#" class="dropdown-toggle" data-toggle="dropdown">参考资源 <span class="caret"></span></a>
  89. <ul class="dropdown-menu" role="menu">
  90. <li><a href="https://github.com/thiagoalessio/tesseract-ocr-for-php">tesseract-ocr-for-php</a></li>
  91. <li><a href="http://getbootstrap.com/">Bootstrap</a></li>
  92. <li><a href="http://www.w3school.com.cn/">W3School</a></li>
  93. <li class="divider"></li>
  94. <li><a href="https://github.com/tesseract-ocr/tesseract">tesseract-ocr</a></li>
  95. </ul>
  96. </li>
  97. </ul>
  98. </div><!-- /.navbar-collapse -->
  99. </div><!-- /.container-fluid -->
  100. </nav>
  101. <div id="container">
  102. <p><a href="#">
  103. OCR演示
  104. </a></p>
  105. <div style="text-align:center;clear:both">
  106. <script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
  107. <script src="/follow.js" type="text/javascript"></script>
  108. </div>
  109. </div>
  110. <script src="js/index.js"></script>
  111. <p><font size="5px">点击图片进行识别</font></p>
  112. <div class="J_Poster poster-main image_show" data-setting='{
  113. "width":800,
  114. "height":500,
  115. "posterWidth":700,
  116. "posterHeight":500,
  117. "scale":0.8,
  118. "autoPlay":true,
  119. "delay":2000,
  120. "speed":300
  121. }'>
  122. <div class="poster-btn poster-prev-btn"></div>
  123. <ul class="poster-list">
  124. <li class="poster-item"><a href="<?php $file_name = "./img/eng_1.png" ; $lan_type = "eng"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  125. <li class="poster-item"><a href="<?php $file_name = "./img/eng_2.png" ; $lan_type = "eng"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  126. <li class="poster-item"><a href="<?php $file_name = "./img/eng_3.png" ; $lan_type = "eng"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  127. <li class="poster-item"><a href="<?php $file_name = "./img/chi_sim1.png" ; $lan_type = "chi_sim"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  128. <li class="poster-item"><a href="<?php $file_name = "./img/chi_sim2.png" ; $lan_type = "chi_sim"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  129. <li class="poster-item"><a href="<?php $file_name = "./img/chi_sim3.png" ; $lan_type = "chi_sim"; echo "./intro_deal.php?file_name=".$file_name."&lan_type=". $lan_type;?>"><img src="<?php echo $file_name?>" width="100%" height="100%"></a></li>
  130. </ul>
  131. <div class="poster-btn poster-next-btn"></div>
  132. </div>
  133. <!--<p style="height:50px;"></p>
  134. <div class="J_Poster poster-main" data-setting='{
  135. "width":800,
  136. "height":500,
  137. "posterWidth":640,
  138. "posterHeight":270,
  139. "scale":0.8,
  140. "autoPlay":true,
  141. "delay":5000,
  142. "speed":300,
  143. "vericalAlign":"top"
  144. }'>
  145. <div class="poster-btn poster-prev-btn"></div>
  146. <ul class="poster-list">
  147. <li class="poster-item"><a href="#"><img src="./img/1.jpg" width="100%" height="100%"></a></li>
  148. <li class="poster-item"><a href="#"><img src="./img/2.jpg" width="100%" height="100%"></a></li>
  149. <li class="poster-item"><a href="#"><img src="./img/3.jpg" width="100%" height="100%"></a></li>
  150. <li class="poster-item"><a href="#"><img src="./img/4.jpg" width="100%" height="100%"></a></li>
  151. </ul>
  152. <div class="poster-btn poster-next-btn"></div>
  153. </div>
  154. -->
  155. <script>
  156. $(function(){
  157. Carousel.init($(".J_Poster"));
  158. });
  159. </script>
  160. </body>
  161. </html>


intro_deal.php

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>OCR文本识别系统</title>
  6. <!-- 新 Bootstrap 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  8. <!-- 可选的Bootstrap主题文件(一般不用引入) -->
  9. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
  10. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  11. <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
  12. <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
  13. <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  14. <style type="text/css">
  15. .form{
  16. position:absolute;
  17. left:600px;
  18. top:100px
  19. }
  20. .image{
  21. position:absolute;
  22. left:10px;
  23. top:60px
  24. }
  25. .retext{
  26. position:absolute;
  27. left:450px;
  28. top :70px;
  29. }
  30. .body{
  31. background-image: url("./img/background.jpg");
  32. }
  33. .text{
  34. text-align: center;
  35. }
  36. </style>
  37. </head>
  38. <body class = "body">
  39. <?php //$file_path = './img/180.jpg'?>
  40. <nav class="navbar navbar-inverse" role="navigation">
  41. <div class="container-fluid">
  42. <!-- Brand and toggle get grouped for better mobile display -->
  43. <div class="navbar-header">
  44. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
  45. <span class="sr-only">Toggle navigation</span>
  46. <span class="icon-bar"></span>
  47. <span class="icon-bar"></span>
  48. <span class="icon-bar"></span>
  49. </button>
  50. <a class="navbar-brand" href="index.php">OCR文本识别系统</a>
  51. </div>
  52. <!-- Collect the nav links, forms, and other content for toggling -->
  53. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  54. <!--<ul class="nav navbar-nav">
  55. <li class="active"><a href="#">系统介绍</a></li>
  56. <li class="dropdown">
  57. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
  58. <ul class="dropdown-menu" role="menu">
  59. <li><a href="#">Action</a></li>
  60. <li><a href="#">Another action</a></li>
  61. <li><a href="#">Something else here</a></li>
  62. <li class="divider"></li>
  63. <li><a href="#">Separated link</a></li>
  64. <li class="divider"></li>
  65. <li><a href="#">One more separated link</a></li>
  66. </ul>
  67. </li>
  68. </ul>
  69. -->
  70. <!--<form class="navbar-form navbar-left" role="search">
  71. <div class="form-group">
  72. <input type="text" class="form-control" placeholder="Search">
  73. </div>
  74. <button type="submit" class="btn btn-default">Submit</button>
  75. </form>
  76. -->
  77. <ul class="nav navbar-nav navbar-right">
  78. <li><a href="./introduce1.php">系统介绍</a></li>
  79. <li><a href="#">实验室介绍</a></li>
  80. <li class="dropdown">
  81. <a href="#" class="dropdown-toggle" data-toggle="dropdown">参考资源 <span class="caret"></span></a>
  82. <ul class="dropdown-menu" role="menu">
  83. <li><a href="https://github.com/thiagoalessio/tesseract-ocr-for-php">tesseract-ocr-for-php</a></li>
  84. <li><a href="http://getbootstrap.com/">Bootstrap</a></li>
  85. <li><a href="http://www.w3school.com.cn/">W3School</a></li>
  86. <li class="divider"></li>
  87. <li><a href="https://github.com/tesseract-ocr/tesseract">tesseract-ocr</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div><!-- /.navbar-collapse -->
  92. </div><!-- /.container-fluid -->
  93. </nav>
  94. <?php
  95. $file_path = $_GET['file_name'];
  96. $lan_type = $_GET['lan_type'];
  97. require '../vendor/autoload.php';
  98. $ocr = new \TesseractOCR($file_path);
  99. $string = $ocr ->lang($lan_type) ->run();
  100. ?>
  101. <div class = "image">
  102. <p>
  103. <img src=<?php echo $file_path;?>
  104. width="440" height="600" />
  105. </p>
  106. </div>
  107. <div class = "retext" style ="width :588px">
  108. <p>识别结果:</p>
  109. <textarea class="form-control" rows="25"><?php echo $string; ?></textarea>
  110. </div>
  111. </body>
  112. </html>





声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/620090
推荐阅读
相关标签
  

闽ICP备14008679号