Added logic in ocr for config
This commit is contained in:
@@ -48,10 +48,15 @@ use thiagoalessio\TesseractOCR\TesseractOCR;
|
|||||||
$text = (new TesseractOCR($filePath))
|
$text = (new TesseractOCR($filePath))
|
||||||
->executable('/usr/bin/tesseract')
|
->executable('/usr/bin/tesseract')
|
||||||
->lang('eng')
|
->lang('eng')
|
||||||
->psm(6)
|
->psm(6) // treats the image as a block of text
|
||||||
|
->config(['tessedit_char_whitelist' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'])
|
||||||
->run();
|
->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) {
|
//catch (\Exception $e) {
|
||||||
// return response()->json(['success' => false, 'error' => $e->getMessage()]);
|
// return response()->json(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
|||||||
Reference in New Issue
Block a user