Skip to content

Commit 04a6bfe

Browse files
author
Riccardo Gallina
committed
Chore: implement memory management for all apps
1 parent d6cd3d5 commit 04a6bfe

24 files changed

+278
-222
lines changed

apps/android-camera/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
applicationId "org.sertiscorp.oneml.onemlcamera"
2828
minSdkVersion 23
2929
targetSdkVersion 30
30-
versionCode 8
30+
versionCode 9
3131
versionName "v0.9.0"
3232

3333
ndk {

apps/android-camera/app/src/main/java/org/sertiscorp/oneml/onemlcamera/CameraActivity.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,6 @@ public synchronized void onStop() {
273273
super.onStop();
274274
}
275275

276-
@Override
277-
public synchronized void onDestroy() {
278-
LOGGER.d("onDestroy " + this);
279-
super.onDestroy();
280-
}
281-
282276
protected synchronized void runInBackground(final Runnable r) {
283277
if (handler != null) {
284278
handler.post(r);

apps/android-camera/app/src/main/java/org/sertiscorp/oneml/onemlcamera/DetectorActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public class DetectorActivity extends CameraActivity implements OnImageAvailable
9595
private FloatingActionButton fabAdd;
9696

9797

98+
@Override
99+
protected void onDestroy() {
100+
super.onDestroy();
101+
faceDetector.delete();
102+
faceId.delete();
103+
utils.delete();
104+
}
105+
98106
@Override
99107
protected void onCreate(Bundle savedInstanceState) {
100108
super.onCreate(savedInstanceState);

apps/android-simple/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
applicationId "com.sertiscorp.oneml.onemlsimpleapp"
2828
minSdkVersion 23
2929
targetSdkVersion 30
30-
versionCode 8
30+
versionCode 9
3131
versionName "v0.9.0"
3232
multiDexEnabled true
3333

apps/android-simple/app/src/main/java/com/sertiscorp/oneml/onemlsimpleapp/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public class MainActivity extends AppCompatActivity {
4444
static final int REGISTER_IMAGE = 1; // The request code
4545
static final int PREDICT_IMAGE = 2; // The request code
4646

47+
@Override
48+
protected void onDestroy() {
49+
super.onDestroy();
50+
faceDetector.delete();
51+
faceEmbedder.delete();
52+
faceId.delete();
53+
utils.delete();
54+
}
55+
4756
@Override
4857
protected void onCreate(Bundle savedInstanceState) {
4958
super.onCreate(savedInstanceState);

apps/csharp/FaceDetectorApp.cs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,40 @@ static void Main(string[] args) {
55
LicenseManager manager = new LicenseManager();
66
manager.ActivateTrial();
77

8-
FaceDetector detector = new FaceDetector(manager);
9-
Utils utils = new Utils(manager);
10-
11-
string basePath = @"../../assets/images/";
12-
string path = basePath + @"face-detect-set/face/0.jpg";
13-
Image image = utils.ReadImageCV(path);
14-
FaceDetectorResult result = detector.Detect(image);
15-
Console.WriteLine("Faces: " + result.GetSize());
16-
17-
ScoreList scores = result.GetScores();
18-
BBoxList bboxes = result.GetBBoxes();
19-
Landmark5List landmarks = result.GetLandmarks();
20-
FacePoseList poses = result.GetPoses();
21-
StatusCodeList statuses = result.GetReturnStatus();
22-
23-
string precision = "F6";
24-
for (int i = 0; i < result.GetSize(); i++) {
25-
Console.WriteLine("Face " + i);
26-
Console.WriteLine("status: " + statuses[i]);
27-
Console.WriteLine("Score: " + scores[i].ToString(precision));
28-
Console.WriteLine("Pose: " + poses[i]);
29-
30-
BBox box = bboxes[i];
31-
string boxString = "BBox: [(" + box.top.ToString(precision) + ", " + box.left.ToString(precision) + ", " + box.bottom.ToString(precision) + ", " + box.right.ToString(precision) + ")]";
32-
Console.WriteLine(boxString);
33-
34-
Landmark5 landmark = landmarks[i];
35-
for (int j = 0; j < Face.GetLandmarkSize(); j++) {
36-
Console.WriteLine("Landmark " + j + ": (" + landmark.x[j].ToString(precision) + ", " + landmark.y[j].ToString(precision) + ")");
8+
using (FaceDetector detector = new FaceDetector(manager))
9+
using (Utils utils = new Utils(manager))
10+
{
11+
string basePath = @"../../assets/images/";
12+
string path = basePath + @"face-detect-set/face/0.jpg";
13+
Image image = utils.ReadImageCV(path);
14+
FaceDetectorResult result = detector.Detect(image);
15+
Console.WriteLine("Faces: " + result.GetSize());
16+
17+
ScoreList scores = result.GetScores();
18+
BBoxList bboxes = result.GetBBoxes();
19+
Landmark5List landmarks = result.GetLandmarks();
20+
FacePoseList poses = result.GetPoses();
21+
StatusCodeList statuses = result.GetReturnStatus();
22+
23+
string precision = "F6";
24+
for (int i = 0; i < result.GetSize(); i++) {
25+
Console.WriteLine("Face " + i);
26+
Console.WriteLine("status: " + statuses[i]);
27+
Console.WriteLine("Score: " + scores[i].ToString(precision));
28+
Console.WriteLine("Pose: " + poses[i]);
29+
30+
BBox box = bboxes[i];
31+
string boxString = "BBox: [(" + box.top.ToString(precision) + ", " + box.left.ToString(precision) + ", " + box.bottom.ToString(precision) + ", " + box.right.ToString(precision) + ")]";
32+
Console.WriteLine(boxString);
33+
34+
Landmark5 landmark = landmarks[i];
35+
for (int j = 0; j < Face.GetLandmarkSize(); j++) {
36+
Console.WriteLine("Landmark " + j + ": (" + landmark.x[j].ToString(precision) + ", " + landmark.y[j].ToString(precision) + ")");
37+
}
3738
}
38-
}
3939

40-
UsageReport report = detector.GetUsage();
41-
report.ToLog();
40+
UsageReport report = detector.GetUsage();
41+
report.ToLog();
42+
}
4243
}
4344
}

apps/csharp/FaceEmbedderApp.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@ static void Main(string[] args) {
2525
LicenseManager manager = new LicenseManager();
2626
manager.ActivateTrial();
2727

28-
FaceEmbedder embedder = new FaceEmbedder(manager);
29-
Utils utils = new Utils(manager);
30-
31-
string basePath = @"../../assets/images/";
32-
string path = basePath + @"register-set/Colin_Powell/colin_powell_0074.jpg";
33-
Image img = utils.ReadImageCV(path);
34-
FaceEmbedderResult result1 = embedder.Embed(img);
35-
Console.WriteLine("Original Embedding");
36-
PrintEmbedding(result1);
37-
38-
FaceEmbedderResult result2 = embedder.Embed(img, true);
39-
Console.WriteLine("Flipped Image Embedding");
40-
PrintEmbedding(result2);
41-
42-
UsageReport report = embedder.GetUsage();
43-
report.ToLog();
28+
using (FaceEmbedder embedder = new FaceEmbedder(manager))
29+
using (Utils utils = new Utils(manager))
30+
{
31+
string basePath = @"../../assets/images/";
32+
string path = basePath + @"register-set/Colin_Powell/colin_powell_0074.jpg";
33+
Image img = utils.ReadImageCV(path);
34+
FaceEmbedderResult result1 = embedder.Embed(img);
35+
Console.WriteLine("Original Embedding");
36+
PrintEmbedding(result1);
37+
38+
FaceEmbedderResult result2 = embedder.Embed(img, true);
39+
Console.WriteLine("Flipped Image Embedding");
40+
PrintEmbedding(result2);
41+
42+
UsageReport report = embedder.GetUsage();
43+
report.ToLog();
44+
}
4445
}
4546
}

apps/csharp/FaceIdApp.cs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,69 @@ static void Main(string[] args) {
2424
LicenseManager manager = new LicenseManager();
2525
manager.ActivateTrial();
2626

27-
FaceEmbedder embedder = new FaceEmbedder(manager);
28-
FaceId faceId = new FaceId(embedder, manager);
29-
Utils utils = new Utils(manager);
27+
using (FaceEmbedder embedder = new FaceEmbedder(manager))
28+
using (FaceId faceId = new FaceId(embedder, manager))
29+
using (Utils utils = new Utils(manager))
30+
{
31+
string basePath = @"../../assets/images";
3032

31-
string basePath = @"../../assets/images";
33+
string path1 = basePath + @"/register-set/Colin_Powell/colin_powell_0074.jpg";
34+
Image img1 = utils.ReadImageCV(path1);
3235

33-
string path1 = basePath + @"/register-set/Colin_Powell/colin_powell_0074.jpg";
34-
Image img1 = utils.ReadImageCV(path1);
36+
string path2 = basePath + @"/register-set/Colin_Powell/colin_powell_0078.jpg";
37+
Image img2 = utils.ReadImageCV(path2);
3538

36-
string path2 = basePath + @"/register-set/Colin_Powell/colin_powell_0078.jpg";
37-
Image img2 = utils.ReadImageCV(path2);
39+
string path3 = basePath + @"/register-set/George_Robertson/george_robertson_0000.jpg";
40+
Image img3 = utils.ReadImageCV(path3);
3841

39-
string path3 = basePath + @"/register-set/George_Robertson/george_robertson_0000.jpg";
40-
Image img3 = utils.ReadImageCV(path3);
42+
string path4 = basePath + @"/register-set/George_Robertson/george_robertson_0002.jpg";
43+
Image img4 = utils.ReadImageCV(path4);
4144

42-
string path4 = basePath + @"/register-set/George_Robertson/george_robertson_0002.jpg";
43-
Image img4 = utils.ReadImageCV(path4);
45+
// isTheSamePerson
46+
bool same1 = faceId.IsTheSamePerson(img1, img2);
47+
Console.WriteLine("Is the same person: " + BooleanToInt(same1));
4448

45-
// isTheSamePerson
46-
bool same1 = faceId.IsTheSamePerson(img1, img2);
47-
Console.WriteLine("Is the same person: " + BooleanToInt(same1));
49+
FaceEmbedderResult result = embedder.Embed(img1);
50+
SamePersonResult sameResult = faceId.IsTheSamePerson(result.GetEmbedding(), img2);
51+
Console.WriteLine("Is the same person: " + BooleanToInt(sameResult.first));
4852

49-
FaceEmbedderResult result = embedder.Embed(img1);
50-
SamePersonResult sameResult = faceId.IsTheSamePerson(result.GetEmbedding(), img2);
51-
Console.WriteLine("Is the same person: " + BooleanToInt(sameResult.first));
53+
// registerId
54+
int size1 = faceId.RegisterId("Colin_Powell", result.GetEmbedding());
55+
Console.WriteLine("Registered size is: " + size1);
5256

53-
// registerId
54-
int size1 = faceId.RegisterId("Colin_Powell", result.GetEmbedding());
55-
Console.WriteLine("Registered size is: " + size1);
57+
Embedding emb = faceId.RegisterId("George_Robertson", img3);
58+
string embSample = "[";
59+
for (int i = 0; i < 5; i++) {
60+
embSample += emb[i].ToString("F6") + ", ";
61+
}
62+
embSample = embSample.Substring(0, embSample.Length-2) + "]";
63+
Console.WriteLine("Registered emb is: " + embSample);
5664

57-
Embedding emb = faceId.RegisterId("George_Robertson", img3);
58-
string embSample = "[";
59-
for (int i = 0; i < 5; i++) {
60-
embSample += emb[i].ToString("F6") + ", ";
61-
}
62-
embSample = embSample.Substring(0, embSample.Length-2) + "]";
63-
Console.WriteLine("Registered emb is: " + embSample);
64-
65-
// predict
66-
Print(faceId.Predict(img2));
65+
// predict
66+
Print(faceId.Predict(img2));
6767

68-
// updateEmbeddingDynamically
69-
faceId.UpdateEmbeddingDynamically("George_Robertson", img3, emb);
70-
Print(faceId.Predict(img4));
68+
// updateEmbeddingDynamically
69+
faceId.UpdateEmbeddingDynamically("George_Robertson", img3, emb);
70+
Print(faceId.Predict(img4));
7171

72-
faceId.UpdateEmbeddingDynamically("Colin_Powell", sameResult.second, result.GetEmbedding());
72+
faceId.UpdateEmbeddingDynamically("Colin_Powell", sameResult.second, result.GetEmbedding());
7373

74-
Print(faceId.Predict(img1));
74+
Print(faceId.Predict(img1));
7575

76-
// updateEmbedding
77-
faceId.UpdateEmbedding("George_Robertson", emb);
78-
Print(faceId.Predict(img3));
76+
// updateEmbedding
77+
faceId.UpdateEmbedding("George_Robertson", emb);
78+
Print(faceId.Predict(img3));
7979

80-
// removeId
81-
faceId.RemoveId("George_Robertson");
82-
faceId.RemoveId("Colin_Powell");
80+
// removeId
81+
faceId.RemoveId("George_Robertson");
82+
faceId.RemoveId("Colin_Powell");
8383

84-
// getIds
85-
IdList idList = faceId.GetIds();
86-
Console.WriteLine("Gallery size: " + idList.Count());
84+
// getIds
85+
IdList idList = faceId.GetIds();
86+
Console.WriteLine("Gallery size: " + idList.Count());
8787

88-
UsageReport report = faceId.GetUsage();
89-
report.ToLog();
88+
UsageReport report = faceId.GetUsage();
89+
report.ToLog();
90+
}
9091
}
9192
}

apps/csharp/FacePadApp.cs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,35 @@ static void Main(string[] args) {
55
LicenseManager manager = new LicenseManager();
66
manager.ActivateTrial();
77

8-
FacePad pad_rgb = new FacePad(PadType.Rgb, manager);
9-
FacePad pad_paper = new FacePad(PadType.Paper, manager);
10-
Utils utils = new Utils(manager);
11-
12-
// PAD RGB
13-
string basePath = @"../../../assets/images/";
14-
string path = basePath + @"pad-rgb-set/spoof/1.jpg";
15-
Image image = utils.ReadImageCV(path);
16-
FacePadResult result = pad_rgb.Classify(image);
17-
18-
string precision = "F6";
19-
Console.WriteLine("Status: " + result.GetReturnStatus());
20-
Console.WriteLine("Spoof probability: " + result.GetSpoofProb().ToString(precision));
21-
Console.WriteLine("Spoof classification: " + result.IsSpoof());
22-
23-
UsageReport report = pad_rgb.GetUsage();
24-
report.ToLog();
25-
26-
// PAD PAPER
27-
path = basePath + @"pad-paper-set/spoof/1.jpg";
28-
image = utils.ReadImageCV(path);
29-
result = pad_paper.Classify(image);
30-
31-
Console.WriteLine("Status: " + result.GetReturnStatus());
32-
Console.WriteLine("Spoof probability: " + result.GetSpoofProb().ToString(precision));
33-
Console.WriteLine("Spoof classification: " + result.IsSpoof());
34-
35-
report = pad_paper.GetUsage();
36-
report.ToLog();
8+
using (FacePad pad_rgb = new FacePad(PadType.Rgb, manager))
9+
using (FacePad pad_paper = new FacePad(PadType.Paper, manager))
10+
using (Utils utils = new Utils(manager))
11+
{
12+
// PAD RGB
13+
string basePath = @"../../../assets/images/";
14+
string path = basePath + @"pad-rgb-set/spoof/1.jpg";
15+
Image image = utils.ReadImageCV(path);
16+
FacePadResult result = pad_rgb.Classify(image);
17+
18+
string precision = "F6";
19+
Console.WriteLine("Status: " + result.GetReturnStatus());
20+
Console.WriteLine("Spoof probability: " + result.GetSpoofProb().ToString(precision));
21+
Console.WriteLine("Spoof classification: " + result.IsSpoof());
22+
23+
UsageReport report = pad_rgb.GetUsage();
24+
report.ToLog();
25+
26+
// PAD PAPER
27+
path = basePath + @"pad-paper-set/spoof/1.jpg";
28+
image = utils.ReadImageCV(path);
29+
result = pad_paper.Classify(image);
30+
31+
Console.WriteLine("Status: " + result.GetReturnStatus());
32+
Console.WriteLine("Spoof probability: " + result.GetSpoofProb().ToString(precision));
33+
Console.WriteLine("Spoof classification: " + result.IsSpoof());
34+
35+
report = pad_paper.GetUsage();
36+
report.ToLog();
37+
}
3738
}
3839
}

0 commit comments

Comments
 (0)