带来各种不同计算机视觉算法和技术的JS库:tracking.js
jopen
10年前
这个tracking.js库将各种不同计算机视觉算法和技术带至浏览器环境中。通过使用现在HTML5规范,它能够让开发人员实现实时颜色跟踪,人脸识别等等。整个库核心只有~7 KB左右并拥有直观的接口。
<!doctype html> <html> <head> <meta charset="utf-8"> <title>tracking.js - color hello world</title> <link rel="stylesheet" href="assets/demo.css"> <script src="../build/tracking-min.js"></script> <style> .rect { width: 80px; height: 80px; position: absolute; left: -1000px; top: -1000px; } </style> </head> <body> <div class="demo-title"> <p><a href="http://trackingjs.com" target="_parent">tracking.js</a> - detect certain colors in a image</p> </div> <div class="demo-frame"> <div class="demo-container"> <img id="img" src="assets/psmove.png" /> </div> </div> <script> window.onload = function() { var img = document.getElementById('img'); var demoContainer = document.querySelector('.demo-container'); var tracker = new tracking.ColorTracker(['magenta', 'cyan', 'yellow']); tracker.on('track', function(event) { event.data.forEach(function(rect) { window.plot(rect.x, rect.y, rect.width, rect.height, rect.color); }); }); tracking.track('#img', tracker); window.plot = function(x, y, w, h, color) { var rect = document.createElement('div'); document.querySelector('.demo-container').appendChild(rect); rect.classList.add('rect'); rect.style.border = '2px solid ' + color; rect.style.width = w + 'px'; rect.style.height = h + 'px'; rect.style.left = (img.offsetLeft + x) + 'px'; rect.style.top = (img.offsetTop + y) + 'px'; }; }; </script> </body> </html>