js_trackbar.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Trackbar Example</title>
  6. <link href="js_example_style.css" rel="stylesheet" type="text/css" />
  7. </head>
  8. <body>
  9. <h2>Trackbar Example</h2>
  10. <p>
  11. &lt;canvas&gt; elements named <b>canvasInput1</b>, <b>canvasInput2</b> and <b>canvasOutput</b> have been prepared.<br>
  12. The code of &lt;textarea&gt; will be executed when &lt;input&gt; element named <b>trackbar</b> value changes.<br>
  13. You can change the code in the &lt;textarea&gt; to investigate more.
  14. </p>
  15. <div>
  16. <textarea class="code" rows="12" cols="80" id="codeEditor" spellcheck="false">
  17. </textarea>
  18. <p class="err" id="errorMessage"></p>
  19. </div>
  20. <div>
  21. <b>trackbar</b>
  22. <input type="range" id="trackbar" disabled value="50" min="0" max="100" step="1">
  23. <label id="weightValue" ></label>
  24. <div>
  25. <table cellpadding="0" cellspacing="0" width="0" border="0">
  26. <tr>
  27. <td>
  28. <canvas id="canvasInput1" class="small"></canvas>
  29. </td>
  30. <td>
  31. <canvas id="canvasInput2" class="small"></canvas>
  32. </td>
  33. <td>
  34. <canvas id="canvasOutput" class="small"></canvas>
  35. </td>
  36. </tr>
  37. <tr>
  38. <td>
  39. <div class="caption">canvasInput1</div>
  40. </td>
  41. <td>
  42. <div class="caption">canvasInput2</div>
  43. </td>
  44. <td>
  45. <div class="caption">canvasOutput</div>
  46. </td>
  47. </tr>
  48. </table>
  49. </div>
  50. </div>
  51. <script src="utils.js" type="text/javascript"></script>
  52. <script id="codeSnippet" type="text/code-snippet">
  53. let trackbar = document.getElementById('trackbar');
  54. let alpha = trackbar.value/trackbar.max;
  55. let beta = ( 1.0 - alpha );
  56. let src1 = cv.imread('canvasInput1');
  57. let src2 = cv.imread('canvasInput2');
  58. let dst = new cv.Mat();
  59. cv.addWeighted( src1, alpha, src2, beta, 0.0, dst, -1);
  60. cv.imshow('canvasOutput', dst);
  61. dst.delete();
  62. src1.delete();
  63. src2.delete();
  64. </script>
  65. <script type="text/javascript">
  66. let utils = new Utils('errorMessage');
  67. utils.loadCode('codeSnippet', 'codeEditor');
  68. utils.loadImageToCanvas('apple.jpg', 'canvasInput1');
  69. utils.loadImageToCanvas('orange.jpg', 'canvasInput2');
  70. let trackbar = document.getElementById('trackbar');
  71. trackbar.addEventListener('input', () => {
  72. utils.executeCode('codeEditor');
  73. });
  74. let weightValue = document.getElementById('weightValue');
  75. weightValue.innerText = trackbar.value;
  76. trackbar.addEventListener('input', () => {
  77. weightValue.innerText = trackbar.value;
  78. });
  79. utils.loadOpenCv(() => {
  80. trackbar.removeAttribute('disabled');
  81. utils.executeCode('codeEditor');
  82. });
  83. </script>
  84. </body>
  85. </html>