[英]Add url as parameter for query using Tesseract OCR
I am using tesseract
ocr and it is working perfectly. 我正在使用
tesseract
ocr,它工作得很好。 But my question is can I run tesseract with a url as parameter. 但我的问题是我可以用url作为参数运行tesseract。
I am looking to do the following 我希望做到以下几点
localhost/test.html/?othersite.com/image/image2.jpg
Some Image url for demo: 一些用于演示的图片网址:
1. https://i.imgur.com/leBXjxq.png
2. https://i.imgur.com/7u9LyF6.png
when the results are processed it would then come to a text-area
box. 处理结果后,它将进入
text-area
框。
Here's a code : 这是一个代码:
<html>
<head>
<title>Tesseract-JS Demo</title>
</head>
<body>
<input type="text" id="url" placeholder="Image URL" />
<!--<div id="ocr_results"> </div>-->
<div id="ocr_status"> </div>
<div>
<label>Filed1
<label>
<textarea id="txt" ></textarea>
</div>
</body>
<script src='https://cdn.rawgit.com/naptha/tesseract.js
/1.0.10/dist/tesseract.js'></script>
<script
src="https://cdnjs.cloudflare.com/ajax/
libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function runOCR(url) {
Tesseract.recognize(url)
.then(function(result) {
document.getElementById("txt")
.innerHTML = result.text;
document.getElementById('txt').focus();
}).progress(function(result) {
document.getElementById("ocr_status")
.innerText = result["status"] + " (" +
(result["progress"] * 100) + "%)";
});
}
document.getElementById("url")
.addEventListener("change", function(e) {
var url = document.getElementById("url").value;
runOCR(url);
});
</script>
You can do localhost/test.html?image=https://i.imgur.com/leBXjxq.png
你可以做
localhost/test.html?image=https://i.imgur.com/leBXjxq.png
And you can get the image from the URL in JavaScript like so: 您可以在JavaScript中从URL获取图像,如下所示:
const urlParams = new URLSearchParams(window.location.search);
const myImage = urlParams.get('image');
myImage variable will be: " https://i.imgur.com/leBXjxq.png " and then you can pass it to your OCR method. myImage变量将是:“ https://i.imgur.com/leBXjxq.png ”,然后您可以将其传递给您的OCR方法。
A sample code will be: 示例代码将是:
const urlParams = new URLSearchParams(window.location.search);
const myImage = urlParams.get('image');
if (myImage) {
runOCR(myImage);
}
Here is a link with updated code: https://gist.github.com/kolarski/0bc2a3feb02adb1b63016d0d78b3653c 这是一个更新代码的链接: https : //gist.github.com/kolarski/0bc2a3feb02adb1b63016d0d78b3653c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.