js_gradients_Sobel.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Image Sobel Example</title>
  6. <link href="js_example_style.css" rel="stylesheet" type="text/css" />
  7. </head>
  8. <body>
  9. <h2>Image Sobel Example</h2>
  10. <p>
  11. &lt;canvas&gt; elements named <b>canvasInput</b>, <b>canvasOutputx</b> and <b>canvasOutputy</b> have been prepared.<br>
  12. Click <b>Try it</b> button to see the result. You can choose another image.<br>
  13. You can change the code in the &lt;textarea&gt; to investigate more.
  14. </p>
  15. <div>
  16. <div class="control"><button id="tryIt" disabled>Try it</button></div>
  17. <textarea class="code" rows="9" cols="100" id="codeEditor" spellcheck="false">
  18. </textarea>
  19. <p class="err" id="errorMessage"></p>
  20. </div>
  21. <div>
  22. <table cellpadding="0" cellspacing="0" width="0" border="0">
  23. <tr>
  24. <td>
  25. <canvas id="canvasInput" class="small"></canvas>
  26. </td>
  27. <td>
  28. <canvas id="canvasOutputx" class="small"></canvas>
  29. </td>
  30. <td>
  31. <canvas id="canvasOutputy" class="small"></canvas>
  32. </td>
  33. </tr>
  34. <tr>
  35. <td>
  36. <div class="caption">canvasInput <input type="file" id="fileInput" name="file" accept="image/*" /></div>
  37. </td>
  38. <td>
  39. <div class="caption">canvasOutputx</div>
  40. </td>
  41. <td>
  42. <div class="caption">canvasOutputy</div>
  43. </td>
  44. </tr>
  45. </table>
  46. </div>
  47. <script src="utils.js" type="text/javascript"></script>
  48. <script id="codeSnippet" type="text/code-snippet">
  49. let src = cv.imread('canvasInput');
  50. let dstx = new cv.Mat();
  51. let dsty = new cv.Mat();
  52. cv.cvtColor(src, src, cv.COLOR_RGB2GRAY, 0);
  53. // You can try more different parameters
  54. cv.Sobel(src, dstx, cv.CV_8U, 1, 0, 3, 1, 0, cv.BORDER_DEFAULT);
  55. cv.Sobel(src, dsty, cv.CV_8U, 0, 1, 3, 1, 0, cv.BORDER_DEFAULT);
  56. // cv.Scharr(src, dstx, cv.CV_8U, 1, 0, 1, 0, cv.BORDER_DEFAULT);
  57. // cv.Scharr(src, dsty, cv.CV_8U, 0, 1, 1, 0, cv.BORDER_DEFAULT);
  58. cv.imshow('canvasOutputx', dstx);
  59. cv.imshow('canvasOutputy', dsty);
  60. src.delete(); dstx.delete(); dsty.delete();
  61. </script>
  62. <script type="text/javascript">
  63. let utils = new Utils('errorMessage');
  64. utils.loadCode('codeSnippet', 'codeEditor');
  65. utils.loadImageToCanvas('lena.jpg', 'canvasInput');
  66. utils.addFileInputHandler('fileInput', 'canvasInput');
  67. let tryIt = document.getElementById('tryIt');
  68. tryIt.addEventListener('click', () => {
  69. utils.executeCode('codeEditor');
  70. });
  71. utils.loadOpenCv(() => {
  72. tryIt.removeAttribute('disabled');
  73. });
  74. </script>
  75. </body>
  76. </html>