modified logic in ocr

This commit is contained in:
dhanabalan
2025-10-23 15:37:11 +05:30
parent b71fe09498
commit 21c73c4744
2 changed files with 41 additions and 73 deletions

View File

@@ -49,18 +49,14 @@ use thiagoalessio\TesseractOCR\TesseractOCR;
->executable('/usr/bin/tesseract')
->lang('eng')
->psm(6) // treats the image as a block of text
//->config(['tessedit_char_whitelist' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'])
->config(['tessedit_char_whitelist' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'])
->run();
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' => $text]);
$lines = preg_split('/\r\n|\r|\n/', $text);
$serials = array_filter(array_map('trim', $lines), fn($line) => preg_match('/^[A-Z0-9]+$/i', $line));
//return response()->json(['success' => true, 'text' => $serials]);
// return response()->json([
// 'success' => true,
// 'text' => array_values($serials), // send as array
// ]);
return response()->json(['success' => true, 'text' => array_values($serials)]);
}
//catch (\Exception $e) {
// return response()->json(['success' => false, 'error' => $e->getMessage()]);