UNPKG

speedy-vision

Version:

GPU-accelerated Computer Vision for JavaScript

107 lines (86 loc) 3.24 kB
<!-- speedy-vision.js GPU-accelerated Computer Vision for JavaScript Copyright 2020-2022 Alexandre Martins <alemartf(at)gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. hello-world.html Hello World demo --> <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="description" content="speedy-vision.js: GPU-accelerated Computer Vision for JavaScript"> <meta name="author" content="Alexandre Martins"> <title>Speedy feature detection</title> <script src="../dist/speedy-vision.js"></script> <link href="style.css" rel="stylesheet"> </head> <body> <h1>Hello, Speedy!</h1> <p>Feature detection made easy:</p> <img src="../assets/masp.jpg" title="Free photo by ckturistando (pexels.com)" hidden> <script> window.onload = async function() { /* Our pipeline: Image ---> Convert to ---> FAST corner ---> Keypoint Source greyscale detector Sink */ // load the image const image = document.querySelector('img'); const media = await Speedy.load(image); // create the pipeline const pipeline = Speedy.Pipeline(); const source = Speedy.Image.Source(); const greyscale = Speedy.Filter.Greyscale(); const fast = Speedy.Keypoint.Detector.FAST(); const sink = Speedy.Keypoint.Sink(); source.media = media; fast.threshold = 50; source.output().connectTo(greyscale.input()); greyscale.output().connectTo(fast.input()); fast.output().connectTo(sink.input()); pipeline.init(source, greyscale, fast, sink); // find the feature points const { keypoints } = await pipeline.run(); // render the feature points const canvas = createCanvas(media.width, media.height, image.title); draw(media, canvas); renderFeatures(canvas, keypoints); } function createCanvas(width, height, title) { const canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; canvas.title = title; return document.body.appendChild(canvas); } function renderFeatures(canvas, features, size = 1, color = 'yellow') { const context = canvas.getContext('2d'); context.beginPath(); for(let feature of features) context.rect(feature.x - size, feature.y - size, 2 * size, 2 * size); context.strokeStyle = color; context.stroke(); } function draw(media, canvas, x = 0, y = 0, width = media.width, height = media.height) { const ctx = canvas.getContext('2d'); ctx.drawImage(media.source, x, y, width, height); } </script> <mark>Powered by <a href="https://github.com/alemart/speedy-vision">speedy-vision.js</a></mark> </body> </html>