6 #include "VisageFeaturesDetector.h" 8 #include "VisageFaceRecognition.h" 9 #include <android/log.h> 10 #include <android/asset_manager.h> 11 #include <android/asset_manager_jni.h> 12 #include "LicenseString.h" 13 #include "VisageRendering.h" 16 #define LOG_TAG "DetectorWrapper" 17 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 18 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 21 #define PATH_TO_GALLERY "/Famous Actors/gallery" 24 #define SIMILARITY_THRESHOLD 0.65f 43 std::string pathToData;
51 float sim[TOP_N_FACES];
62 void Java_com_visagetechnologies_facedetectdemo_ImageDetectorView_AddToGallery(JNIEnv *env, jobject obj, jbyteArray image, jstring filename, jint width, jint height)
65 const char *imgName = env->GetStringUTFChars(filename, 0);
67 jbyte *f = env->GetByteArrayElements(image, 0);
68 VsImage *frame = vsCreateImage(vsSize(width, height), VS_DEPTH_8U, 3);
74 const char *pos = strchr(imgName,
'.');
75 int offset = (int)(pos - imgName);
76 strncat(name, imgName, offset);
79 int ret = m_visageFaceRecognition->
addDescriptor(frame, &recData, (
const char*)name);
82 vsReleaseImage(&frame);
86 static bool endsWith(
const std::string& str,
const std::string& suffix)
88 return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
98 const char *_appPath = env->GetStringUTFChars(appPath, 0);
99 className =
"com/visagetechnologies/facedetectdemo/RecognitionActivity";
102 std::string pathToLicense(_appPath + std::string(
"/") + licenseKey);
103 if (endsWith(licenseKey,
".vlc"))
104 initializeLicenseManager(env, obj, pathToLicense.c_str(),
AlertCallback);
106 initializeLicenseManager(env, obj, licenseKey.c_str(),
AlertCallback);
108 std::string path(_appPath);
110 std::string pathToCfgFile(_appPath + std::string(
"/") +
"Face Detector.cfg");
112 bool ret = m_visageFeaturesDetector->
Initialize();
114 path.append(
"/vfr/fr.tflite");
120 LOGI(
"Could not load required face recognition data files!");
132 if(m_visageFeaturesDetector == 0)
135 jbyte *f = env->GetByteArrayElements(frame, 0);
136 inputImage = vsCreateImage(vsSize(width, height), VS_DEPTH_8U, 3);
142 for (
int i = 0; i < facesRec; i++)
147 short *descriptor =
new short[DESCRIPTOR_SIZE];
148 const char* names[TOP_N_FACES];
152 LOGI(
"Descriptor was not successfully extracted");
155 int rec = m_visageFaceRecognition->
recognize(descriptor, TOP_N_FACES, names, sim);
157 LOGI(
"Number of faces for comparison needs to be larger than 0");
158 sprintf(result,
"%s %f", names[0], sim[0]);
163 LOGI(
"Face was not detected");
174 VisageRendering::Reset();
197 glHeight = glHeight*tmp/
glWidth;
207 LOGE(
"Could not load font");
211 LOGE(
"Could not load logo");
215 for (
int i = 0; i < facesRec; i++)
217 if (sim[0] > SIMILARITY_THRESHOLD)
230 vsReleaseImage(&inputImage);
231 vsReleaseImage(&logo);
232 vsReleaseImage(&font);
234 delete m_visageFaceRecognition;
235 m_visageFaceRecognition = 0;
236 delete m_visageFeaturesDetector;
237 m_visageFeaturesDetector = 0;
int height
Image height in pixels.
static void DisplayResults(FaceData *trackingData, int trackStat, int width, int height, VsImage *frame, int drawingOptions=DISPLAY_DEFAULT)
Method calls other methods for drawing the frame and tracking results.
void Java_com_visagetechnologies_facedetectdemo_ImageDetectorView_recognizeFace(JNIEnv *env, jobject obj, jbyteArray frame, jint width, jint height)
Method which performs face recognition on a given image.
int glHeight
Size of the OpenGL view.
Faces and facial features detector implementation.
float videoAspect
Aspect of the video.
void Java_com_visagetechnologies_facedetectdemo_RecognitionActivity_CleanUp(JNIEnv *env, jobject obj)
Method for cleaning up resources used by application.
VisageFaceRecognition class contains a face recognition algorithm capable of measuring similarity bet...
char * imageData
Pointer to aligned image data.
void Java_com_visagetechnologies_facedetectdemo_RecognitionActivity_InitRecognition(JNIEnv *env, jobject obj, jstring appPath)
Method for initializing the recognizer.
int addDescriptor(VsImage *image, FaceData *facedata, const char *name)
Extracts a face descriptor from the input RGB, RGBA or grayscale image and adds it to the gallery...
void AlertCallback(const char *warningMessage)
Callback method for license notification.
int width
Image width in pixels.
int extractDescriptor(FaceData *facedata, VsImage *image, short *descriptor)
Extracts the face descriptor for face recognition from a facial image.
bool is_initialized
If the model used in the VisageFaceRecognition is loaded and initialized successfully value of the is...
static void DisplayText(const char *displayText, float effectValue, float scale=1.0f)
Method used to display text with animation (fade in or fade out effect)
static void SetFontTexture(const VsImage *font_tex)
Method sets font texture.
int imageSize
Image data size in bytes (==image->height*image->widthStep in case of interleaved data) ...
int detectFacialFeatures(VsImage *frame, FaceData *output, int maxFaces=1, float minFaceScale=0.1f, float maxFaceScale=1.0f, bool outputOnly2DFeatures=false)
Performs faces and facial features detection in a still image.
bool Initialize()
Initializes the features detector.
int glWidth
Size of the OpenGL view.
int recognize(short *descriptor, int n, const char **names, float *similarities)
Compare a face to all faces in the current gallery and return n names of the most similar faces...
Face data structure, used as container for all face tracking and detection results.
int getDescriptorSize()
Gets the descriptor's size.
static void DisplayLogo(const VsImage *logo, int width, int height)
Method draws a logo in the upper right corner.
void Java_com_visagetechnologies_facedetectdemo_DetectorRenderer_displayIdentity(JNIEnv *env, jobject obj, jint width, jint height)
Method for displaying recognition results.