Skip to content

Commit bb1078e

Browse files
committed
implement all orientations
1 parent 74faab8 commit bb1078e

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

visionSamples/FaceTracker/app/src/main/cpp/native-lib.cpp

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,13 @@ Java_dlib_android_FaceRecognizer_recognizeFaces(JNIEnv *env,
244244
pixelscolor = (char *) pixelscolor + infocolor.stride;
245245
}
246246

247-
//dlib::save_bmp(img, "/sdcard/Download/tt.bmp");
247+
//dlib::save_bmp(img, "/sdcard/Download/res1.bmp");
248+
248249
std::vector<dlib::rectangle> dets = detector1(img);
249250
if (dets.size() == 0){
250251
return strarr;
251252
}
252253

253-
//LOGI("dets: %d", dets.size());
254-
255254
std::vector<matrix<rgb_pixel>> faces;
256255
for (auto face : dets)
257256
{
@@ -261,8 +260,6 @@ Java_dlib_android_FaceRecognizer_recognizeFaces(JNIEnv *env,
261260
faces.push_back(move(face_chip));
262261
}
263262

264-
//LOGI("faces: %d", faces.size());
265-
266263
std::vector<matrix<float, 0, 1>> face_descriptors = net1(faces);
267264

268265
for (size_t i = 0; i < face_descriptors.size(); ++i)
@@ -325,46 +322,46 @@ Java_dlib_android_FaceRecognizer_recognizeFace(JNIEnv *env, jobject instance, jo
325322
}
326323

327324
//todo: smth wrong with colors
328-
dlib::save_bmp(img, "/sdcard/Download/res.bmp");
329-
330-
// std::vector<dlib::rectangle> dets = detector(img);
331-
// LOGI("detected size %d", dets.size());
332-
//
333-
// float min_dist = 0.0;
334-
// if(dets.size() > 0 ){
335-
// auto face = dets.front();
336-
// std::vector<matrix<rgb_pixel>> faces;
337-
// int x = face.left();
338-
// int y = face.top();
339-
// int width = face.width();
340-
// int height = face.height();
341-
//
342-
// auto shape = sp(img, face);
343-
// matrix<rgb_pixel> face_chip;
344-
// extract_image_chip(img, get_face_chip_details(shape, 150, 0.25), face_chip);
345-
// faces.push_back(move(face_chip));
346-
//
347-
// std::vector<matrix<float, 0, 1>> face_descriptors = net(faces);
348-
//
349-
// if (face_descriptors.size() > 0)
350-
// {
351-
// matrix<float, 0, 1> face_desc = face_descriptors[0];
352-
// for (auto& i : known_faces) {
353-
// float dist = length(face_desc - i.second );
354-
// if (dist < min_dist){
355-
// min_dist = dist;
356-
// }
357-
// if( dist < FACE_RECOGNIZE_THRESH) //todo: extract thresh
358-
// {
359-
// LOGI("recognized");
360-
// return env->NewStringUTF(i.first.c_str());
361-
// }
362-
// }
363-
// }
364-
// LOGI("not recognized, max dist %0.2f", min_dist);
365-
// }
366-
//
367-
LOGI("unlocking pixels");
325+
//dlib::save_bmp(img, "/sdcard/Download/res.bmp");
326+
327+
std::vector<dlib::rectangle> dets = detector(img);
328+
LOGI("detected size %d", dets.size());
329+
330+
float min_dist = 0.0;
331+
if(dets.size() > 0 ){
332+
auto face = dets.front();
333+
std::vector<matrix<rgb_pixel>> faces;
334+
int x = face.left();
335+
int y = face.top();
336+
int width = face.width();
337+
int height = face.height();
338+
339+
auto shape = sp(img, face);
340+
matrix<rgb_pixel> face_chip;
341+
extract_image_chip(img, get_face_chip_details(shape, 150, 0.25), face_chip);
342+
faces.push_back(move(face_chip));
343+
344+
std::vector<matrix<float, 0, 1>> face_descriptors = net(faces);
345+
346+
if (face_descriptors.size() > 0)
347+
{
348+
matrix<float, 0, 1> face_desc = face_descriptors[0];
349+
for (auto& i : known_faces) {
350+
float dist = length(face_desc - i.second );
351+
if (dist < min_dist){
352+
min_dist = dist;
353+
}
354+
if( dist < FACE_RECOGNIZE_THRESH)
355+
{
356+
//LOGI("recognized");
357+
return env->NewStringUTF(i.first.c_str());
358+
}
359+
}
360+
}
361+
LOGI("not recognized, max dist %0.2f", min_dist);
362+
}
363+
364+
// LOGI("unlocking pixels");
368365
AndroidBitmap_unlockPixels(env, bmp);
369366

370367
std::string returnValue = "Unknown";

0 commit comments

Comments
 (0)