|
9 | 9 | * This quickstart contains: |
10 | 10 | * - Detect Faces: detect a face or faces in an image and URL |
11 | 11 | * - 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 |
12 | 14 | * |
13 | 15 | * Prerequisites: |
14 | 16 | * - 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) { |
72 | 74 | System.out.println("============== Find Similar =============="); |
73 | 75 | // Finds a similar face in group image. Returns a list of UUIDs and prints them. |
74 | 76 | 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); |
75 | 81 |
|
76 | 82 | System.out.println("============== Identify =============="); |
77 | 83 | // Groups similar photos of a person, then uses that group |
@@ -132,6 +138,52 @@ public static List<UUID> findSimilar(FaceAPI client, List<UUID> singleFaceList, |
132 | 138 | /** |
133 | 139 | * END - Find Similar |
134 | 140 | */ |
| 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 | + */ |
135 | 187 |
|
136 | 188 | /** |
137 | 189 | * Identify Faces |
|
0 commit comments