changed logic in ocr
This commit is contained in:
@@ -39,21 +39,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
</script> --}}
|
||||
|
||||
|
||||
|
||||
<div x-data="cameraCapture()" x-init="initCamera()" class="space-y-2">
|
||||
<video x-ref="video" width="320" height="240" autoplay playsinline class="border rounded"></video>
|
||||
<canvas x-ref="canvas" width="320" height="240" class="hidden"></canvas>
|
||||
<img x-ref="snapshot" class="hidden border rounded max-w-full">
|
||||
|
||||
<div class="flex space-x-4 mt-2">
|
||||
<x-filament::button color="primary" @click="capturePhoto" x-show="!photoTaken">Capture</x-filament::button>
|
||||
<x-filament::button color="secondary" @click="retakePhoto" x-show="photoTaken">Retake</x-filament::button>
|
||||
<x-filament::button color="gray" @click="switchCamera" x-show="!photoTaken">Switch Camera</x-filament::button>
|
||||
</div>
|
||||
<x-filament::button color="primary" @click="capturePhoto" x-show="!photoTaken">Capture</x-filament::button>
|
||||
<x-filament::button color="secondary" @click="retakePhoto" x-show="photoTaken">Retake</x-filament::button>
|
||||
<x-filament::button color="gray" @click="switchCamera" x-show="!photoTaken">Switch Camera</x-filament::button>
|
||||
</div>
|
||||
|
||||
{{-- <input type="hidden" name="{{ $getName() }}" x-ref="hiddenInput"> --}}
|
||||
<input type="hidden" name="photo_data" x-ref="hiddenInput">
|
||||
|
||||
<input type="hidden" name="{{ $getName() }}" x-ref="hiddenInput">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
@@ -62,7 +60,6 @@ function cameraCapture() {
|
||||
stream: null,
|
||||
currentFacingMode: 'user', // 'user' = front, 'environment' = back
|
||||
photoTaken: false,
|
||||
recognizedText: '',
|
||||
|
||||
async initCamera() {
|
||||
try {
|
||||
@@ -107,20 +104,6 @@ function cameraCapture() {
|
||||
this.$refs.hiddenInput.value = dataUrl;
|
||||
},
|
||||
|
||||
async verifyPhoto() {
|
||||
this.recognizedText = 'Processing...';
|
||||
|
||||
const snapshot = this.$refs.snapshot;
|
||||
|
||||
try {
|
||||
const result = await Tesseract.recognize(snapshot.src, 'eng');
|
||||
this.recognizedText = result.data.text.trim();
|
||||
} catch (err) {
|
||||
console.error('OCR Error:', err);
|
||||
this.recognizedText = 'Error reading text from image.';
|
||||
}
|
||||
},
|
||||
|
||||
async retakePhoto() {
|
||||
this.photoTaken = false;
|
||||
this.$refs.snapshot.classList.add('hidden');
|
||||
|
||||
Reference in New Issue
Block a user