【问题标题】:Dlib image load error, unable to load imageDlib 图像加载错误,无法加载图像
【发布时间】:2018-02-01 21:42:28
【问题描述】:

我正在开发一个 iOs 应用程序,在该应用程序中我实现了 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

【问题讨论】:

  • 确保在导入文件时选中如果需要则复制项目
  • 我已将文件复制到项目文件夹中

标签: ios iphone dlib


【解决方案1】:

您需要为对我有用的图像提供捆绑路径。

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

注意:直接将图像添加到捆绑包中,不要将图像添加到资产文件夹。

【讨论】:

    猜你喜欢
    • 2013-12-21
    • 2023-03-24
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 2021-06-21
    相关资源
    最近更新 更多