Skip to content

Commit bcf23b2

Browse files
authored
Added Verify example
1 parent 0f5c371 commit bcf23b2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

java/Face/FaceQuickstart.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* This quickstart contains:
1010
* - Detect Faces: detect a face or faces in an image and URL
1111
* - Find Similar: find face similar to the single-faced image in the group image
12+
* - Verify: with 2 images, check if they are the same person or different people
13+
* - Identify: with grouped images of the same person, use group to find similar faces in another image
1214
*
1315
* Prerequisites:
1416
* - Create a lib folder in the root directory of your project, then add the jars from dependencies.txt
@@ -72,6 +74,10 @@ public static void main(String[] args) {
7274
System.out.println("============== Find Similar ==============");
7375
// Finds a similar face in group image. Returns a list of UUIDs and prints them.
7476
findSimilar(client, singleFaceID, groupFaceIDs, groupImageName);
77+
78+
System.out.println("============== Verify ==============");
79+
// Checks if 2 photos are of the same or different person.
80+
verify(client, IMAGE_BASE_URL);
7581

7682
System.out.println("============== Identify ==============");
7783
// Groups similar photos of a person, then uses that group
@@ -132,6 +138,52 @@ public static List<UUID> findSimilar(FaceAPI client, List<UUID> singleFaceList,
132138
/**
133139
* END - Find Similar
134140
*/
141+
142+
/**
143+
* Verify
144+
* With 2 photos, compare them to check if they are the same or different person.
145+
*/
146+
public static void verify(FaceAPI client, String imageBaseURL) {
147+
148+
// Source images to use for the query
149+
String sourceImage1 = "Family1-Dad3.jpg";
150+
String sourceImage2 = "Family1-Son1.jpg";
151+
152+
// The target images to find similarities in.
153+
List<String> targetImages = new ArrayList<>();
154+
targetImages.add("Family1-Dad1.jpg");
155+
targetImages.add("Family1-Dad2.jpg");
156+
157+
// Detect faces in the source images
158+
List<UUID> source1ID = detectFaces(client, imageBaseURL + sourceImage1, sourceImage1);
159+
List<UUID> source2ID = detectFaces(client, imageBaseURL + sourceImage2, sourceImage2);
160+
161+
// Create list to hold target image IDs
162+
List<UUID> targetIDs = new ArrayList<>();
163+
164+
// Detect the faces in the target images
165+
for (String face : targetImages) {
166+
List<UUID> faceId = detectFaces(client, imageBaseURL + face, face);
167+
targetIDs.add(faceId.get(0));
168+
}
169+
170+
// Verification example for faces of the same person.
171+
VerifyResult sameResult = client.faces().verifyFaceToFace(source1ID.get(0), targetIDs.get(0));
172+
System.out.println(sameResult.isIdentical() ?
173+
"Faces from " + sourceImage1 + " & " + targetImages.get(0) + " are of the same person." :
174+
"Faces from " + sourceImage1 + " & " + targetImages.get(0) + " are different people.");
175+
176+
// Verification example for faces of different persons.
177+
VerifyResult differentResult = client.faces().verifyFaceToFace(source2ID.get(0), targetIDs.get(0));
178+
System.out.println(differentResult.isIdentical() ?
179+
"Faces from " + sourceImage2 + " & " + targetImages.get(1) + " are of the same person." :
180+
"Faces from " + sourceImage2 + " & " + targetImages.get(1) + " are different people.");
181+
182+
System.out.println();
183+
}
184+
/**
185+
* END - Verify
186+
*/
135187

136188
/**
137189
* Identify Faces

0 commit comments

Comments
 (0)