-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (75 loc) · 2.44 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Watching eyes</title>
</head>
<body>
<video id="video" autoplay
style="position:absolute;left:0px;top:0px;width: 320px; height: 240px; border: 1px solid black;"></video>
<canvas id="canvas" style="position:absolute;left:0px;top:0px"></canvas>
<script src="js/FaceDetector.js"></script>
<script src="js/WebcamManager.js"></script>
<script>
var camStreamWidth = 640;
var camStreamHeight = 480;
var VIEW_WIDTH = 320;
var VIEW_HEIGHT = 240;
var video = document.getElementById("video");
var canvas = document.getElementById("canvas");
canvas.width = VIEW_WIDTH;
canvas.height = VIEW_HEIGHT;
var webcamParams = {
video: {
mandatory: {
maxWidth: camStreamWidth,
maxHeight: camStreamHeight,
minWidth: camStreamWidth,
minHeight: camStreamHeight
}
}
};
var webcamMgr = new WebCamManager(
{
webcamParams: webcamParams, //Set params for web camera
testVideoMode: false,//true:force use example video for test false:use web camera
videoTag: video
}
);
var faceDetector = new FaceDetector(
{
video: webcamMgr.getVideoTag(),
flipLeftRight: false,
flipUpsideDown: false
}
);
webcamMgr.setOnGetUserMediaCallback(function () {
faceDetector.startDetecting();
});
faceDetector.setOnFaceAddedCallback(function (addedFaces, detectedFaces) {
for (var i = 0; i < addedFaces.length; i++) {
console.log("[facedetector] New face detected id=" + addedFaces[i].faceId + " index=" + addedFaces[i].faceIndex);
}
});
faceDetector.setOnFaceLostCallback(function (lostFaces, detectedFaces) {
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
for (var i = 0; i < lostFaces.length; i++) {
console.log("[facedetector] Face removed id=" + lostFaces[i].faceId + " index=" + lostFaces[i].faceIndex);
}
});
faceDetector.setOnFaceUpdatedCallback(function (detectedFaces) {
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
ctx.strokeStyle = "red";
ctx.lineWidth = 3;
ctx.fillStyle = "red";
for (var i = 0; i < detectedFaces.length; i++) {
var face = detectedFaces[i];
ctx.strokeRect(face.x * VIEW_WIDTH, face.y * VIEW_HEIGHT + 10, face.width * VIEW_WIDTH, face.height * VIEW_HEIGHT);
}
});
webcamMgr.startCamera();
</script>
</body>
</html>