changed logic in ocr
This commit is contained in:
@@ -86,58 +86,27 @@ 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');
|
||||||
|
|
||||||
// Draw current video frame to canvas
|
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||||
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
const dataUrl = canvas.toDataURL('image/png');
|
||||||
|
|
||||||
// Get base64 image
|
// stop camera stream after capture
|
||||||
const dataUrl = canvas.toDataURL('image/png');
|
if (this.stream) {
|
||||||
|
this.stream.getTracks().forEach(track => track.stop());
|
||||||
|
}
|
||||||
|
|
||||||
// Show captured image
|
snapshot.src = dataUrl;
|
||||||
snapshot.src = dataUrl;
|
snapshot.classList.remove('hidden');
|
||||||
snapshot.classList.remove('hidden');
|
this.photoTaken = true;
|
||||||
|
|
||||||
// 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