feat: scan
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Ocr;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
class TesseractOcrDriver implements OcrDriver
|
||||
{
|
||||
public function recognize(string $imagePath): string
|
||||
{
|
||||
if (! is_file($imagePath)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$bin = (string) config('coruna.ocr.tesseract', 'tesseract');
|
||||
$langs = (string) config('coruna.ocr.langs', 'eng+chi_sim');
|
||||
$result = Process::timeout(90)->run([
|
||||
$bin,
|
||||
$imagePath,
|
||||
'stdout',
|
||||
'-l', $langs,
|
||||
'--psm', '6',
|
||||
]);
|
||||
|
||||
if (! $result->successful()) {
|
||||
Log::channel('stack')->warning('tesseract ocr failed', [
|
||||
'path' => $imagePath,
|
||||
'error' => mb_substr($result->errorOutput() ?: $result->output(), 0, 500),
|
||||
]);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
return trim($result->output());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user