This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
110 lines (89 loc) · 3.32 KB
/
demo.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
99
100
101
102
103
104
105
106
107
108
109
110
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<title>Gate Keeper</title>
<link rel='stylesheet' href='css/styles.css' />
</head>
<body>
<div id='wrapper'>
<h1>Gate Keeper</h1>
<div id='flash_container' class='container'>
<object id="iembedflash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="240">
<param name="movie" value="camcanvas.swf" />
<param name="quality" value="high" />
<param name="allowScriptAccess" value="always" />
<embed allowScriptAccess="always" id="embedflash" src="camcanvas.swf" quality="high" width="320" height="240" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" mayscript="true" wmode='transparent' />
</object>
</div>
<div id='canvas_container' class='container'>
<canvas id='canvas' width='320' height='240'></canvas>
</div>
<button id='capture'>Capture</button>
<button id='detect'>Detect</button>
</div>
<script src='js/ccv/ccv.js'></script>
<script src='js/ccv/face.js'></script>
<script>
//declarations
var cam = document.getElementById("embedflash"),
canvas = document.getElementById("canvas"),
ctx = canvas.getContext('2d'),
c_w = canvas.width,
c_h = canvas.height,
c_imageData = ctx.getImageData( 0, 0, c_w, c_h),
c_imageDataBuffer = ctx.getImageData( 0, 0, c_w, c_h),
c = 0,
btn_capture = document.getElementById("capture"),
btn_detect = document.getElementById("detect"),
passLine, updateCanvas, detectFace;
//methods
passLine = function (stringPixels) {
var coll = stringPixels.split("-"), intVal,
mask = 0xff;
for(var i=0;i<320;i++) {
intVal = parseInt(coll[i], 10);
r = (intVal >> 16) & mask;
g = (intVal >> 8) & mask;
b = (intVal ) & mask;
c_imageData.data[ c + 0 ] = r;
c_imageData.data[ c + 1 ] = g;
c_imageData.data[ c + 2 ] = b;
c_imageData.data[ c + 3 ] = 255;
c += 4;
}
if( c >= (320 * 240 * 4) ) {
c=0;
ctx.putImageData( c_imageData, 0, 0 );
}
};
updateCanvas = function () {
cam.ccCapture();
//setTimeout(updateCanvas, 300);
};
detectFace = function () {
var image = new Image(), comp, i = 0, c_l;
image.src = canvas.toDataURL();
image.onload = function () {
comp = ccv.detect_objects({ "canvas" : ccv.grayscale(ccv.pre(image)),
"cascade" : cascade,
"interval" : 5,
"min_neighbors" : 1 });
ctx.lineWidth = 3;
ctx.strokeStyle = "#f00";
c_l = comp.length;
for (; i < c_l; i++) {
ctx.strokeRect(comp[i].x, comp[i].y, comp[i].width, comp[i].height);
}
};
}
//bindings
btn_capture.addEventListener('click', function () {
updateCanvas();
}, false);
btn_detect.addEventListener('click', function () {
detectFace();
}, false);
</script>
</body>
</html>