-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (149 loc) · 5.43 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.77.0.min.js"></script>
<style>
.thumbnail img {
height: 180px;
max-width: 171px;
}
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
</style>
</head>
<body>
<div class="container">
<div class="row" style="margin-top: 50px; margin-bottom: 30px; text-align: center">
<form class="form-inline">
<label for="exampleInputName2" style="margin-right: 20px">Search by picture</label>
<span class="btn btn-primary btn-file">
Upload picture <input type="file" id="searchphoto">
</span>
</form>
</div>
<hr>
<div id="faces" class="row">
</div>
</div>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button id="similar" type="button" class="btn btn-warning" style="float: left; padding: 5px 50px">Find similar faces</button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<img src="" style="max-width: 300px; max-height: 300px; margin: 10px;" align="left">
<h3></h3>
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
AWS.config.update({
accessKeyId: "AKIAIACAV2QTUVXMA2UA",
secretAccessKey: ""
});
var s3 = new AWS.S3({region: "us-east-1"});
var rekognition = new AWS.Rekognition({region: "us-east-1"});
$.getJSON("faces.json", function(json) {
thumbnail(Object.keys(json).map(function(face){ return json[face]; }));
$('a.thumbnail').click(function(){
var face = json[$(this).data('id')];
$('#myModal .modal-body img').attr('src', 'https://s3.amazonaws.com/icofaces/' + face.id + '.jpg');
if (face.url) {
$('#myModal .modal-body h3').html('<a href="' + face.url + '" target="_blank">' + face.name + '</a>');
} else {
$('#myModal .modal-body h3').text(face.name);
}
$('#myModal .modal-body p').html(face.role + ' of <b><a href="' + face.site + '" target="_blank">' + face.project + '</a></b>');
$('#myModal #similar').data('face', face.face);
$('#myModal').modal();
return false;
});
$('#myModal #similar').click(function(){
$('#myModal').modal('hide');
console.log('search by', $(this).data('face'));
rekognition.searchFaces({
CollectionId: "icofaces",
FaceId: $(this).data('face'),
FaceMatchThreshold: 70,
MaxFaces: 10
}, function(err, data) {
if(err) return alert('Error');
if(data && data.FaceMatches) {
thumbnail(data.FaceMatches.map(function(face){
return json[face.Face.ExternalImageId];
}));
}
});
});
$(document).on('change', '#searchphoto', function() {
var file = document.getElementById('searchphoto').files[0];
s3.upload({
Bucket: 'icosearch',
Key: file.name,
Body: file,
ACL: 'public-read'
}, function(err, data) {
if(err) return alert('Error');
rekognition.searchFacesByImage({
CollectionId: "icofaces",
FaceMatchThreshold: 70,
MaxFaces: 10,
Image: {
S3Object: {
Bucket: data.Bucket,
Name: data.Key
}
}
}, function(err, data) {
if(err) return alert('Error');
if(data && data.FaceMatches) {
thumbnail(data.FaceMatches.map(function(face){
return json[face.Face.ExternalImageId];
}));
}
});
});
});
});
function thumbnail(faces){
if (!faces.length) {
return $('#faces').html('<h3 align="center">Not found any similar faces</h2>');
}
$('#faces').html('');
faces.forEach(function(face) {
$('#faces').append('<div class="col-xs-6 col-md-3"><a href="#" data-id="'
+ face.id + '" class="thumbnail"><img src="https://s3.amazonaws.com/icofaces/'
+ face.id + '.jpg" alt="' + face.name + '"></a></div>');
});
}
</script>
</body>
</html>