Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (bool)load {
- std::lock_guard<decltype(mutex)> guard(mutex);
- NSString *path = [[[NSBundle bundleWithIdentifier:@"ru.visionlabs.FaceEngine"] resourcePath] stringByAppendingPathComponent:kModelsDirectory];
- std::string configPath = std::string([path UTF8String]) + "/faceengine.conf";
- loaded = false;
- // Face engine objects
- // 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)
- // Note #2: SDK defines smart pointers for various object types named like IInterfacePtr.
- // Such objects implement reference counting to manage their life time. The smart pointers
- // will ensure that reference counting functions are called appropriately and the objects
- // are properly destroyed after use.
- fsdk::ISettingsProviderPtr config;
- // Create FaceEngine root SDK object config.
- config.acquire(fsdk::createSettingsProvider(configPath.c_str()));
- OUT("face engine data path: " << [path UTF8String]);
- // Create FaceEngine root SDK object
- if(!(engine = fsdk::acquire(fsdk::createFaceEngine()))) {
- OUT("Failed to create face engine");
- return false;
- }
- // change config to use mobile net extraction model
- config->setValue("DescriptorFactory::Settings", "useMobileNet", 1);
- engine->setSettingsProvider(config);
- engine->setDataDirectory([path UTF8String]);
- // MARK: Factories
- // MARK: SDK components
- // do not create if no such module
- // Create descriptor extractor
- // If you can't create it, it means you have FRONT END version
- if (!(descriptorExtractor = fsdk::acquire(engine->createExtractor()))) {
- OUT("Failed to create descriptor extractor->FaceEngine.framework is frontend version");
- hasExtraction = false;
- } else {
- hasExtraction = true;
- // Create descriptor matcher
- if (!(descriptorMatcher = fsdk::acquire(engine->createMatcher()))) {
- OUT("Failed to create descriptor matcher");
- return false;
- }
- }
- hasExtractionDecided = true;
- // Create MTCNN face and features detector.
- if (!(mtcnnFaceDetector = fsdk::acquire(engine->createDetector(fsdk::ODT_MTCNN)))) {
- OUT("Failed to create face detector instance.");
- return false;
- }
- // Create CNN warper.
- if (!(warper = fsdk::acquire(engine->createWarper()))) {
- OUT("Failed to create face warper instance.");
- return false;
- }
- // Create quality estimator.
- if (!(qualityEstimator = fsdk::acquire(engine->createQualityEstimator()))) {
- OUT("Failed to create image quality estimator instance.");
- return false;
- }
- // Create complex estimator.
- if (!(attributesEstimator = fsdk::acquire(engine->createAttributeEstimator()))) {
- OUT("Failed to create face attributes estimator instance.");
- return false;
- }
- // Create eye estimator
- if (!(eyeEstimator = fsdk::acquire(engine->createEyeEstimator()))) {
- OUT("Failed to create eye estimator instance.");
- return false;
- }
- // Create head pose estimator
- if (!(headPoseEstimator = fsdk::acquire(engine->createHeadPoseEstimator()))) {
- OUT("Failed to create head pose estimator instance.");
- return false;
- }
- // Create smile estimator
- if (!(smileEstimator = fsdk::acquire(engine->createSmileEstimator()))) {
- OUT("Failed to create smile estimator instance.");
- return false;
- }
- // Create gaze estimator
- if (!(gazeEstimator = fsdk::acquire(engine->createGazeEstimator()))) {
- OUT("Failed to create gaze estimator instance.");
- return false;
- }
- // Create emotions estimator
- if (!(emotionsEstimator = fsdk::acquire(engine->createEmotionsEstimator()))) {
- OUT("Failed to create emotions estimator instance.");
- return false;
- }
- // Create emotions estimator
- if (!(ethnicityEstimator = fsdk::acquire(engine->createEthnicityEstimator()))) {
- OUT("Failed to create ethnicity estimator instance.");
- return false;
- }
- loaded = true;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement