2014-02-22 31 views
0

這段代碼應該拍攝幾張圖片並加載它們,試着在代碼中使用3種不同的方法,它們都不起作用。這裏的答案Getting OpenCV Error "Image step is wrong" in Fisherfaces.train() method不適合我,因爲我沒有這些庫。我該如何獲得Imread在Xcode中的工作

#include <opencv2/opencv.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv/cvaux.h> 
using namespace cv; 

int main(int argc, char** argv) 
{ 

    //The code segments commented (not mine) are taken from  http://docs.opencv.org/modules/contrib/doc/facerec/facerec_api.html 

    // holds images and labels (not mine) 
    cv::vector<cv::Mat> images; 
    cv::vector<int> labels; 


    //this doesnt assign anything to img 
    Mat img = cv::imread("/Users/STUFF/Desktop/Projects/OpenCV_testing/person0/0.jpg", 0); 

    //this also does nothing 
    IplImage *img=cvLoadImage("Image_Name); 
    Mat mat(img); 


    // images for first person (not mine) except incresed pathing/ 
    //repeat for multiple people in future 
    images.push_back(cv::imread("/snip", CV_LOAD_IMAGE_GRAYSCALE)); 
    labels.push_back(0); 

    images.push_back(cv::imread("/snip", CV_LOAD_IMAGE_GRAYSCALE)); 
    labels.push_back(0); 

    images.push_back(cv::imread("/snip", CV_LOAD_IMAGE_GRAYSCALE)); 
    labels.push_back(0); 

    // Create a new Fisherfaces model and retain all available Fisherfaces, 
    // this is the most common usage of this specific FaceRecognizer: 
    //(not mine) 
    Ptr<FaceRecognizer> model = createFisherFaceRecognizer(); 

    // This is the common interface to train all of the available cv::FaceRecognizer 
    // implementations: 
    //(not mine) 
    model->train(images, labels); 

    model->save("/snip.xml"); 

    return 0; 
} 

imread沒有做任何事情,導致其餘代碼無用。我真的是新來的openCV,並不真正理解文檔,所以也許即時實施一些東西錯了。我很感謝imread的幫助以及如何閱讀opencv文檔。

回答

0

不是一個真正的答案(因爲只是在註釋代碼不工作..)

但它總是一個好主意,檢查時加載資源:

Mat img = imread(path,flags); 
if (img.empty()) 
{ 
    // either the path was wrong, or it could not decompress it 
    cerr << "could not load " << path << endl; 
    return -1; 
} 
相關問題