From a25e3ccdbfaef96dfa3ce1fc06c03cad097c0523 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 23 Oct 2025 15:17:00 +0530 Subject: [PATCH] Added logic in ocr for config --- routes/web.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index 2766a27..9041c4f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,10 +48,15 @@ use thiagoalessio\TesseractOCR\TesseractOCR; $text = (new TesseractOCR($filePath)) ->executable('/usr/bin/tesseract') ->lang('eng') - ->psm(6) + ->psm(6) // treats the image as a block of text + ->config(['tessedit_char_whitelist' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz']) ->run(); - return response()->json(['success' => true, 'text' => $text]); + //return response()->json(['success' => true, 'text' => $text]); + $lines = preg_split('/\r\n|\r|\n/', $text); + $serials = array_filter(array_map('trim', $lines), fn($line) => preg_match('/^[A-Z0-9]+$/', $line)); + + return response()->json(['success' => true, 'text' => $serials]); } //catch (\Exception $e) { // return response()->json(['success' => false, 'error' => $e->getMessage()]);