C++ 如何让imread在Xcode中工作

C++ 如何让imread在Xcode中工作,c++,opencv,C++,Opencv,这段代码应该拍摄一些图像并加载它们,在代码中尝试3种不同的方法,但它们似乎都不起作用。这里的答案不适用于我,因为我没有这些库 #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv/cvaux.h> using namespace cv; int main(int argc, char** argv) { //The code seg

这段代码应该拍摄一些图像并加载它们,在代码中尝试3种不同的方法,但它们似乎都不起作用。这里的答案不适用于我,因为我没有这些库

#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;
}
#包括
#包括
#包括
使用名称空间cv;
int main(int argc,字符**argv)
{
//注释的代码段(不是我的)取自http://docs.opencv.org/modules/contrib/doc/facerec/facerec_api.html
//保存图像和标签(不是我的)
矢量图像;
向量标签;
//这不会给img分配任何内容
Mat img=cv::imread(“/Users/STUFF/Desktop/Projects/OpenCV_testing/person0/0.jpg”,0);
//这也无济于事
IplImage*img=cvLoadImage(“图像名称”);
Mat(img);
//第一人称图像(不是我的),递增路径除外/
//以后对多个人重复此操作
图像。向后推(cv::imread(“/snip”,cv\u LOAD\u IMAGE\u GRAYSCALE));
标签。向后推_(0);
图像。向后推(cv::imread(“/snip”,cv\u LOAD\u IMAGE\u GRAYSCALE));
标签。向后推_(0);
图像。向后推(cv::imread(“/snip”,cv\u LOAD\u IMAGE\u GRAYSCALE));
标签。向后推_(0);
//创建新的Fisherfaces模型并保留所有可用的Fisherfaces,
//这是此特定人脸识别器最常见的用法:
//(不是我的)
Ptr模型=createFisherFaceRecognizer();
//这是培训所有可用cv::FaceRecognitor的通用接口
//实施:
//(不是我的)
模型->列车(图像、标签);
模型->保存(“/snip.xml”);
返回0;
}
imread没有做任何使其余代码无用的事情。我对openCV非常陌生,也不太了解文档,因此可能我实现了一些错误的东西。我希望能得到imread的帮助以及如何阅读openCV文档。

不是真正的答案(只是因为注释中的代码不起作用……)

但在加载资源时检查始终是一个好主意:

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;
}
Mat img=imread(路径、标志);
if(img.empty())
{   
//要么路径错误,要么无法解压缩
瑟尔