Commit 1c5941d3a1ecc5854f4549f4cd8beb891233d593
Merge pull request #279 from biometrics/expose_pp5_context
Expose certain PP5 context properties in PP5EnrollTransform
Showing
1 changed file
with
63 additions
and
13 deletions
openbr/plugins/pp5.cpp
| @@ -46,7 +46,7 @@ class PP5Initializer : public Initializer | @@ -46,7 +46,7 @@ class PP5Initializer : public Initializer | ||
| 46 | { | 46 | { |
| 47 | TRY(ppr_initialize_sdk(qPrintable(Globals->sdkPath + "/share/openbr/models/pp5/"), my_license_id, my_license_key)) | 47 | TRY(ppr_initialize_sdk(qPrintable(Globals->sdkPath + "/share/openbr/models/pp5/"), my_license_id, my_license_key)) |
| 48 | Globals->abbreviations.insert("PP5","Open+Expand+PP5Enroll!PP5Gallery"); | 48 | Globals->abbreviations.insert("PP5","Open+Expand+PP5Enroll!PP5Gallery"); |
| 49 | - Globals->abbreviations.insert("PP5Register", "Open+PP5Enroll(true,requireLandmarks=true)+RenameFirst([eyeL,PP5_Landmark0_Right_Eye],Affine_0)+RenameFirst([eyeR,PP5_Landmark1_Left_Eye],Affine_1)"); | 49 | + Globals->abbreviations.insert("PP5Register", "Open+PP5Enroll(true,true,0.02,5,Frontal,1)+RenameFirst([eyeL,PP5_Landmark0_Right_Eye],Affine_0)+RenameFirst([eyeR,PP5_Landmark1_Left_Eye],Affine_1)"); |
| 50 | Globals->abbreviations.insert("PP5CropFace", "Open+PP5Enroll(true)+RenameFirst([eyeL,PP5_Landmark0_Right_Eye],Affine_0)+RenameFirst([eyeR,PP5_Landmark1_Left_Eye],Affine_1)+Affine(128,128,0.25,0.35)+Cvt(Gray)"); | 50 | Globals->abbreviations.insert("PP5CropFace", "Open+PP5Enroll(true)+RenameFirst([eyeL,PP5_Landmark0_Right_Eye],Affine_0)+RenameFirst([eyeR,PP5_Landmark1_Left_Eye],Affine_1)+Affine(128,128,0.25,0.35)+Cvt(Gray)"); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| @@ -67,24 +67,25 @@ struct PP5Context | @@ -67,24 +67,25 @@ struct PP5Context | ||
| 67 | { | 67 | { |
| 68 | ppr_context_type context; | 68 | ppr_context_type context; |
| 69 | 69 | ||
| 70 | - PP5Context() | 70 | + PP5Context(bool detectOnly = false, float adaptiveMinSize = 0.01f, int minSize = 4, ppr_landmark_range_type landmarkRange = PPR_LANDMARK_RANGE_COMPREHENSIVE, int searchPruningAggressiveness = 0) |
| 71 | { | 71 | { |
| 72 | ppr_settings_type default_settings = ppr_get_default_settings(); | 72 | ppr_settings_type default_settings = ppr_get_default_settings(); |
| 73 | 73 | ||
| 74 | default_settings.detection.adaptive_max_size = 1.f; | 74 | default_settings.detection.adaptive_max_size = 1.f; |
| 75 | - default_settings.detection.adaptive_min_size = 0.01f; | 75 | + default_settings.detection.adaptive_min_size = adaptiveMinSize; |
| 76 | default_settings.detection.detect_best_face_only = !Globals->enrollAll; | 76 | default_settings.detection.detect_best_face_only = !Globals->enrollAll; |
| 77 | default_settings.detection.enable = 1; | 77 | default_settings.detection.enable = 1; |
| 78 | - default_settings.detection.min_size = 4; | 78 | + default_settings.detection.min_size = minSize; |
| 79 | + default_settings.detection.search_pruning_aggressiveness = searchPruningAggressiveness; | ||
| 79 | default_settings.detection.use_serial_face_detection = 1; | 80 | default_settings.detection.use_serial_face_detection = 1; |
| 80 | 81 | ||
| 81 | default_settings.landmarks.enable = 1; | 82 | default_settings.landmarks.enable = 1; |
| 82 | - default_settings.landmarks.landmark_range = PPR_LANDMARK_RANGE_COMPREHENSIVE; | 83 | + default_settings.landmarks.landmark_range = landmarkRange; |
| 83 | default_settings.landmarks.manually_detect_landmarks = 0; | 84 | default_settings.landmarks.manually_detect_landmarks = 0; |
| 84 | 85 | ||
| 85 | - default_settings.recognition.automatically_extract_templates = 1; | ||
| 86 | - default_settings.recognition.enable_comparison = 1; | ||
| 87 | - default_settings.recognition.enable_extraction = 1; | 86 | + default_settings.recognition.automatically_extract_templates = !detectOnly; |
| 87 | + default_settings.recognition.enable_comparison = !detectOnly; | ||
| 88 | + default_settings.recognition.enable_extraction = !detectOnly; | ||
| 88 | default_settings.recognition.num_comparison_threads = 1; | 89 | default_settings.recognition.num_comparison_threads = 1; |
| 89 | default_settings.recognition.recognizer = PPR_RECOGNIZER_MULTI_POSE; | 90 | default_settings.recognition.recognizer = PPR_RECOGNIZER_MULTI_POSE; |
| 90 | TRY(ppr_initialize_context(default_settings, &context)) | 91 | TRY(ppr_initialize_context(default_settings, &context)) |
| @@ -249,6 +250,8 @@ struct PP5Context | @@ -249,6 +250,8 @@ struct PP5Context | ||
| 249 | /*! | 250 | /*! |
| 250 | * \ingroup transforms | 251 | * \ingroup transforms |
| 251 | * \brief Enroll faces in PP5 | 252 | * \brief Enroll faces in PP5 |
| 253 | + * | ||
| 254 | + * See PittPatt documentation for the relationship between minSize and pixel IPD. | ||
| 252 | * \author Josh Klontz \cite jklontz | 255 | * \author Josh Klontz \cite jklontz |
| 253 | * \author E. Taborsky \cite mmtaborsky | 256 | * \author E. Taborsky \cite mmtaborsky |
| 254 | */ | 257 | */ |
| @@ -256,11 +259,55 @@ class PP5EnrollTransform : public UntrainableMetaTransform | @@ -256,11 +259,55 @@ class PP5EnrollTransform : public UntrainableMetaTransform | ||
| 256 | { | 259 | { |
| 257 | Q_OBJECT | 260 | Q_OBJECT |
| 258 | Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly RESET reset_detectOnly STORED false) | 261 | Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly RESET reset_detectOnly STORED false) |
| 259 | - BR_PROPERTY(bool, detectOnly, false) | ||
| 260 | Q_PROPERTY(bool requireLandmarks READ get_requireLandmarks WRITE set_requireLandmarks RESET reset_requireLandmarks STORED false) | 262 | Q_PROPERTY(bool requireLandmarks READ get_requireLandmarks WRITE set_requireLandmarks RESET reset_requireLandmarks STORED false) |
| 263 | + Q_PROPERTY(float adaptiveMinSize READ get_adaptiveMinSize WRITE set_adaptiveMinSize RESET reset_adaptiveMinSize STORED false) | ||
| 264 | + Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false) | ||
| 265 | + Q_PROPERTY(LandmarkRange landmarkRange READ get_landmarkRange WRITE set_landmarkRange RESET reset_landmarkRange STORED false) | ||
| 266 | + Q_PROPERTY(int searchPruningAggressiveness READ get_searchPruningAggressiveness WRITE set_searchPruningAggressiveness RESET reset_searchPruningAggressiveness STORED false) | ||
| 267 | + | ||
| 268 | +public: | ||
| 269 | + enum LandmarkRange | ||
| 270 | + { | ||
| 271 | + Frontal = PPR_LANDMARK_RANGE_FRONTAL, | ||
| 272 | + Extended = PPR_LANDMARK_RANGE_EXTENDED, | ||
| 273 | + Full = PPR_LANDMARK_RANGE_FULL, | ||
| 274 | + Comprehensive = PPR_LANDMARK_RANGE_COMPREHENSIVE | ||
| 275 | + }; | ||
| 276 | + Q_ENUMS(LandmarkRange) | ||
| 277 | + | ||
| 278 | +private: | ||
| 279 | + BR_PROPERTY(bool, detectOnly, false) | ||
| 261 | BR_PROPERTY(bool, requireLandmarks, false) | 280 | BR_PROPERTY(bool, requireLandmarks, false) |
| 281 | + BR_PROPERTY(float, adaptiveMinSize, 0.01f) | ||
| 282 | + BR_PROPERTY(int, minSize, 4) | ||
| 283 | + BR_PROPERTY(LandmarkRange, landmarkRange, Comprehensive) | ||
| 284 | + BR_PROPERTY(int, searchPruningAggressiveness, 0) | ||
| 285 | + | ||
| 262 | Resource<PP5Context> contexts; | 286 | Resource<PP5Context> contexts; |
| 263 | 287 | ||
| 288 | + struct PP5ContextMaker : public ResourceMaker<PP5Context> | ||
| 289 | + { | ||
| 290 | + PP5ContextMaker(PP5EnrollTransform *pp5EnrollTransform) | ||
| 291 | + : pp5EnrollTransform(pp5EnrollTransform) {} | ||
| 292 | + | ||
| 293 | + private: | ||
| 294 | + PP5EnrollTransform *pp5EnrollTransform; | ||
| 295 | + | ||
| 296 | + PP5Context *make() const | ||
| 297 | + { | ||
| 298 | + return new PP5Context(pp5EnrollTransform->detectOnly, | ||
| 299 | + pp5EnrollTransform->adaptiveMinSize, | ||
| 300 | + pp5EnrollTransform->minSize, | ||
| 301 | + (ppr_landmark_range_type) pp5EnrollTransform->landmarkRange, | ||
| 302 | + pp5EnrollTransform->searchPruningAggressiveness); | ||
| 303 | + } | ||
| 304 | + }; | ||
| 305 | + | ||
| 306 | + void init() | ||
| 307 | + { | ||
| 308 | + contexts.setResourceMaker(new PP5ContextMaker(this)); | ||
| 309 | + } | ||
| 310 | + | ||
| 264 | void project(const Template &src, Template &dst) const | 311 | void project(const Template &src, Template &dst) const |
| 265 | { | 312 | { |
| 266 | if (Globals->enrollAll) | 313 | if (Globals->enrollAll) |
| @@ -293,10 +340,13 @@ class PP5EnrollTransform : public UntrainableMetaTransform | @@ -293,10 +340,13 @@ class PP5EnrollTransform : public UntrainableMetaTransform | ||
| 293 | 340 | ||
| 294 | for (int i=0; i<face_list.length; i++) { | 341 | for (int i=0; i<face_list.length; i++) { |
| 295 | ppr_face_type face = face_list.faces[i]; | 342 | ppr_face_type face = face_list.faces[i]; |
| 296 | - int extractable; | ||
| 297 | - TRY(ppr_is_template_extractable(context->context, face, &extractable)) | ||
| 298 | - if (!extractable && !detectOnly) continue; | ||
| 299 | - else foundFace = true; | 343 | + if (!detectOnly) { |
| 344 | + int extractable; | ||
| 345 | + TRY(ppr_is_template_extractable(context->context, face, &extractable)) | ||
| 346 | + if (!extractable) | ||
| 347 | + continue; | ||
| 348 | + } | ||
| 349 | + foundFace = true; | ||
| 300 | 350 | ||
| 301 | cv::Mat m; | 351 | cv::Mat m; |
| 302 | if (detectOnly) { | 352 | if (detectOnly) { |