From 9b784db4f1e05fddab041007a3ff6d778e5bde4c Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Nov 2021 11:51:49 +0000 Subject: [PATCH] . --- rapids/templates/rapids/rapid_form.html | 138 ++++++++++++++---------- 1 file changed, 80 insertions(+), 58 deletions(-) diff --git a/rapids/templates/rapids/rapid_form.html b/rapids/templates/rapids/rapid_form.html index bea584f8..4f212a90 100755 --- a/rapids/templates/rapids/rapid_form.html +++ b/rapids/templates/rapids/rapid_form.html @@ -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( `${n}: ${el.files[0].name}`