We are about to switch to a new forum software. Until then we have removed the registration on this forum.
After correctly loading an image I get the below error message when trying to recognize text on an image with Tesseract.js.
tesseract.js:356 Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': HTMLCanvasElement object could not be cloned. at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:356:25 at loadImage (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:415:16) at Object.sendPacket (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:354:5) at TesseractJob._send (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:549:21) at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:643:9 at Array. (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:673:5) at TesseractWorker._dequeue (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:683:19) at TesseractWorker._delay (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:675:32) at TesseractWorker.recognize (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js:635:16) at recognizeFile (http://localhost:8080/:41:19) (anonymous) @ tesseract.js:356 loadImage @ tesseract.js:415 sendPacket @ tesseract.js:354 _send @ tesseract.js:549 (anonymous) @ tesseract.js:643 (anonymous) @ tesseract.js:673 _dequeue @ tesseract.js:683 _delay @ tesseract.js:675 recognize @ tesseract.js:635 recognizeFile @ (index):41 keyPressed @ (index):35 e._onkeydown @ p5.min.js:9
This is my code:
<title>Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.12/p5.min.js" type="text/javascript"></script>
<script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js' type="text/javascript"></script>
<script>
var img;
function preload()
{
// http://cheesiemack.com/wp/wp-content/uploads/2012/06/CT-872NED.jpg
img = loadImage("licenseplate.jpg");
}
function setup()
{
canvas = createCanvas (windowWidth, windowHeight);
}
function draw()
{
background (255, 255, 0);
image (img, 0, 0);
}
function keyPressed()
{
recognizeFile (img);
}
function recognizeFile (img)
{
Tesseract.recognize (img, {lang: 'eng'})
.then (function(data) {console.log (data.text)})
}
function windowResized()
{
resizeCanvas (windowWidth, windowHeight);
}
</script>
Answers
<canvas>
tag element: https://Developer.Mozilla.org/en-US/docs/Web/HTML/Element/canvas<canvas>
is cited as 1 of the valid ImageLike datatypes! \m/<canvas>
?https://Developer.Mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
img.canvas
orimg.drawingContext
to Tesseract::recognize() as its argument. :\">index.html:
sketch.js:
P.S.: I had to use http://CORS-Anywhere.HerokuApp.com in order to load the remote image "CT-872NED.jpg" from http://CheesieMack.com, b/c it wasn't CORS-enabled there! :-O
@GotoLoop, thanks for taking the time to look into this and giving me a such detailed explanation! Much appreciated!