Download doc/js_tutorials/js_assets/js_contour_features_area.html from tgollogly/test: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/tgollogly/test/resolve/main/doc/js_tutorials/js_assets/js_contour_features_area.html
- Command line
-
hf download hf://tgollogly/test/doc/js_tutorials/js_assets/js_contour_features_area.html
-
curl -L -o js_contour_features_area.html https://huggingface.co/tgollogly/test/resolve/main/doc/js_tutorials/js_assets/js_contour_features_area.html
2.06 kB
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Image Area Example</title> | |
| <link href="js_example_style.css" rel="stylesheet" type="text/css" /> | |
| </head> | |
| <body> | |
| <h2>Image Area Example</h2> | |
| <p> | |
| <canvas> elements named <b>canvasInput</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> | |
| <div> | |
| <canvas id="canvasInput"></canvas> | |
| <div class="caption">canvasInput <input type="file" id="fileInput" name="file" accept="image/*" /></div> | |
| </div> | |
| <div> | |
| <p><strong>The area is: </strong><span id="areaOutput"></span></p> | |
| </div> | |
| </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); | |
| cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0); | |
| cv.threshold(src, src, 177, 200, cv.THRESH_BINARY); | |
| let contours = new cv.MatVector(); | |
| let hierarchy = new cv.Mat(); | |
| cv.findContours(src, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE); | |
| let cnt = contours.get(20); | |
| // You can try more different parameters | |
| let area = cv.contourArea(cnt, false); | |
| areaOutput.innerHTML = area; | |
| src.delete(); dst.delete(); contours.delete(); hierarchy.delete(); cnt.delete(); | |
| </script> | |
| <script type="text/javascript"> | |
| let utils = new Utils('errorMessage'); | |
| utils.loadCode('codeSnippet', 'codeEditor'); | |
| utils.loadImageToCanvas('lena.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> | |