1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Image HoughLinesP Example</title>
- <link href="js_example_style.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <h2>Image HoughLinesP Example</h2>
- <p>
- <canvas> elements named <b>canvasInput</b> and <b>canvasOutput</b> have been prepared.<br>
- Click <b>Try it</b> button to see the result. You can choose another image.<br>
- You can change the code in the <textarea> to investigate more.
- </p>
- <div>
- <div class="control"><button id="tryIt" disabled>Try it</button></div>
- <textarea class="code" rows="9" cols="100" id="codeEditor" spellcheck="false">
- </textarea>
- <p class="err" id="errorMessage"></p>
- </div>
- <div>
- <table cellpadding="0" cellspacing="0" width="0" border="0">
- <tr>
- <td>
- <canvas id="canvasInput"></canvas>
- </td>
- <td>
- <canvas id="canvasOutput"></canvas>
- </td>
- </tr>
- <tr>
- <td>
- <div class="caption">canvasInput <input type="file" id="fileInput" name="file" accept="image/*" /></div>
- </td>
- <td>
- <div class="caption">canvasOutput</div>
- </td>
- </tr>
- </table>
- </div>
- <script src="utils.js" type="text/javascript"></script>
- <script id="codeSnippet" type="text/code-snippet">
- let src = cv.imread('canvasInput');
- let dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8UC3);
- let lines = new cv.Mat();
- let color = new cv.Scalar(255, 0, 0);
- cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
- cv.Canny(src, src, 50, 200, 3);
- // You can try more different parameters
- cv.HoughLinesP(src, lines, 1, Math.PI / 180, 2, 0, 0);
- // draw lines
- for (let i = 0; i < lines.rows; ++i) {
- let startPoint = new cv.Point(lines.data32S[i * 4], lines.data32S[i * 4 + 1]);
- let endPoint = new cv.Point(lines.data32S[i * 4 + 2], lines.data32S[i * 4 + 3]);
- cv.line(dst, startPoint, endPoint, color);
- }
- cv.imshow('canvasOutput', dst);
- src.delete(); dst.delete(); lines.delete();
- </script>
- <script type="text/javascript">
- let utils = new Utils('errorMessage');
- utils.loadCode('codeSnippet', 'codeEditor');
- utils.loadImageToCanvas('shape.jpg', 'canvasInput');
- utils.addFileInputHandler('fileInput', 'canvasInput');
- let tryIt = document.getElementById('tryIt');
- tryIt.addEventListener('click', () => {
- utils.executeCode('codeEditor');
- });
- utils.loadOpenCv(() => {
- tryIt.removeAttribute('disabled');
- });
- </script>
- </body>
- </html>
|