万象优图接口 swift

Posted by Roy on 2017-04-17
954字预计6分
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// UIImageWriteToSavedPhotosAlbum(newImage, self, #selector(savedPhotosAlbum(image:didFinishSavingWithError:contextInfo:)), nil)
func savedPhotosAlbum(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: AnyObject) {
if error != nil {
print("存到相册失败")
} else {
print("存到相册成功")
}
}
// 检测给定图片中的所有人脸(Face)的位置和相应的面部属性。位置包括(x, y, w, h),面部属性包括性别(gender), 年龄(age), 表情(expression), 魅力(beauty), 眼镜(glass)和姿态(pitch,roll,yaw)。
func detect(){
// 1.get token
CloudManager.getToken { (Any) in
self.newPerson()
}
let url = "http://service.image.myqcloud.com/face/detect"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"mode":"0",
"url":"http://taoxi-1253464289.pictj.myqcloud.com/1491812091.71443.jpg"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
func faceIdentify(){
// 1.get token
CloudManager.getToken { (Any) in
self.faceIdentify()
}
let url = "http://service.image.myqcloud.com/face/identify"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"group_id":"contrastGroup",
"url":"http://taoxi-1253464289.costj.myqcloud.com/1492053505.00994.jpg"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
// 给定一个图片和一个Person,检查是否是同一个人。
func faceVerify(){
// 1.get token
CloudManager.getToken { (Any) in
self.faceVerify()
}
let url = "http://service.image.myqcloud.com/face/verify"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"person_id":"duyaohui",
"url":"http://taoxi-1253464289.costj.myqcloud.com/1492053504.97242.jpg"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
//获取1999916287842615047人脸信息
func getfaceinfo(){
// 1.get token
CloudManager.getToken { (Any) in
self.newPerson()
}
let url = "http://service.image.myqcloud.com/face/getfaceinfo"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"face_id":"1999916287842615047"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
//获取person信息
func getinfo(){
// 1.get token
CloudManager.getToken { (Any) in
self.newPerson()
}
let url = "http://service.image.myqcloud.com/face/getinfo"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"group_ids":[ "a007"],
"person_id": "demo_person_id_zh001"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
//增加人脸
func addface(){
// 1.get token
CloudManager.getToken { (Any) in
self.newPerson()
}
let url = "http://service.image.myqcloud.com/face/addface"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"group_ids":[ "a007"],
"person_id": "demo_person_id_zh001",
"urls": [
"http://taoxi-1253464289.pictj.myqcloud.com/1491467336.23696.jpg",
"http://taoxi-1253464289.pictj.myqcloud.com/1491812091.71443.jpg"
]]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters1, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}
//个体创建
func newPerson() {
// 1.get token
CloudManager.getToken { (Any) in
self.newPerson()
}
let url = "http://service.image.myqcloud.com/face/newperson"
let parameters1: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"group_ids":["contrastGroup"],
"person_id": "duyaohui",
"url": "http://taoxi-1253464289.costj.myqcloud.com/1492052506.05618.jpg"]
let parameters2: Parameters = [
"appid": "1253464289",
"bucket": "taoxi",
"group_ids":["contrastGroup"],
"person_id": "wangsong",
"url": "http://taoxi-1253464289.costj.myqcloud.com/1492052506.04147.jpg"]
let headers: HTTPHeaders = [
"Host": "service.image.myqcloud.com",
"Content-Type": "application/json",
"Authorization":CloudManager.share.sign
]
Alamofire.request(url, method: .post, parameters: parameters2, encoding: JSONEncoding.default,headers:headers).responseJSON { (responseObject) -> Void in
if responseObject.result.isSuccess {
let JSON = responseObject.result.value
if (JSON != nil) {
//成功
debugPrint(JSON!)
}
else {
//失败
}
}
if responseObject.result.isFailure {
let httpError: NSError = responseObject.result.error! as NSError
let statusCode = httpError.code
let error:NSDictionary = ["error" : httpError,"statusCode" : statusCode]
print(error)
}
}
}

Kommentare: