changed logic for detect text
This commit is contained in:
@@ -517,37 +517,38 @@ function cameraCapture() {
|
|||||||
|
|
||||||
if (!video.videoWidth) return;
|
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");
|
const tempCanvas = document.createElement("canvas");
|
||||||
tempCanvas.width = video.videoWidth;
|
tempCanvas.width = video.videoWidth;
|
||||||
tempCanvas.height = video.videoHeight;
|
tempCanvas.height = video.videoHeight;
|
||||||
const tempCtx = tempCanvas.getContext("2d");
|
const tempCtx = tempCanvas.getContext("2d");
|
||||||
tempCtx.drawImage(video, 0, 0);
|
tempCtx.drawImage(video, 0, 0);
|
||||||
|
|
||||||
const result = await Tesseract.recognize(
|
// Use Tesseract worker for better performance
|
||||||
tempCanvas.toDataURL(),
|
if (!this.worker) {
|
||||||
"eng",
|
this.worker = Tesseract.createWorker({
|
||||||
{
|
logger: m => console.log(m)
|
||||||
logger: m => console.log(m),
|
});
|
||||||
tessedit_char_whitelist: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
await this.worker.load();
|
||||||
|
await this.worker.loadLanguage('eng');
|
||||||
|
await this.worker.initialize('eng');
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
const words = result.data.words;
|
const { data: { words } } = await this.worker.recognize(tempCanvas);
|
||||||
ctx.clearRect(0, 0, overlay.width, overlay.height);
|
|
||||||
|
|
||||||
ctx.strokeStyle = "lime";
|
ctx.strokeStyle = "lime";
|
||||||
ctx.lineWidth = 3;
|
ctx.lineWidth = 2;
|
||||||
|
|
||||||
words.forEach(w => {
|
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;
|
const { x0, y0, x1, y1 } = w.bbox;
|
||||||
ctx.strokeRect(x0, y0, x1 - x0, y1 - y0);
|
ctx.strokeRect(x0, y0, x1 - x0, y1 - y0);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// startDetection() {
|
|
||||||
// setInterval(() => this.detectText(), 700);
|
|
||||||
// },
|
|
||||||
startDetection() {
|
startDetection() {
|
||||||
if (this.textDetectionInterval) {
|
if (this.textDetectionInterval) {
|
||||||
clearInterval(this.textDetectionInterval);
|
clearInterval(this.textDetectionInterval);
|
||||||
|
|||||||
Reference in New Issue
Block a user