change dlogic in ocr for verify
This commit is contained in:
@@ -754,6 +754,9 @@ function cameraCapture() {
|
|||||||
|
|
||||||
async initCamera() {
|
async initCamera() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
await this.initWorker();
|
||||||
|
|
||||||
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
||||||
|
|
||||||
const video = this.$refs.video;
|
const video = this.$refs.video;
|
||||||
@@ -778,6 +781,18 @@ function cameraCapture() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async initWorker() {
|
||||||
|
if (this.ocrWorker) return;
|
||||||
|
|
||||||
|
// ✅ Create and load OCR worker once
|
||||||
|
this.ocrWorker = await Tesseract.createWorker('eng');
|
||||||
|
await this.ocrWorker.loadLanguage('eng');
|
||||||
|
await this.ocrWorker.initialize('eng');
|
||||||
|
this.isWorkerReady = true;
|
||||||
|
|
||||||
|
console.log("✅ OCR Worker Ready");
|
||||||
|
},
|
||||||
|
|
||||||
async switchCamera() {
|
async switchCamera() {
|
||||||
this.currentFacingMode = this.currentFacingMode === 'user' ? 'environment' : 'user';
|
this.currentFacingMode = this.currentFacingMode === 'user' ? 'environment' : 'user';
|
||||||
await this.initCamera();
|
await this.initCamera();
|
||||||
@@ -854,6 +869,11 @@ function cameraCapture() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.isWorkerReady) {
|
||||||
|
alert("OCR worker not ready yet!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = this.capturedPhoto;
|
img.src = this.capturedPhoto;
|
||||||
@@ -865,9 +885,15 @@ function cameraCapture() {
|
|||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.drawImage(img, 0, 0);
|
ctx.drawImage(img, 0, 0);
|
||||||
|
|
||||||
const result = await Tesseract.recognize(canvas, 'eng', {
|
// const result = await Tesseract.recognize(canvas, 'eng', {
|
||||||
logger: m => console.log(m)
|
// logger: m => console.log(m)
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
// const result = await Tesseract.recognize(canvas, 'eng', {
|
||||||
|
// logger: m => console.log(m.status, m.progress)
|
||||||
|
// });
|
||||||
|
|
||||||
|
const result = await this.ocrWorker.recognize(img);
|
||||||
|
|
||||||
const detectedText = result.data.text.trim();
|
const detectedText = result.data.text.trim();
|
||||||
// const matches = detectedText.match(/\d+/g) || [];
|
// const matches = detectedText.match(/\d+/g) || [];
|
||||||
@@ -964,7 +990,7 @@ function cameraCapture() {
|
|||||||
|
|
||||||
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(), 700);
|
||||||
},
|
},
|
||||||
|
|
||||||
stopDetection() {
|
stopDetection() {
|
||||||
|
|||||||
Reference in New Issue
Block a user