From 2bf73c3ac2002cc528081df729bbf66b166ed10f Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 25 Oct 2025 09:02:56 +0530 Subject: [PATCH] changed logic for detect text --- .../views/fields/camera-capture.blade.php | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/resources/views/fields/camera-capture.blade.php b/resources/views/fields/camera-capture.blade.php index 7ebf365..2b32ab3 100644 --- a/resources/views/fields/camera-capture.blade.php +++ b/resources/views/fields/camera-capture.blade.php @@ -517,37 +517,38 @@ function cameraCapture() { if (!video.videoWidth) return; + // Clear overlay first + ctx.clearRect(0, 0, overlay.width, overlay.height); + + // Draw current video frame to temp canvas const tempCanvas = document.createElement("canvas"); tempCanvas.width = video.videoWidth; tempCanvas.height = video.videoHeight; const tempCtx = tempCanvas.getContext("2d"); tempCtx.drawImage(video, 0, 0); - const result = await Tesseract.recognize( - tempCanvas.toDataURL(), - "eng", - { - logger: m => console.log(m), - tessedit_char_whitelist: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" - } - ); + // Use Tesseract worker for better performance + if (!this.worker) { + this.worker = Tesseract.createWorker({ + logger: m => console.log(m) + }); + await this.worker.load(); + await this.worker.loadLanguage('eng'); + await this.worker.initialize('eng'); + } - const words = result.data.words; - ctx.clearRect(0, 0, overlay.width, overlay.height); + const { data: { words } } = await this.worker.recognize(tempCanvas); ctx.strokeStyle = "lime"; - ctx.lineWidth = 3; + ctx.lineWidth = 2; words.forEach(w => { - if (!w.bbox || w.confidence < 70) return; // ✅ Ignore low confidence - + if (!w.bbox || w.confidence < 50) return; const { x0, y0, x1, y1 } = w.bbox; ctx.strokeRect(x0, y0, x1 - x0, y1 - y0); }); }, - // startDetection() { - // setInterval(() => this.detectText(), 700); - // }, + startDetection() { if (this.textDetectionInterval) { clearInterval(this.textDetectionInterval);