Skip to content

Instantly share code, notes, and snippets.

@shri
Created May 6, 2014 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shri/11552108 to your computer and use it in GitHub Desktop.
Save shri/11552108 to your computer and use it in GitHub Desktop.
[wearscript] ar tags on glass
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000">
<script>
function centralTag(tags){
var distances = [];
var numTags = tags[0].length / 9;
var minDist = 1000;
var center = tags[0][0];
for (var i = 0; i < numTags; i++) {
var x = 0;
var y = 0;
x = (tags[0][9 * i + 1]+tags[0][9 * i + 3]+tags[0][9 * i + 5]+tags[0][9 * i + 7])/4;
y = (tags[0][9 * i + 2]+tags[0][9 * i + 4]+tags[0][9 * i + 6]+tags[0][9 * i + 8])/4;
x = x - 320;
y = y - 180;
var dist = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
if(dist<minDist){
center = tags[0][9 * i];
minDist = dist;
}
}
return center;
}
function main() {
var tagList = ["plant", "milk", "backpack", "laptop", "penny", "Google Glass", "Macbook", "chair", "table", "mouse", "keyboard", "monitor", "headphones", "red bull", "pen", "tv"];
if (WS.scriptVersion(1)) return;
WS.cameraOnBackgroundUnsafe(1, 360, 640);
var model_ar = btoa(msgpack.pack([{'kw': {}, 'name': 'picarus.ARMarkerDetector'}]).map(function (x) {return String.fromCharCode(x)}).join(''));
model = new WS.PicarusModel(model_ar, function () {
model.processStream(function (tags) {
tags = msgpack.unpack(tags);
if (tags && tags[0].length) {
console.log(tags);
var curtag = tagList[centralTag(tags)];
WS.say(tagList[centralTag(tags)]);
var tree = new WS.Cards();
tree.add(curtag, " ");
WS.cardTree(tree);
WS.displayCardTree();
}
});
})}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment