image-processing.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <html>
  2. <head>
  3. <script src="/dist/tesseract.min.js"></script>
  4. <style>
  5. .column {
  6. float: left;
  7. width: 20%;
  8. padding: 5px;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <input type="file" id="uploader">
  14. <div class="row">
  15. <div class="column">
  16. <p>Input Image</p>
  17. <img id="imgInput" style="max-width:500px;">
  18. </div>
  19. <div class="column">
  20. <p>Rotated, Original Color</p>
  21. <img id="imgOriginal" style="max-width:500px;">
  22. </div>
  23. <div class="column">
  24. <p>Rotated, Grey</p>
  25. <img id="imgGrey" style="max-width:500px;">
  26. </div>
  27. <div class="column">
  28. <p>Rotated, Binary</p>
  29. <img id="imgBinary" style="max-width:500px;">
  30. </div>
  31. </div>
  32. <script>
  33. const recognize = async ({ target: { files } }) => {
  34. document.getElementById("imgInput").src = URL.createObjectURL(files[0]);
  35. const worker = await Tesseract.createWorker("eng", 1, {
  36. // corePath: '/tesseract-core-simd.wasm.js',
  37. workerPath: "/dist/worker.min.js"
  38. });
  39. const ret = await worker.recognize(files[0], {rotateAuto: true}, {imageColor: true, imageGrey: true, imageBinary: true});
  40. document.getElementById("imgOriginal").src = ret.data.imageColor;
  41. document.getElementById("imgGrey").src = ret.data.imageGrey;
  42. document.getElementById("imgBinary").src = ret.data.imageBinary;
  43. }
  44. const elm = document.getElementById('uploader');
  45. elm.addEventListener('change', recognize);
  46. </script>
  47. </body>
  48. </html>