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">
|
||||
|
||||
</div>
|
||||
<!-- Latest Tesseract.js from CDN -->
|
||||
|
||||
|
||||
<script>
|
||||
function cameraCapture() {
|
||||
return {
|
||||
stream: null,
|
||||
currentFacingMode: 'user',
|
||||
photoTaken: false,
|
||||
photo1: '',
|
||||
|
||||
|
||||
async initCamera() {
|
||||
try {
|
||||
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
||||
@@ -354,33 +358,61 @@ function cameraCapture() {
|
||||
if (this.stream) this.stream.getTracks().forEach(track => track.stop());
|
||||
},
|
||||
|
||||
// retakePhoto() {
|
||||
// this.photoTaken = false;
|
||||
// this.initCamera();
|
||||
// }
|
||||
|
||||
async verifyOCR(dataUrl) {
|
||||
try {
|
||||
const { data: { text } } = await Tesseract.recognize(
|
||||
dataUrl,
|
||||
'eng',
|
||||
{ logger: m => console.log(m) }
|
||||
);
|
||||
alert("OCR Result: " + text);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert("OCR Failed: " + err.message);
|
||||
}
|
||||
},
|
||||
// async verifyOCR(dataUrl) {
|
||||
// try {
|
||||
// const { data: { text } } = await Tesseract.recognize(
|
||||
// dataUrl,
|
||||
// 'eng',
|
||||
// { logger: m => console.log(m) }
|
||||
// );
|
||||
// alert("OCR Result: " + text);
|
||||
// } catch (err) {
|
||||
// console.error(err);
|
||||
// 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() {
|
||||
const dataUrl = this.$refs.hiddenInput.value;
|
||||
if (!dataUrl) {
|
||||
const filePath = this.$refs.hiddenInput.value; // e.g., "temp/capture_1760764396.jpeg"
|
||||
|
||||
if (!filePath) {
|
||||
alert("No captured image found!");
|
||||
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() {
|
||||
this.photoTaken = false;
|
||||
|
||||
Reference in New Issue
Block a user