changed logic in ocr fro automatical verify
This commit is contained in:
@@ -288,14 +288,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
<input type="hidden" x-ref="hiddenInput" x-model="photo1" name="camera_capture_file">
|
<input type="hidden" x-ref="hiddenInput" x-model="photo1" name="camera_capture_file">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Latest Tesseract.js from CDN -->
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function cameraCapture() {
|
function cameraCapture() {
|
||||||
return {
|
return {
|
||||||
stream: null,
|
stream: null,
|
||||||
|
currentFacingMode: 'user',
|
||||||
photoTaken: false,
|
photoTaken: false,
|
||||||
photo1: '',
|
photo1: '',
|
||||||
|
|
||||||
|
|
||||||
async initCamera() {
|
async initCamera() {
|
||||||
try {
|
try {
|
||||||
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
||||||
@@ -354,34 +358,62 @@ function cameraCapture() {
|
|||||||
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
||||||
},
|
},
|
||||||
|
|
||||||
// retakePhoto() {
|
|
||||||
// this.photoTaken = false;
|
|
||||||
// this.initCamera();
|
|
||||||
// }
|
|
||||||
|
|
||||||
async verifyOCR(dataUrl) {
|
// async verifyOCR(dataUrl) {
|
||||||
try {
|
// try {
|
||||||
const { data: { text } } = await Tesseract.recognize(
|
// const { data: { text } } = await Tesseract.recognize(
|
||||||
dataUrl,
|
// dataUrl,
|
||||||
'eng',
|
// 'eng',
|
||||||
{ logger: m => console.log(m) }
|
// { logger: m => console.log(m) }
|
||||||
);
|
// );
|
||||||
alert("OCR Result: " + text);
|
// alert("OCR Result: " + text);
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
console.error(err);
|
// console.error(err);
|
||||||
alert("OCR Failed: " + err.message);
|
// alert("OCR Failed: " + err.message);
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
|
|
||||||
|
// async verify() {
|
||||||
|
// const dataUrl = this.$refs.hiddenInput.value;
|
||||||
|
// if (!dataUrl) {
|
||||||
|
// alert("No captured image found!");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// await this.verifyOCR(dataUrl);
|
||||||
|
// },
|
||||||
|
|
||||||
async verify() {
|
async verify() {
|
||||||
const dataUrl = this.$refs.hiddenInput.value;
|
const filePath = this.$refs.hiddenInput.value; // e.g., "temp/capture_1760764396.jpeg"
|
||||||
if (!dataUrl) {
|
|
||||||
|
if (!filePath) {
|
||||||
alert("No captured image found!");
|
alert("No captured image found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.verifyOCR(dataUrl);
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/verify-ocr', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ path: filePath })
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
alert("OCR Result: " + data.text);
|
||||||
|
} else {
|
||||||
|
alert("OCR Failed: " + data.error);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
alert("OCR request failed: " + err.message);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
async retakePhoto() {
|
async retakePhoto() {
|
||||||
this.photoTaken = false;
|
this.photoTaken = false;
|
||||||
this.$refs.snapshot.classList.add('hidden');
|
this.$refs.snapshot.classList.add('hidden');
|
||||||
|
|||||||
Reference in New Issue
Block a user