js_gradients_absSobel.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Image AbsSobel Example</title>
  6. <link href="js_example_style.css" rel="stylesheet" type="text/css" />
  7. </head>
  8. <body>
  9. <h2>Image AbsSobel Example</h2>
  10. <p>
  11. &lt;canvas&gt; elements named <b>canvasInput</b>, <b>canvasOutput8U</b> and <b>canvasOutput64F</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="canvasOutput8U" class="small"></canvas>
  29. </td>
  30. <td>
  31. <canvas id="canvasOutput64F" 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">canvasOutput8U</div>
  40. </td>
  41. <td>
  42. <div class="caption">canvasOutput64F</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 absDstx = 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, absDstx, cv.CV_64F, 1, 0, 3, 1, 0, cv.BORDER_DEFAULT);
  56. cv.convertScaleAbs(absDstx, absDstx, 1, 0);
  57. cv.imshow('canvasOutput8U', dstx);
  58. cv.imshow('canvasOutput64F', absDstx);
  59. src.delete(); dstx.delete(); absDstx.delete();
  60. </script>
  61. <script type="text/javascript">
  62. let utils = new Utils('errorMessage');
  63. utils.loadCode('codeSnippet', 'codeEditor');
  64. utils.loadImageToCanvas('shape.jpg', 'canvasInput');
  65. utils.addFileInputHandler('fileInput', 'canvasInput');
  66. let tryIt = document.getElementById('tryIt');
  67. tryIt.addEventListener('click', () => {
  68. utils.executeCode('codeEditor');
  69. });
  70. utils.loadOpenCv(() => {
  71. tryIt.removeAttribute('disabled');
  72. });
  73. </script>
  74. </body>
  75. </html>