-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
185 lines (164 loc) · 7.61 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>DAAN Roadshow Gesichtserkennungs-Demo</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">DAAN Roadshow</a>
</nav>
<main role="main" class="container">
<div class="container">
<h1>Gesichtserkennungs-Demo</h1>
</div>
<div class="container">
<video id="video" width="640" height="480" autoplay></video>
</div>
<div class="container">
<button class="btn btn-primary btn-lg mb-1" disabled="true" id="snap">Gesichter erkennen</button>
<button class="btn btn-primary btn-lg mb-1" id="showCam">Kamerabild zeigen</button>
<div class="form-group ml-5">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" value="" id="hungerCheck">
<label class="form-check-label" for="hungerCheck">
Hunger bewerten
</label>
</div>
</div>
<div class="container" style="display:none">
<!--<div class="container">-->
<canvas id="canvas" width="640" height="480"></canvas>
</div>
</main>
<script src="js/aws_access_vars.js"></script>
<!--<script src="https://sdk.amazonaws.com/js/aws-sdk-2.176.0.min.js"></script>-->
<script>
// Grab elements, create settings, etc.
var video = document.getElementById('video');
// Elements for taking the snapshot
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var video = document.getElementById('video');
var snapButton = document.getElementById("snap");
var showVideoButton = document.getElementById("showCam");
var snapCanvas = document.createElement("canvas");
var hungerCheck = document.getElementById("hungerCheck")
w = 640;
h = 480;
genderCol = {Male: "rgb(100,200,250)", Female: "rgb(250,200,200)"};
snapCanvas.width = w;
snapCanvas.height = h;
snapCanvas.id="canvas";
function startCam() {
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
});
}
snapButton.disabled = false;
showVideoButton.disabled = true;
}
startCam();
showVideoButton.addEventListener("click", function() {
snapCanvas.parentNode.replaceChild(video, snapCanvas);
startCam();
video.play();
});
// Trigger photo take
snapButton.addEventListener("click", function() {
context.drawImage(video, 0, 0, w, h);
var dataURL = canvas.toDataURL();
var now = new Date();
/*
// AWS Config
AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
//This is a PUT operation
s3.upload({
Key: now.toString(),
Body: dataURL
}, function(err, data) {
if (err) {
return alert('There was an error uploading your photo: ', err.message);
}
alert('Successfully uploaded photo.');
});*/
//Alternative ajax upload
video.pause();
video.parentNode.replaceChild(snapCanvas, video);
snapButton.disabled = true;
showVideoButton.disabled = false;
snapCtxt = snapCanvas.getContext('2d');
snapCtxt.drawImage(canvas, 0, 0, w, h);
$.ajax({
type: "POST",
url: lambdaUrl,
contentType: "application/json",
data: JSON.stringify({ picture: dataURL }),
success: function(data) {
console.log(data);
data["FaceDetails"].forEach(function(face) {
box = face["BoundingBox"];
snapCtxt.font = 'bold 18px sans-serif';
text = face["AgeRange"]["Low"] + "-" + face["AgeRange"]["High"] +
"J, ";
if (face["Emotions"].length>0) {
if (hungerCheck.checked==false) {
text += face["Emotions"][0]["Type"].replace("HAPPY", "fröhlich")
.replace("SAD", "traurig").replace("ANGRY", "wütend").replace("CONFUSED", "verwirrt")
.replace("DISGUSTED","angewidert").replace("SURPRISED", "überrascht").replace("CALM", "ruhig")
.replace("UNKNOWN", "unbekannt");
}
else {
text += face["Emotions"][0]["Type"].replace("HAPPY", "satt")
.replace("SAD", "hungrig").replace("ANGRY", "verhungert").replace("CONFUSED", "sehr hungrig")
.replace("DISGUSTED","angewidert").replace("SURPRISED", "hungrig").replace("CALM", "satt")
.replace("UNKNOWN", "unbekannt");
}
}
snapCtxt.fillStyle=genderCol[face["Gender"]["Value"]];
snapCtxt.fillText(text, box["Left"]*w, box["Top"]*h-11);
snapCtxt.beginPath();
snapCtxt.strokeStyle=genderCol[face["Gender"]["Value"]];
snapCtxt.lineWidth = 5;
snapCtxt.moveTo(box["Left"]*w, box["Top"]*h);
snapCtxt.lineTo((box["Left"]+box["Width"])*w, box["Top"]*h);
snapCtxt.lineTo((box["Left"]+box["Width"])*w, (box["Top"]+box["Height"])*h);
snapCtxt.lineTo(box["Left"]*w, (box["Top"]+box["Height"])*h);
snapCtxt.closePath();
snapCtxt.stroke();
});
}
}).done(function(data, textStatus, jqXHR ) {
console.log("Daten gesendet");
// If you want the file to be visible in the browser
// - please modify the callback in javascript. All you
// need is to return the url to the file, you just saved
// and than put the image in your browser.
});
});
</script>
<script src="js/jquery-3.2.1.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>