changed logic in ocr
This commit is contained in:
@@ -86,27 +86,58 @@ function cameraCapture() {
|
|||||||
await this.initCamera();
|
await this.initCamera();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// capturePhoto() {
|
||||||
|
// const video = this.$refs.video;
|
||||||
|
// const canvas = this.$refs.canvas;
|
||||||
|
// const snapshot = this.$refs.snapshot;
|
||||||
|
// const context = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||||
|
// const dataUrl = canvas.toDataURL('image/png');
|
||||||
|
|
||||||
|
// // stop camera stream after capture
|
||||||
|
// if (this.stream) {
|
||||||
|
// this.stream.getTracks().forEach(track => track.stop());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// snapshot.src = dataUrl;
|
||||||
|
// snapshot.classList.remove('hidden');
|
||||||
|
// this.photoTaken = true;
|
||||||
|
|
||||||
|
// // this.$refs.hiddenInput.value = dataUrl;
|
||||||
|
// @this.set('photo1', dataUrl);
|
||||||
|
// },
|
||||||
capturePhoto() {
|
capturePhoto() {
|
||||||
const video = this.$refs.video;
|
const video = this.$refs.video;
|
||||||
const canvas = this.$refs.canvas;
|
const canvas = this.$refs.canvas;
|
||||||
const snapshot = this.$refs.snapshot;
|
const snapshot = this.$refs.snapshot;
|
||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
|
|
||||||
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
// Draw current video frame to canvas
|
||||||
const dataUrl = canvas.toDataURL('image/png');
|
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// stop camera stream after capture
|
// Get base64 image
|
||||||
if (this.stream) {
|
const dataUrl = canvas.toDataURL('image/png');
|
||||||
this.stream.getTracks().forEach(track => track.stop());
|
|
||||||
}
|
|
||||||
|
|
||||||
snapshot.src = dataUrl;
|
// Show captured image
|
||||||
snapshot.classList.remove('hidden');
|
snapshot.src = dataUrl;
|
||||||
this.photoTaken = true;
|
snapshot.classList.remove('hidden');
|
||||||
|
|
||||||
|
// Hide video so snapshot is visible
|
||||||
|
video.classList.add('hidden');
|
||||||
|
|
||||||
|
// Stop the camera stream AFTER snapshot is captured
|
||||||
|
if (this.stream) {
|
||||||
|
this.stream.getTracks().forEach(track => track.stop());
|
||||||
|
this.stream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.photoTaken = true;
|
||||||
|
|
||||||
|
// Update Livewire property
|
||||||
|
@this.set('photo1', dataUrl);
|
||||||
|
}
|
||||||
|
|
||||||
// this.$refs.hiddenInput.value = dataUrl;
|
|
||||||
@this.set('photo1', dataUrl);
|
|
||||||
},
|
|
||||||
|
|
||||||
async retakePhoto() {
|
async retakePhoto() {
|
||||||
this.photoTaken = false;
|
this.photoTaken = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user