.
This commit is contained in:
@@ -374,67 +374,89 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function ocr(input) {
|
function ocr2(url, input) {
|
||||||
// Tesseract.recognize(f, "eng",{ logger: m => console.log(m) }
|
Tesseract.recognize(
|
||||||
// ).then(({ data: { text } }) => {
|
url,
|
||||||
// console.log(text);
|
'eng',
|
||||||
// l = text.toLowerCase();
|
{ logger: m => console.log(m) }
|
||||||
// if (l.includes("accesion") || l.includes("number") || l.search(/(REF|RK9|RH8|RA9)\d+/g)) {
|
).then(({ data: { text } }) => {
|
||||||
// console.log("SHIT", this);
|
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) {
|
async function blobToBase64(blob) {
|
||||||
return new Promise((resolve, _) => {
|
return new Promise((resolve, _) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
@@ -482,7 +504,7 @@
|
|||||||
} else if ($(el).hasClass("image-ident-ok")) {
|
} else if ($(el).hasClass("image-ident-ok")) {
|
||||||
extra_class = " image-ident-ok";
|
extra_class = " image-ident-ok";
|
||||||
}
|
}
|
||||||
ocr(el);
|
ocr2(el);
|
||||||
|
|
||||||
$("#drop-filenames").append(
|
$("#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>`
|
`<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>`
|
||||||
|
|||||||
Reference in New Issue
Block a user