2017-08-24 189 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); 

注:直接添加圖像捆綁不添加圖像資產文件夾。