added retake photo functionality and improved capture logic in camera capture component

This commit is contained in:
dhanabalan
2025-10-27 16:24:05 +05:30
parent 39eedf1fe9
commit a9421963a7

View File

@@ -734,17 +734,13 @@ function cameraCapture() {
<x-filament::button color="primary" @click="switchCamera">Switch Camera</x-filament::button> <x-filament::button color="primary" @click="switchCamera">Switch Camera</x-filament::button>
<x-filament::button color="success" @click="capturePhoto">Capture Photo</x-filament::button> <x-filament::button color="success" @click="capturePhoto">Capture Photo</x-filament::button>
<x-filament::button color="warning" @click="verifyPhoto">Verify</x-filament::button> <x-filament::button color="warning" @click="verifyPhoto">Verify</x-filament::button>
<x-filament::button color="primary" @click="retakePhoto">Retake</x-filament::button>
</div> </div>
<input type="hidden" x-ref="hiddenInput" name="camera_capture_file"> <input type="hidden" x-ref="hiddenInput" name="camera_capture_file">
{{-- <input type="hidden" x-ref="serialInput" name="serialNumbers"> --}} {{-- <input type="hidden" x-ref="serialInput" name="serialNumbers"> --}}
{{-- <input type="hidden" x-model="serialNumbers" name="serialNumbers"> --}} {{-- <input type="hidden" x-model="serialNumbers" name="serialNumbers"> --}}
<input type="hidden" x-model="serialNumbers" name="serialNumbers"> <input type="hidden" x-model="serialNumbers" name="serialNumbers">
</div> </div>
<!-- Scripts --> <!-- Scripts -->
@@ -825,36 +821,35 @@ function cameraCapture() {
// this.stopDetection(); // this.stopDetection();
// }, // },
async capturePhoto() { async capturePhoto() {
const video = this.$refs.video; const video = this.$refs.video;
const canvas = this.$refs.canvas; const canvas = this.$refs.canvas;
const overlay = this.$refs.overlay; const overlay = this.$refs.overlay;
const snapshot = this.$refs.snapshot; // ✅ Fix: define snapshot reference const snapshot = this.$refs.snapshot; // ✅ Fix: define snapshot reference
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
canvas.width = video.videoWidth; canvas.width = video.videoWidth;
canvas.height = video.videoHeight; canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0); ctx.drawImage(video, 0, 0);
const snapshotData = canvas.toDataURL('image/png'); // ✅ Correct data var const snapshotData = canvas.toDataURL('image/png'); // ✅ Correct data var
this.$refs.hiddenInput.value = snapshotData; this.$refs.hiddenInput.value = snapshotData;
this.capturedPhoto = snapshotData; this.capturedPhoto = snapshotData;
// ✅ Stop camera // ✅ Stop camera
if (this.stream) this.stream.getTracks().forEach(track => track.stop()); if (this.stream) this.stream.getTracks().forEach(track => track.stop());
// ✅ Hide video + overlay // ✅ Hide video + overlay
video.classList.add('hidden'); video.classList.add('hidden');
overlay.classList.add('hidden'); overlay.classList.add('hidden');
// ✅ Show captured image // ✅ Show captured image
snapshot.src = snapshotData; // ✅ Correct variable snapshot.src = snapshotData; // ✅ Correct variable
snapshot.classList.remove('hidden'); snapshot.classList.remove('hidden');
alert("Photo captured!"); alert("Photo captured!");
this.stopDetection(); this.stopDetection();
}, },
async verifyPhoto() { async verifyPhoto() {
if (!this.capturedPhoto) { if (!this.capturedPhoto) {
@@ -885,7 +880,6 @@ function cameraCapture() {
//this.$refs.serialInput.value = JSON.stringify(this.serialNumbers); //this.$refs.serialInput.value = JSON.stringify(this.serialNumbers);
alert("Serial numbers stored in hidden input:\n" + this.$refs.serialInput.value); alert("Serial numbers stored in hidden input:\n" + this.$refs.serialInput.value);
} }
} catch (err) { } catch (err) {
console.error("OCR verify error:", err); console.error("OCR verify error:", err);
@@ -924,6 +918,14 @@ function cameraCapture() {
} }
}, },
async retakePhoto() {
this.photoTaken = false;
this.$refs.snapshot.classList.add('hidden');
this.$refs.video.classList.remove('hidden');
await this.initCamera();
},
startDetection() { startDetection() {
if (this.textDetectionInterval) clearInterval(this.textDetectionInterval); if (this.textDetectionInterval) clearInterval(this.textDetectionInterval);
this.textDetectionInterval = setInterval(() => this.detectText(), 1000); this.textDetectionInterval = setInterval(() => this.detectText(), 1000);
@@ -946,3 +948,6 @@ function cameraCapture() {