-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture.html
More file actions
161 lines (149 loc) · 4.91 KB
/
capture.html
File metadata and controls
161 lines (149 loc) · 4.91 KB
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
<html>
<head>
<title>Capture document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<link rel="stylesheet" href="http://css-spinners.com/css/spinner/three-quarters.css" type="text/css">
<script lang="javascript/text">
// -------- SUBMIT CONTENT TO NODE.JS -> MONGO DB
//QueryString to Json
queryToJSON = function(queryString) {
var j, q;
q = queryString.split("&");
j = {};
$.each(q, function(i, arr) {
arr = arr.split('=');
return j[arr[0]] = arr[1];
});
return j;
}
$(document).ready(function(){
$("#capture").submit(function(e){
$("#bar").show();
var fd = {
meta: queryToJSON($(this).serialize()),
photo: {
contentType: 'image/png',
binary: canvas.toDataURL("image/png")
}
};
$.ajax({
url: "/contact",
type: "POST",
data: JSON.stringify(fd),
contentType: 'application/json',
processData: false,
success: function() {
bootbox.alert("Contact stored.", function() {
location.reload();
});
},
complete: function() {
$("#bar").hide();
}
});
// Avoid page redirection
e.preventDefault();
});
// -------- PREPARE IMAGE AND SUBMIT FOR RECOGNITION
$("#snap").click(function() {
$("#bar").show();
context.drawImage(video, 0, 0, 320, 240);
var fd = {
binary: canvas.toDataURL("image/png")
}
video.pause();
$.ajax({
url: "/recognize",
type: "POST",
data: JSON.stringify(fd),
contentType: 'application/json',
processData: false,
success: function(res) {
var out = JSON.parse(res);
console.log(out);
$('#age').val(out.age);
$('input[name=gender][value=' + out.gender + ']').prop('checked', true);
},
complete: function() {
$("#bar").hide();
}
});
});
var canvas = $("#canvas")[0],
context = canvas.getContext("2d"),
video = $("#video")[0],
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({ video:true,audio:false}, function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
},
function(error) { alert(error); }
);
}
else {
alert('Sorry, the browser you are using doesn\'t support getUserMedia');
return;
}
});
</script>
</head>
<body>
<div class="container-fluid" style="min-width:400px">
<h3>Add new person</h3>
<div class="jumbotron">
<form id="capture" action="#" method="post" class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-10">
<input type="text" name="name" id="name" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="gender">Gender:</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="male" />Male</label>
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="female" />Female</label>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Age:</label>
<div class="col-sm-10">
<input type="text" name="age" id="age" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="photo">Photo:</label>
<div class="col-sm-10">
<video id="video" width="320" height="240" autoplay></video>
<canvas id="canvas" width="320" height="240" style="display:none"></canvas>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="snap"></label>
<div class="col-sm-10">
<a class="btn btn-primary btn-lg" href="#" role="button" name="snap" id="snap">Capture</a>
<input type="submit" class="btn btn-primary btn-lg" value="Store" id="store" name="store">
<div id="bar" name="bar" style="vertical-align:middle; display:none" class="three-quarters-loader">
Loading…
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>