Added logic in ocr for lens
This commit is contained in:
@@ -307,6 +307,7 @@ function cameraCapture() {
|
|||||||
currentFacingMode: 'user',
|
currentFacingMode: 'user',
|
||||||
photoTaken: false,
|
photoTaken: false,
|
||||||
photo1: '',
|
photo1: '',
|
||||||
|
textDetectionInterval: null,
|
||||||
|
|
||||||
|
|
||||||
async initCamera() {
|
async initCamera() {
|
||||||
@@ -318,7 +319,14 @@ function cameraCapture() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$refs.video.srcObject = this.stream;
|
this.$refs.video.srcObject = this.stream;
|
||||||
this.startDetection();
|
await video.play(); // ✅ ensure camera actually starts
|
||||||
|
|
||||||
|
const overlay = this.$refs.overlay;
|
||||||
|
overlay.width = video.videoWidth;
|
||||||
|
overlay.height = video.videoHeight;
|
||||||
|
|
||||||
|
setTimeout(() => this.startDetection(), 300);
|
||||||
|
//this.startDetection();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Camera error:", err);
|
console.error("Camera error:", err);
|
||||||
alert("Cannot access camera. Enable permissions or use HTTPS.");
|
alert("Cannot access camera. Enable permissions or use HTTPS.");
|
||||||
@@ -498,14 +506,13 @@ function cameraCapture() {
|
|||||||
const overlay = this.$refs.overlay;
|
const overlay = this.$refs.overlay;
|
||||||
const ctx = overlay.getContext("2d");
|
const ctx = overlay.getContext("2d");
|
||||||
|
|
||||||
// Draw video frame to temp canvas
|
// Temp image from video
|
||||||
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);
|
||||||
|
|
||||||
// OCR detection
|
|
||||||
const { data: { words } } = await Tesseract.recognize(
|
const { data: { words } } = await Tesseract.recognize(
|
||||||
tempCanvas.toDataURL(),
|
tempCanvas.toDataURL(),
|
||||||
"eng"
|
"eng"
|
||||||
@@ -513,8 +520,8 @@ function cameraCapture() {
|
|||||||
|
|
||||||
ctx.clearRect(0, 0, overlay.width, overlay.height);
|
ctx.clearRect(0, 0, overlay.width, overlay.height);
|
||||||
|
|
||||||
ctx.strokeStyle = "red";
|
ctx.strokeStyle = "lime";
|
||||||
ctx.lineWidth = 2;
|
ctx.lineWidth = 3;
|
||||||
|
|
||||||
words.forEach(word => {
|
words.forEach(word => {
|
||||||
if (word.bbox) {
|
if (word.bbox) {
|
||||||
@@ -523,12 +530,16 @@ function cameraCapture() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// startDetection() {
|
||||||
|
// setInterval(() => this.detectText(), 700);
|
||||||
|
// },
|
||||||
startDetection() {
|
startDetection() {
|
||||||
setInterval(() => this.detectText(), 700);
|
if (this.textDetectionInterval) {
|
||||||
|
clearInterval(this.textDetectionInterval);
|
||||||
|
}
|
||||||
|
this.textDetectionInterval = setInterval(() => this.detectText(), 500);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Initialize camera and detection
|
// Initialize camera and detection
|
||||||
async init() {
|
async init() {
|
||||||
await this.initCamera();
|
await this.initCamera();
|
||||||
|
|||||||
Reference in New Issue
Block a user