feat: scan

This commit is contained in:
hashbro
2026-09-12 23:53:53 +08:00
parent e294053285
commit 558912864d
36 changed files with 4165 additions and 15 deletions
+37
View File
@@ -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());
}
}