-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (63 loc) · 2.28 KB
/
script.js
File metadata and controls
71 lines (63 loc) · 2.28 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
// Code goes here
var app = angular.module('app', []);
app.factory('recognizeService', function($http) {
return {
recognize: function(imgLink) {
var url = 'https://wt-huyhoang8a5-gmail-com-0.run.webtask.io/idol-recognize';
return $http({
method: 'POST',
url,
data: {
url: imgLink
}
});
}
}
});
app.controller('mainCtrl', function($scope, recognizeService) {
$scope.isLoading = false;
$scope.$watch('imageLink', function(oldValue, newValue) {
$scope.faces = [];
$scope.faceDisplay = [];
});
// Gọi hàm này khi người dùng click button "Nhận diện"
$scope.recognize = function() {
if ($scope.isLoading)
return;
$scope.isLoading = true;
// Gọi hàm recognize của service
recognizeService.recognize($scope.imageLink).then(result => {
$scope.faces = result.data;
// Dựa vào kết quả trả về để set style động cho class idol-face
$scope.faceDisplay = result.data.map(rs => {
return {
style: {
top: rs.face.top + 'px',
left: rs.face.left + 'px',
width: rs.face.width + 'px',
height: rs.face.height + 'px'
},
name: rs.idol.name
}
});
$scope.isLoading = false;
});
}
// Danh sách ảnh để test
$scope.testImages = ["http://tse3.mm.bing.net/th?id=OIP.M62d737028ee51f22482fab76bdfe112do1&pid=15.1", "http://tse4.mm.bing.net/th?id=OIP.M93d1646690a0f345e561a80523529bb2o1&pid=15.1", "http://media.ngoisao.vn/resize_580/news/2014/11/30/miu-le-20.jpg", "http://static.giaoducthoidai.vn/uploaded/hainv/2016_01_27/images16422691452168028hotgirlhaiphongxinhnhumong191657_uzve.jpg?width=500"];
// Danh sách idol
$scope.idols = [
"Ngọc Trinh",
"Bà tưng",
"Hường Hana",
"Hoàng Thùy Linh",
"Elly Trần",
"Thuỷ Top",
"Tâm Tít",
"Midu",
"Miu Lê",
"Chi Pu",
"Khả Ngân",
"Angela Phương Trinh"
];
});