This commit is contained in:
Ross
2021-11-12 11:51:49 +00:00
parent 7ce07b17e8
commit 9b784db4f1
+80 -58
View File
@@ -374,67 +374,89 @@
});
function ocr(input) {
// Tesseract.recognize(f, "eng",{ logger: m => console.log(m) }
// ).then(({ data: { text } }) => {
// console.log(text);
// l = text.toLowerCase();
// if (l.includes("accesion") || l.includes("number") || l.search(/(REF|RK9|RH8|RA9)\d+/g)) {
// console.log("SHIT", this);
// }
// })
function ocr2(url, input) {
Tesseract.recognize(
url,
'eng',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
l = text.toLowerCase();
$(`img[data-input-id='${input.id}'`).removeClass("image-ident-loading");
console.log(l);
if (l.includes("accesion") || l.includes("number") || l.search(
/(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) {
console.log("Match found ", input);
$(input).addClass("image-ident-warning");
$(`img[data-input-id='${input.id}'`).addClass("image-ident-warning");
} else {
$(input).addClass("image-ident-ok");
console.log('{% static "worker.min.js" %}');
console.log('{{ STATIC_URL }}/tesseract-core.wasm.js %}');
}
})
const worker = Tesseract.createWorker({
workerPath: '{% static "worker.min.js" %}',
langPath: '{% static "" %}',
//langPath: '{{ STATIC_URL }}',
corePath: '{% static "tesseract-core.wasm.js" %}',
});
const url = URL.createObjectURL(input.files[0]);
let img = new Image;
img.src = url;
img.onload = function () {
width = img.width;
// const rectangle = { left: 0, top: 0, width: width, height: 10 }
(async () => {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
// const { data: { text } } = await worker.recognize(input.files[0], { rectangle });
const {
data: {
text
}
} = await worker.recognize(input.files[0]);
//console.log(text);
l = text.toLowerCase();
$(`img[data-input-id='${input.id}'`).removeClass("image-ident-loading");
console.log(l);
if (l.includes("accesion") || l.includes("number") || l.search(
/(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) {
console.log("SHIT", input);
$(input).addClass("image-ident-warning");
$(`img[data-input-id='${input.id}'`).addClass("image-ident-warning");
} else {
$(input).addClass("image-ident-ok");
}
await worker.terminate();
})();
}
}
// function ocr(input) {
// // Tesseract.recognize(f, "eng",{ logger: m => console.log(m) }
// // ).then(({ data: { text } }) => {
// // console.log(text);
// // l = text.toLowerCase();
// // if (l.includes("accesion") || l.includes("number") || l.search(/(REF|RK9|RH8|RA9)\d+/g)) {
// // console.log("SHIT", this);
// // }
// // })
// console.log('{% static "worker.min.js" %}');
// console.log('{{ STATIC_URL }}/tesseract-core.wasm.js %}');
// const worker = Tesseract.createWorker({
// workerPath: '{% static "worker.min.js" %}',
// langPath: '{% static "" %}',
// //langPath: '{{ STATIC_URL }}',
// corePath: '{% static "tesseract-core.wasm.js" %}',
// });
// const url = URL.createObjectURL(input.files[0]);
// let img = new Image;
// img.src = url;
// img.onload = function () {
// width = img.width;
// // const rectangle = { left: 0, top: 0, width: width, height: 10 }
// (async () => {
// await worker.load();
// await worker.loadLanguage('eng');
// await worker.initialize('eng');
// // const { data: { text } } = await worker.recognize(input.files[0], { rectangle });
// const {
// data: {
// text
// }
// } = await worker.recognize(input.files[0]);
// //console.log(text);
// l = text.toLowerCase();
// $(`img[data-input-id='${input.id}'`).removeClass("image-ident-loading");
// console.log(l);
// if (l.includes("accesion") || l.includes("number") || l.search(
// /(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) {
// console.log("SHIT", input);
// $(input).addClass("image-ident-warning");
// $(`img[data-input-id='${input.id}'`).addClass("image-ident-warning");
// } else {
// $(input).addClass("image-ident-ok");
// }
// await worker.terminate();
// })();
// }
// }
async function blobToBase64(blob) {
return new Promise((resolve, _) => {
const reader = new FileReader();
@@ -482,7 +504,7 @@
} else if ($(el).hasClass("image-ident-ok")) {
extra_class = " image-ident-ok";
}
ocr(el);
ocr2(el);
$("#drop-filenames").append(
`<span data-input-id='${el.id}'><span>${n}: ${el.files[0].name}</span><img class='uploading${extra_class}' data-input-id='${el.id}' src=${url}></span>`