-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathface_test.go
167 lines (134 loc) · 4.14 KB
/
face_test.go
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
package face_test
import (
"fmt"
"log"
"os"
"testing"
. "github.com/kkdai/oxford-face"
)
var API_KEY string
const (
// The same man
//id: 4541fc12-55f2-4eae-b548-2310188fdb8f
imageURL1_1 string = "https://oxfordportal.blob.core.windows.net/face/demov1/verification1-1.jpg"
//id: e71470cc-64f3-4cda-91e3-a8e7d9f99d48
imageURL1_2 string = "https://oxfordportal.blob.core.windows.net/face/demov1/verification1-2.jpg"
// The same woman
//id: 075afb27-00e5-465b-b8ee-726369bf2396
imageURL2_1 string = "https://oxfordportal.blob.core.windows.net/face/demov1/verification3-1.jpg"
//id: 06b04805-0a97-425d-a12b-36301f91797e
imageURL2_2 string = "https://oxfordportal.blob.core.windows.net/face/demov1/verification3-2.jpg"
)
func init() {
API_KEY = os.Getenv("MSFT_KEY")
if API_KEY == "" {
fmt.Println("Please export your key to environment first, `export MSFT_KEY=12234`")
}
}
func TestFaceDetect(t *testing.T) {
if API_KEY == "" {
return
}
client := NewFace(API_KEY)
_, err := client.DetectUrl(nil, "")
if err == nil {
t.Error("Error happen on face detect URL: imput empty")
}
_, err = client.DetectUrl(nil, imageURL1_1)
if err != nil {
t.Error("Error happen on face detect URL")
}
param := DetectParameters{RceturnFaceIdcdd: true, ReturnFaceLandmarks: true, ReturnFaceAttributes: "age,gender"}
res1, err := client.DetectUrl(¶m, imageURL1_1)
if err != nil {
t.Error("Error happen on face detect URL with option")
}
ret := NewFaceResponse(res1)
log.Println("Url1-1 detect:", ret)
res1, err = client.DetectUrl(¶m, imageURL1_2)
if err != nil {
t.Error("Error happen on face detect URL with option")
}
ret = NewFaceResponse(res1)
log.Println("Url1-2 detect:", ret)
// woman
res1, err = client.DetectUrl(¶m, imageURL2_1)
if err != nil {
t.Error("Error happen on face detect URL with option")
}
ret = NewFaceResponse(res1)
log.Println("Url2-1 detect:", ret)
res1, err = client.DetectUrl(¶m, imageURL2_2)
if err != nil {
t.Error("Error happen on face detect URL with option")
}
ret = NewFaceResponse(res1)
log.Println("Url2-2 detect:", ret)
res2, err := client.DetectFile(¶m, "test_data/verification1-1.jpg")
if err != nil {
t.Error("Error happen on face detect URL with option")
}
ret2 := NewFaceResponse(res2)
log.Println("File detect:", ret2)
}
func TestFaceSimilar(t *testing.T) {
if API_KEY == "" {
return
}
client := NewFace(API_KEY)
param := DetectParameters{RceturnFaceIdcdd: true, ReturnFaceLandmarks: true, ReturnFaceAttributes: "age,gender"}
var faceList []string
res1, err := client.DetectFile(¶m, "test_data/verification1-1.jpg")
if err != nil {
t.Error("Error happen on face detect URL with option")
}
face1 := NewFaceResponse(res1)
if face1 == nil {
t.Error("json result failed.")
}
faceList = append(faceList, face1[0].Faceid)
res2, err := client.DetectFile(¶m, "test_data/verification1-2.jpg")
if err != nil {
t.Error("Error happen on face detect URL with option")
}
face2 := NewFaceResponse(res2)
if face2 == nil {
t.Error("json result failed.")
}
faceList = append(faceList, face2[0].Faceid)
result, err := client.FindSimilarFromList(faceList[0], faceList, 20)
if err != nil {
t.Error("Error happen on similar:" + err.Err.Error())
log.Println("Ret:", result)
}
log.Println("Ret:", string(result))
}
func TestFaceGroup(t *testing.T) {
if API_KEY == "" {
return
}
var faceList []string
faceList = append(faceList, "4541fc12-55f2-4eae-b548-2310188fdb8f")
faceList = append(faceList, "e71470cc-64f3-4cda-91e3-a8e7d9f99d48")
faceList = append(faceList, "075afb27-00e5-465b-b8ee-726369bf2396")
faceList = append(faceList, "06b04805-0a97-425d-a12b-36301f91797e")
client := NewFace(API_KEY)
res, err := client.GroupFaces(faceList)
if err != nil {
t.Error("Grouping error:", err)
}
log.Println("Grouping:", string(res))
}
func TestFaceVerify(t *testing.T) {
if API_KEY == "" {
return
}
source := "e71470cc-64f3-4cda-91e3-a8e7d9f99d48"
target := "4541fc12-55f2-4eae-b548-2310188fdb8f"
client := NewFace(API_KEY)
res, err := client.VerifyWithFace(source, target)
if err != nil {
t.Error("Verify error:", err)
}
log.Println("Verify:", string(res))
}