Advertisement
Guest User

Untitled

a guest
Sep 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (bool)load {
  2.     std::lock_guard<decltype(mutex)> guard(mutex);
  3.     NSString *path = [[[NSBundle bundleWithIdentifier:@"ru.visionlabs.FaceEngine"] resourcePath] stringByAppendingPathComponent:kModelsDirectory];
  4.     std::string configPath = std::string([path UTF8String]) + "/faceengine.conf";
  5.    
  6.     loaded = false;
  7.    
  8.     // Face engine objects
  9.    
  10.     // Note #1: You don't have to create all objects at once. You might wanna do creation on demand of specific function, because loaded FaceEngine objects allocate a lot of memory and take some time to load (up to hundreds of millisecs)
  11.     // Note #2: SDK defines smart pointers for various object types named like IInterfacePtr.
  12.     // Such objects implement reference counting to manage their life time. The smart pointers
  13.     // will ensure that reference counting functions are called appropriately and the objects
  14.     // are properly destroyed after use.
  15.     fsdk::ISettingsProviderPtr config;
  16.    
  17.     // Create FaceEngine root SDK object config.
  18.     config.acquire(fsdk::createSettingsProvider(configPath.c_str()));
  19.    
  20.     OUT("face engine data path: " << [path UTF8String]);
  21.    
  22.     // Create FaceEngine root SDK object
  23.     if(!(engine = fsdk::acquire(fsdk::createFaceEngine()))) {
  24.         OUT("Failed to create face engine");
  25.         return false;
  26.     }
  27.    
  28.     // change config to use mobile net extraction model
  29.     config->setValue("DescriptorFactory::Settings", "useMobileNet", 1);
  30.     engine->setSettingsProvider(config);
  31.     engine->setDataDirectory([path UTF8String]);
  32.    
  33.     // MARK: Factories
  34.     // MARK: SDK components
  35.     // do not create if no such module
  36.     // Create descriptor extractor
  37.     // If you can't create it, it means you have FRONT END version
  38.     if (!(descriptorExtractor = fsdk::acquire(engine->createExtractor()))) {
  39.         OUT("Failed to create descriptor extractor->FaceEngine.framework is frontend version");
  40.         hasExtraction = false;
  41.     } else {
  42.         hasExtraction = true;
  43.        
  44.         // Create descriptor matcher
  45.         if (!(descriptorMatcher = fsdk::acquire(engine->createMatcher()))) {
  46.             OUT("Failed to create descriptor matcher");
  47.             return false;
  48.         }
  49.     }
  50.    
  51.     hasExtractionDecided = true;
  52.    
  53.     // Create MTCNN face and features detector.
  54.     if (!(mtcnnFaceDetector = fsdk::acquire(engine->createDetector(fsdk::ODT_MTCNN)))) {
  55.         OUT("Failed to create face detector instance.");
  56.         return false;
  57.     }
  58.    
  59.     // Create CNN warper.
  60.     if (!(warper = fsdk::acquire(engine->createWarper()))) {
  61.         OUT("Failed to create face warper instance.");
  62.         return false;
  63.     }
  64.    
  65.     // Create quality estimator.
  66.     if (!(qualityEstimator = fsdk::acquire(engine->createQualityEstimator()))) {
  67.         OUT("Failed to create image quality estimator instance.");
  68.         return false;
  69.     }
  70.    
  71.     // Create complex estimator.
  72.     if (!(attributesEstimator = fsdk::acquire(engine->createAttributeEstimator()))) {
  73.         OUT("Failed to create face attributes estimator instance.");
  74.         return false;
  75.     }
  76.    
  77.     // Create eye estimator
  78.     if (!(eyeEstimator = fsdk::acquire(engine->createEyeEstimator()))) {
  79.         OUT("Failed to create eye estimator instance.");
  80.         return false;
  81.     }
  82.    
  83.     // Create head pose estimator
  84.     if (!(headPoseEstimator = fsdk::acquire(engine->createHeadPoseEstimator()))) {
  85.         OUT("Failed to create head pose estimator instance.");
  86.         return false;
  87.     }
  88.    
  89.     // Create smile estimator
  90.     if (!(smileEstimator = fsdk::acquire(engine->createSmileEstimator()))) {
  91.         OUT("Failed to create smile estimator instance.");
  92.         return false;
  93.     }
  94.    
  95.     // Create gaze estimator
  96.     if (!(gazeEstimator = fsdk::acquire(engine->createGazeEstimator()))) {
  97.         OUT("Failed to create gaze estimator instance.");
  98.         return false;
  99.     }
  100.    
  101.     // Create emotions estimator
  102.     if (!(emotionsEstimator = fsdk::acquire(engine->createEmotionsEstimator()))) {
  103.         OUT("Failed to create emotions estimator instance.");
  104.         return false;
  105.     }
  106.    
  107.     // Create emotions estimator
  108.     if (!(ethnicityEstimator = fsdk::acquire(engine->createEthnicityEstimator()))) {
  109.         OUT("Failed to create ethnicity estimator instance.");
  110.         return false;
  111.     }
  112.    
  113.     loaded = true;
  114.    
  115.     return true;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement