changed logic for detect text

This commit is contained in:
dhanabalan
2025-10-25 09:02:56 +05:30
parent ffc742914f
commit 2bf73c3ac2

View File

@@ -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);