From cefac4e8f3be3d5568c18f04243bfa8948bb2ddc Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 27 Oct 2025 11:10:15 +0530 Subject: [PATCH] Added logic of init camera in ocr --- .../views/fields/camera-capture.blade.php | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/resources/views/fields/camera-capture.blade.php b/resources/views/fields/camera-capture.blade.php index 8e8db24..81b87a9 100644 --- a/resources/views/fields/camera-capture.blade.php +++ b/resources/views/fields/camera-capture.blade.php @@ -756,32 +756,49 @@ function cameraCapture() { capturedPhoto: null, // store captured image serialNumbers: [], + // async initCamera() { + // try { + // if (this.stream) this.stream.getTracks().forEach(track => track.stop()); + + // const video = this.$refs.video; + // this.stream = await navigator.mediaDevices.getUserMedia({ + // video: { facingMode: this.currentFacingMode } + // }); + + // video.srcObject = this.stream; + // await new Promise(resolve => video.onloadedmetadata = resolve); + // video.play(); + + // // Overlay size matches video + // const overlay = this.$refs.overlay; + // overlay.width = video.videoWidth; + // overlay.height = video.videoHeight; + + // this.startDetection(); + // } catch (err) { + // console.error("Camera error:", err); + // alert("Camera error:\n" + (err.message || err)); + // this.stopDetection(); + // } + // }, + async initCamera() { try { if (this.stream) this.stream.getTracks().forEach(track => track.stop()); - const video = this.$refs.video; this.stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: this.currentFacingMode } }); - video.srcObject = this.stream; - await new Promise(resolve => video.onloadedmetadata = resolve); - video.play(); - - // Overlay size matches video - const overlay = this.$refs.overlay; - overlay.width = video.videoWidth; - overlay.height = video.videoHeight; - + this.$refs.video.srcObject = this.stream; this.startDetection(); } catch (err) { console.error("Camera error:", err); - alert("Camera error:\n" + (err.message || err)); - this.stopDetection(); + alert("Cannot access camera. Enable permissions or use HTTPS."); } }, + async switchCamera() { this.currentFacingMode = this.currentFacingMode === 'user' ? 'environment' : 'user'; await this.initCamera();