Mac“XAMPP”上的 Tesseract 问题

问题描述 投票:0回答:1

我已经在 mac (ventura) 上安装了 tesseract。当我在终端中运行它时,它工作正常。当我使用位于的 apache2 服务器运行 html php 代码时

'/usr/local/' 
路径 有用。我不确定其中的一个
'/private/'
路径,如果有意义的话。

当我尝试在 xampp 上运行 tesseract 时出现问题!

在 mac 上我首先收到错误:

Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract The current $PATH is /usr/bin:/bin:/usr/sbin:/sbin

如果我更改执行路径,我会收到以下错误:

[01-Mar-2024 14:33:41 Europe/Berlin] PHP Fatal error:  Uncaught thiagoalessio\TesseractOCR\UnsuccessfulCommandException: Error! The command did not produce any output.

Generated command:
"/usr/local/Cellar/tesseract/5.3.4_1/bin/tesseract" "uploads/test.png" "/var/folders/ct/4574d7l95d71vhc0bf_mj7rr0000gn/T/" -c "tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZ" -l eng

Returned message:
dyld[2171]: Symbol not found: _WebPMalloc
  Referenced from: <405E0AB2-EB03-3BCF-BA09-6CAFB225680E> /usr/local/Cellar/webp/1.3.2/lib/libwebpmux.3.0.13.dylib
  Expected in:     <4D95CAC6-C8B4-39C0-9B98-B286ABEB684E> /Applications/XAMPP/xamppfiles/lib/libwebp.7.dylib in /Applications/XAMPP/xamppfiles/htdocs/texte/vendor/thiagoalessio/tesseract_ocr/src/FriendlyErrors.php:66

我的猜测是,它与 (1) php xampp 执行命令有关,因为我也尝试过在 php 中执行 tesseract 命令,但没有任何效果。或者,(2)环境路径 - 我不确定它是如何工作的,所以我无法正确解释它。

我使用的代码是:

<?php
$fileRead = '';
use thiagoalessio\TesseractOCR\TesseractOCR;

require 'vendor/autoload.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['submit'])) {
        $file_name = $_FILES['file']['name'];
        $tmp_file = $_FILES['file']['tmp_name'];


        if (!session_id()) {
            session_start();
            $unq = session_id();
        }

        $file_name = uniqid() . '_' . time() . '_' . str_replace(array('!', "@", '#', '$', '%', '^', '&', ' ', '*', '(', ')', ':', ';', ',', '?', '/' . '\\', '~', '`', '-'), '_', strtolower($file_name));

        if (move_uploaded_file($tmp_file, 'uploads/' . $file_name)) {
            try {
    
                $fileRead = (new TesseractOCR('uploads/' . $file_name))
                    ->setLanguage('eng')
                    ->run();
    
            } catch (Exception $e) {
    
                echo $e->getMessage();
    
            }
        } else {
            echo "<p class='alert alert-danger'>File failed to upload.</p>";
        }

    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document Reader</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
    <div class="container mt-5">
        <div class="row mt-5">
            <div class="col-sm-8 mx-auto">
                <div class="jumbotron">
                    <h1 class="display-4">Read Text from Images</h1>
                    <p class="lead">


                        <?php if ($_POST) : ?>
                            <pre>
                                <?= $fileRead ?>
                            </pre>
                        <?php endif; ?>


                </p>
                <hr class="my-4">
                </div>
            </div>
        </div>
        <div class="row col-sm-8 mx-auto">
            <div class="card mt-5">
                <div class="card-body">


                    <form action="" method="post" enctype="multipart/form-data">
                        <div class="form-group">

                            <label for="filechoose">Choose File</label>

                            <input type="file" name="file" class="form-control-file" id="filechoose">

                            <button class="btn btn-success mt-3" type="submit" name="submit">Upload</button>

                        </div>
                    </form>


                </div>
            </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
</body>
</html>
php macos xampp apache2 tesseract
1个回答
0
投票

我不熟悉 php,但是

Error! The command "tesseract" was not found
这意味着 tesseract 不在您的脚本可用/可访问的
PATH
中。

看看提供Tesseract功能的php库的配置,是否可以定义Tesseract的绝对路径。或者调整负责的环境/php 变量,以便您可以在脚本中使用 tesseract 安装。

© www.soinside.com 2019 - 2024. All rights reserved.