-
Notifications
You must be signed in to change notification settings - Fork 0
/
processing_and_tracking.html
69 lines (58 loc) · 1.68 KB
/
processing_and_tracking.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<head>
<title>tracking.js + processing</title>
<script src="processing.min.js"></script>
<script src="tracking-min.js"></script>
</head>
<body>
<video id="myVideo" width="400" height="300" preload autoplay loop muted></video>
<canvas id="canvas1"></canvas>
<script>
var video = document.querySelector("#myVideo");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({video: true})
.then(function(stream) {
video.srcObject = stream;
})
.catch(function(err0r) {
console.log("Something went wrong!");
});
}
var colors = new tracking.ColorTracker(['magenta', 'cyan', 'yellow']);
var height;
var width;
var color;
var valueY;
var valueX;
colors.on('track', function(event) {
if (event.data.length === 0) {
// No colors were detected in this frame.
} else {
event.data.forEach(function(rect) {
valueX = rect.x;
valueY = rect.y;
height = rect.height;
width = rect.width;
color = rect.color;
});
console.log(valueX, valueY, height, width, color);
}
});
tracking.track('#myVideo', colors);
function sketchProc(processing) {
processing.setup = function() {
processing.size(400, 300);
}
processing.draw = function() {
processing.background(200);
processing.fill(255,0,0);
processing.stroke(0,255,0);
processing.ellipse(valueX, valueY, 50, 50);
};
}
var canvas = document.getElementById("canvas1");
var processingInstance = new Processing(canvas, sketchProc);
</script>
</body>
</html>