簡體   English   中英

如何在Objective-C中使用dlib的shape_predictor?

[英]How to use dlib's shape_predictor in Objective-C?

我正在嘗試為iOS應用程序實現dlib的面部標志性檢測。 在dlib的例子中,他們初始化shape_predictor:

// And we also need a shape_predictor.  This is the tool that will predict face
// landmark positions given an image and face bounding box.  Here we are just
// loading the model from the shape_predictor_68_face_landmarks.dat file you gave
// as a command line argument.
    shape_predictor sp;
    deserialize(argv[1]) >> sp;

我正在嘗試在Objective-C中做同樣的事情並且已經做到這一點:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"shape_predictor_68_face_landmarks" ofType:@"dat"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];

執行以下操作會給我一個錯誤“接收器類型'dlib :: shape_predictor'不是Objective-C類”

sp = [dlib::shape_predictor deserialize:myData];

假設您已在項目中正確設置了dlib庫(並包含了source.cpp文件),則需要一個.mm文件(Objective-C ++),您可以在其中執行以下操作:

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/opencv.h>
#include <dlib/image_io.h>

然后,您可以加載所需的dlib類,並使用常規C ++語法。 這是一個例子:

dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();
dlib::shape_predictor shapePredictor;

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *landmarkdat = [[NSString alloc] initWithFormat:@"%@/%s", mainBundle.bundlePath,"shape_predictor_68_face_landmarks.dat"];
dlib::deserialize(landmarkdat.UTF8String) >> shapePredictor;

注意:在我的項目中,我在project-> Target-> Build Phrases-> Copy bundle resources中添加了shape_predictor_68_face_landmarks.dat作為包資源,並檢查了復制按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM