From 21b7ef353a7140b9f268c80eb58e85bcc878a8c5 Mon Sep 17 00:00:00 2001 From: Harish Karumuthil Date: Fri, 17 Sep 2021 21:35:39 +0530 Subject: [PATCH] Support more languages --- public/app.js | 12 +++++++++--- public/index.html | 13 +++++++++++-- routes/root.js | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/public/app.js b/public/app.js index 73ed8c6..ce36b08 100644 --- a/public/app.js +++ b/public/app.js @@ -5,11 +5,11 @@ * Copyright 2020 Harish.K */ -function ocrByServer(image) { +function ocrByServer(image, opts) { var data = new FormData(); data.append("image", image); return fetch( - "./ocr", + "./ocr?lang="+opts.lang.join(':'), { method: "POST", body: data, @@ -28,11 +28,17 @@ new Vue({ currentFileBlob: null, isLoading: false, ocrOutput: "", + availableLangs:[ + { label: 'Malayalam', code: 'mal' }, + { label: 'English', code: 'eng' }, + { label: 'Hindi', code: 'hin' }, + ], + selectedLangs:['mal'] }, methods: { doOcr: function () { this.isLoading = true; - ocrByServer(this.currentFileBlob) + ocrByServer(this.currentFileBlob, { lang: this.selectedLangs }) .then((data) => { console.log("success", data); this.ocrOutput = data.text; diff --git a/public/index.html b/public/index.html index e78485c..189464c 100644 --- a/public/index.html +++ b/public/index.html @@ -50,7 +50,7 @@ readonly v-model="selectedFileName" class="form-control" - placeholder="Choose a file..." + placeholder="Choose an image..." @click="$refs.file_input.click()" />
@@ -59,7 +59,7 @@ type="button" @click="$refs.file_input.click()" > - Choose another image + Choose an image
+
+
+ +
+ + +
+
+
diff --git a/routes/root.js b/routes/root.js index a8f9212..f373def 100644 --- a/routes/root.js +++ b/routes/root.js @@ -17,7 +17,7 @@ module.exports = async function (fastify, opts) { const data = await req.file(); const uid = crypto.randomBytes(16).toString("hex"); const filename = `${UPLOAD_PATH}/${uid}.${mime.extension(data.mimetype)}`; - const lang = "mal+eng"; + const lang = req.query.lang ? req.query.lang.replace(/:/g, "+") : "mal"; await pump(data.file, fs.createWriteStream(filename)); const args = [filename, "stdout", "-l", lang]; const { stdout, stderr } = await exec("tesseract", args);