2017-08-24 231 views
0

我正在开发一个iOs应用程序,其中我实现了Dlib库以获取图像中的面部标志点。以下是我实施的代码。Dlib图像加载错误,无法加载图像

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; 
dlib::array2d<dlib::rgb_pixel> img;  
dlib::load_image(img,"001.png"); 

但是当我运行在Xcode 8.3的代码我得到error.dlib::image_load_error: Unable to open file

+0

确保您检查**复制项目,如果需要**当您导入文件 –

+0

我已将该文件复制到项目文件夹 –

回答

0

您需要为图像这为我工作提供束路径。

NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]; 
    std::string fileName = [imagePath UTF8String]; 
    dlib::array2d<unsigned char> img; 
    load_image(img, fileName); 

注:直接添加图像捆绑不添加图像资产文件夹。