-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Riccardo Gallina
committed
Mar 30, 2022
1 parent
a41b025
commit da1d099
Showing
12 changed files
with
428 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,43 @@ | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.sertiscorp.oneml.face.*; | ||
|
||
public class FaceDetectorApp { | ||
|
||
public static void main(String[] args) throws IOException { | ||
Path basePath = Paths.get("", "../../assets/images"); | ||
String path = basePath "/face-detect-set/face/0.jpg"; | ||
|
||
LicenseManager manager = new LicenseManager(); | ||
manager.activateTrial(); | ||
FaceDetector detector = new FaceDetector(manager); | ||
Utils utils = new Utils(manager); | ||
|
||
Image img = utils.readImageCV(path); | ||
FaceDetectorResult result = detector.detect(img); | ||
System.out.println("Faces: " result.getSize()); | ||
|
||
BBoxList boxes = result.getBBoxes(); | ||
Landmark5List landmarks = result.getLandmarks(); | ||
ScoreList scores = result.getScores(); | ||
FacePoseList poses = result.getPoses(); | ||
|
||
for (int i = 0; i < result.getSize(); i ) { | ||
System.out.println("Face " i); | ||
System.out.println(String.format("Score: %.6f", scores.get(i))); | ||
System.out.println("Pose: " poses.get(i)); | ||
|
||
BBox box = boxes.get(i); | ||
String out = String.format("BBox: [(%.6f, %.6f), (%.6f, %.6f)]", box.getTop(), box.getLeft(), box.getBottom(), box.getRight()); | ||
System.out.println(out); | ||
|
||
int n_landmarks = Face.getLandmarkSize(); | ||
Landmark5 landmark = landmarks.get(i); | ||
for (int j = 0; j < n_landmarks; j ) { | ||
System.out.println(String.format("Landmark %d: (%.6f, %.6f)", j, landmark.getX().get(j), landmark.getY().get(j))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,47 @@ | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.io.IOException; | ||
|
||
import java.util.List; | ||
import java.util.StringJoiner; | ||
|
||
import java.util.stream.DoubleStream; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Collectors; | ||
import java.util.function.Supplier; | ||
|
||
import org.sertiscorp.oneml.face.*; | ||
|
||
public class FaceEmbedderApp { | ||
|
||
static String joinAsString(Iterable<Double> it) { | ||
StringJoiner joiner = new StringJoiner(", ", "[", "]"); | ||
for (Double i: it) { | ||
joiner.add(String.format("%.6f", i)); | ||
} | ||
|
||
return joiner.toString(); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
Path basePath = Paths.get("", "../../assets/images"); | ||
String path = basePath "/register-set/Colin_Powell/colin_powell_0074.jpg"; | ||
|
||
LicenseManager manager = new LicenseManager(); | ||
manager.activateTrial(); | ||
FaceEmbedder embedder = new FaceEmbedder(manager); | ||
Utils utils = new Utils(manager); | ||
|
||
Image img = utils.readImageCV(path); | ||
FaceEmbedderResult result = embedder.embed(img); | ||
|
||
System.out.println("Embedding size: " Face.getEmbeddingSize()); | ||
|
||
float[] embedding = result.getEmbedding(); | ||
Supplier<DoubleStream> supplier = () -> IntStream.range(0, embedding.length).mapToDouble(i -> embedding[i]); | ||
List<Double> sample = supplier.get().limit(5).boxed().collect(Collectors.toList()); | ||
|
||
System.out.println("Embedding sample: " joinAsString(sample)); | ||
System.out.println(String.format("Embedding sum: %.5f", supplier.get().sum())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,106 @@ | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.io.IOException; | ||
|
||
import java.util.List; | ||
import java.util.StringJoiner; | ||
|
||
import java.util.stream.DoubleStream; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Collectors; | ||
import java.util.function.Supplier; | ||
|
||
import org.sertiscorp.oneml.face.*; | ||
|
||
public class FaceIdApp { | ||
|
||
static String joinAsString(Iterable<Double> it) { | ||
StringJoiner joiner = new StringJoiner(", ", "[", "]"); | ||
for (Double i: it) { | ||
joiner.add(String.format("%.6f", i)); | ||
} | ||
|
||
return joiner.toString(); | ||
} | ||
|
||
static void print(FaceIdResult result) { | ||
System.out.println("Is identifiable: " booleanToInt(result.isIdentifiable())); | ||
System.out.println("Id: " result.getId()); | ||
System.out.println(String.format("Nearest node distance: %.6f", result.getNearestNodeDistance())); | ||
System.out.println(String.format("Combined distance: %.6f", result.getCombinedDistance())); | ||
} | ||
|
||
static void print(FaceIdResultList results) { | ||
for (FaceIdResult result: results) { | ||
print(result); | ||
} | ||
} | ||
|
||
static int booleanToInt(boolean val) { | ||
return val ? 1 : 0; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
Path basePath = Paths.get("", "../../assets/images"); | ||
|
||
LicenseManager manager = new LicenseManager(); | ||
manager.activateTrial(); | ||
Utils utils = new Utils(manager); | ||
|
||
String path1 = basePath "/register-set/Colin_Powell/colin_powell_0074.jpg"; | ||
Image img1 = utils.readImageCV(path1); | ||
|
||
String path2 = basePath "/register-set/Colin_Powell/colin_powell_0078.jpg"; | ||
Image img2 = utils.readImageCV(path2); | ||
|
||
String path3 = basePath "/register-set/George_Robertson/george_robertson_0000.jpg"; | ||
Image img3 = utils.readImageCV(path3); | ||
|
||
String path4 = basePath "/register-set/George_Robertson/george_robertson_0002.jpg"; | ||
Image img4 = utils.readImageCV(path4); | ||
|
||
FaceEmbedder embedder = new FaceEmbedder(manager); | ||
FaceId faceId = new FaceId(embedder, manager); | ||
|
||
// isTheSamePerson | ||
boolean same1 = faceId.isTheSamePerson(img1, img2); | ||
System.out.println("Is the same person: " booleanToInt(same1)); | ||
|
||
FaceEmbedderResult result = embedder.embed(img1); | ||
SamePersonResult sameResult = faceId.isTheSamePerson(result.getEmbedding(), img2); | ||
System.out.println("Is the same person: " booleanToInt(sameResult.getSame())); | ||
|
||
// registerId | ||
int size1 = faceId.registerId("Colin_Powell", result.getEmbedding()); | ||
System.out.println("Registered size is: " size1); | ||
|
||
Embedding emb_ = faceId.registerId("George_Robertson", img3); | ||
float[] emb = emb_.toArray(); | ||
Supplier<DoubleStream> supplier = () -> IntStream.range(0, emb.length).mapToDouble(i -> emb[i]); | ||
List<Double> sample = supplier.get().limit(5).boxed().collect(Collectors.toList()); | ||
System.out.println("Registered emb is: " joinAsString(sample)); | ||
|
||
// predict | ||
print(faceId.predict(img2)); | ||
|
||
// updateEmbeddingDynamically | ||
faceId.updateEmbeddingDynamically("George_Robertson", img3, emb); | ||
print(faceId.predict(img4)); | ||
|
||
faceId.updateEmbeddingDynamically("Colin_Powell", sameResult.getEmbedding(), result.getEmbedding()); | ||
|
||
print(faceId.predict(img1)); | ||
|
||
// updateEmbedding | ||
faceId.updateEmbedding("George_Robertson", emb); | ||
print(faceId.predict(img3)); | ||
|
||
// removeId | ||
faceId.removeId("George_Robertson"); | ||
faceId.removeId("Colin_Powell"); | ||
|
||
// getIds | ||
IdList idList = faceId.getIds(); | ||
System.out.println("Gallery size: " idList.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,72 @@ | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.sertiscorp.oneml.face.*; | ||
|
||
public class FaceVerificationApp { | ||
|
||
static int booleanToInt(boolean val) { | ||
return val ? 1 : 0; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
LicenseManager manager = new LicenseManager(); | ||
manager.activateTrial(); | ||
|
||
Path basePath = Paths.get("", "../../assets/images"); | ||
File file1 = new File(basePath "/register-set/Colin_Powell/colin_powell_0074.jpg"); | ||
File file2 = new File(basePath "/evaluate-set/Colin_Powell/colin_powell_0097.jpg"); | ||
File file3 = new File(basePath "/register-set/George_Robertson/george_robertson_0000.jpg"); | ||
File file4 = new File(basePath "/evaluate-set/George_Robertson/george_robertson_0009.jpg"); | ||
|
||
FaceEmbedder embedder = new FaceEmbedder(manager); | ||
FaceId faceId = new FaceId(embedder, manager); | ||
FaceDetector detector = new FaceDetector(manager); | ||
Utils utils = new Utils(manager); | ||
|
||
Image img1 = utils.readImageCV(file1.getAbsolutePath()); | ||
Image img2 = utils.readImageCV(file2.getAbsolutePath()); | ||
Image img3 = utils.readImageCV(file3.getAbsolutePath()); | ||
Image img4 = utils.readImageCV(file4.getAbsolutePath()); | ||
|
||
ImageBatch register_batch = new ImageBatch(); | ||
register_batch.add(img1); | ||
register_batch.add(img3); | ||
|
||
ImageBatch eval_batch = new ImageBatch(); | ||
eval_batch.add(img2); | ||
eval_batch.add(img4); | ||
|
||
FaceDetectorResultList register_results = detector.detect(register_batch); | ||
FaceDetectorResultList eval_results = detector.detect(eval_batch); | ||
|
||
Image align_img1 = utils.cropAlignFaceLandmark(img1, register_results.get(0).getLandmarks().get(0)); | ||
Image align_img3 = utils.cropAlignFaceLandmark(img3, register_results.get(1).getLandmarks().get(0)); | ||
Image align_img2 = utils.cropAlignFaceLandmark(img2, eval_results.get(0).getLandmarks().get(0)); | ||
Image align_img4 = utils.cropAlignFaceLandmark(img4, eval_results.get(1).getLandmarks().get(0)); | ||
|
||
faceId.registerId("colin_powell", align_img1); | ||
faceId.registerId("george_robertson", align_img3); | ||
|
||
ImageBatch predict_batch = new ImageBatch(); | ||
predict_batch.add(align_img2); | ||
predict_batch.add(align_img4); | ||
FaceIdResultList results = faceId.predict(predict_batch); | ||
|
||
// Run with registration & predict style to print scores for validating with other language applications | ||
// since isTheSamePerson API doesn't provide any score. | ||
System.out.println("First person nearest node distance: " String.format("%.8f", results.get(0).getNearestNodeDistance())); | ||
System.out.println("Second person nearest node distance: " String.format("%.8f", results.get(1).getNearestNodeDistance())); | ||
System.out.println("First person: " results.get(0).getId()); | ||
System.out.println("Second person: " results.get(1).getId()); | ||
|
||
// Also test the actual face verification API (IsTheSamePerson) | ||
boolean same1 = faceId.isTheSamePerson(img1, img2); | ||
System.out.println("Is the same person (colin_powell): " booleanToInt(same1)); | ||
|
||
boolean same2 = faceId.isTheSamePerson(img3, img4); | ||
System.out.println("Is the same person (george_robertson): " booleanToInt(same2)); | ||
} | ||
} |
Oops, something went wrong.