commented ocr veify in filament
This commit is contained in:
@@ -30,6 +30,9 @@ class OcrValidationResource extends Resource
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public $camera_capture;
|
||||
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
@@ -70,10 +73,20 @@ class OcrValidationResource extends Resource
|
||||
->helperText('You can take a picture from your webcam')
|
||||
->reactive(),
|
||||
|
||||
Forms\Components\TextInput::make('photo1')
|
||||
->label('Captured Photo')
|
||||
->hidden()
|
||||
->extraAttributes(['x-ref' => 'hiddenInput']),
|
||||
// Forms\Components\TextInput::make('camera_capture')
|
||||
// ->label('Captured Photo')
|
||||
// ->hidden()
|
||||
// ->extraAttributes([
|
||||
// 'x-ref' => 'hiddenInput', // so Alpine can target it
|
||||
// ]),
|
||||
|
||||
Forms\Components\TextInput::make('camera_capture_file')
|
||||
->label('Captured Photo')
|
||||
->reactive()
|
||||
->hidden()
|
||||
->extraAttributes([
|
||||
'x-ref' => 'hiddenInput', // so Alpine can reference it
|
||||
]),
|
||||
Forms\Components\Actions::make([
|
||||
Action::make('uploadNow1')
|
||||
->label('Upload OCR')
|
||||
@@ -203,56 +216,59 @@ class OcrValidationResource extends Resource
|
||||
}
|
||||
}),
|
||||
|
||||
Action::make('verifyOcr')
|
||||
->label('Verify OCR')
|
||||
->action(function ($get) {
|
||||
$base64Image = $get('photo1');
|
||||
// Action::make('verifyOcr')
|
||||
// ->label('Verify OCR')
|
||||
// ->action(function ($get) {
|
||||
// $base64Image = $get('camera_capture_file');
|
||||
// // $fileName = 'capture_1760680702.png';
|
||||
|
||||
if (!$base64Image) {
|
||||
Notification::make()
|
||||
->title('No captured image found')
|
||||
->warning()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
// // //dd($base64Image);
|
||||
// if (!$base64Image) {
|
||||
// Notification::make()
|
||||
// ->title('No captured image found')
|
||||
// ->warning()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Decode and store the base64 image
|
||||
$image = str_replace('data:image/jpeg;base64,', '', $base64Image);
|
||||
$image = str_replace(' ', '+', $image);
|
||||
// // Decode and store the base64 image
|
||||
// $image = str_replace('data:image/jpeg;base64,', '', $base64Image);
|
||||
// $image = str_replace(' ', '+', $image);
|
||||
|
||||
$grNumber = $get('gr_number') ?: 'Unknown';
|
||||
$safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
|
||||
$fileName = $safeName . '.jpg';
|
||||
$filePath = storage_path("app/private/uploads/OCR/{$fileName}");
|
||||
// $grNumber = $get('gr_number') ?: 'Unknown';
|
||||
// $safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
|
||||
// $fileName = $safeName . '.jpg';
|
||||
// $filePath = storage_path("app/private/uploads/OCR/{$fileName}");
|
||||
|
||||
if (!file_exists(dirname($filePath))) {
|
||||
mkdir(dirname($filePath), 0777, true);
|
||||
}
|
||||
// if (!file_exists(dirname($filePath))) {
|
||||
// mkdir(dirname($filePath), 0777, true);
|
||||
// }
|
||||
|
||||
file_put_contents($filePath, base64_decode($image));
|
||||
// file_put_contents($filePath, base64_decode($image));
|
||||
|
||||
// 🧠 Run OCR
|
||||
$text = (new TesseractOCR($filePath))
|
||||
->lang('eng')
|
||||
->run();
|
||||
// // 🧠 Run OCR
|
||||
// $text = (new TesseractOCR($filePath))
|
||||
// ->lang('eng')
|
||||
// ->run();
|
||||
|
||||
preg_match_all('/\d+/', $text, $matches);
|
||||
$serialNumbers = array_slice($matches[0], 0, 4);
|
||||
// preg_match_all('/\d+/', $text, $matches);
|
||||
// $serialNumbers = array_slice($matches[0], 0, 4);
|
||||
|
||||
if (empty($serialNumbers)) {
|
||||
Notification::make()
|
||||
->title('No numbers found in image')
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
// if (empty($serialNumbers)) {
|
||||
// Notification::make()
|
||||
// ->title('No numbers found in image')
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
Notification::make()
|
||||
->title('OCR Read Successfully')
|
||||
->body('Serial Numbers: ' . implode(', ', $serialNumbers))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
// Notification::make()
|
||||
// ->title('OCR Read Successfully')
|
||||
// ->body('Serial Numbers: ' . implode(', ', $serialNumbers))
|
||||
// ->success()
|
||||
// ->send();
|
||||
|
||||
// }),
|
||||
|
||||
Action::make('downloadAttachment')
|
||||
->label('Download PDF')
|
||||
|
||||
Reference in New Issue
Block a user