尝试使用通过cmake安装的OpenCV-2.3.1在XCode中运行示例MacOSX FaceTracker程序

时间:2011-12-14 05:31:47

标签: c xcode macos opencv osx-lion

确定。我按照本网站上的“使用CMake构建”说明进行操作: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

我制作了一个“build”文件夹。我使用cmake生成了“Unix Makefiles”。我运行make -j8和sudo make install。一切都应该在它需要的地方,对吧?错误。我打开了FaceTracker.xcodeproj文件,单击“运行”,这是我得到的:

  

运行目标My Mac 64位对于运行方案'FaceTracker'无效。

     

方案'FaceTracker'不包含可为>支持的SDK构建的可构建项目。运行目标我的Mac 64位。确保您的目标都指定了SDK   这个版本的Xcode支持。

我该怎么做才能让它发挥作用?我很害怕在Lion上使用预编译的OpenCV软件包,考虑它们的年龄。我也是Xcode的新手。

编辑:12月14日,下午7:05:

我制作了一个helloworld计划

////////////////////////////////////////////////////////////////////////
//
// hello-world.cpp
//
// This is a simple, introductory OpenCV program. The program reads an
// image from a file, inverts it, and displays the result. 
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;

  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

  // invert the image
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&img );
  return 0;
}

我尝试用gcc编译它:

gcc helloworld.cpp 
helloworld.cpp:12:16: error: cv.h: No such file or directory
helloworld.cpp:13:21: error: highgui.h: No such file or directory
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:18: error: ‘IplImage’ was not declared in this scope
helloworld.cpp:18: error: ‘img’ was not declared in this scope
helloworld.cpp:20: error: ‘uchar’ was not declared in this scope
helloworld.cpp:20: error: ‘data’ was not declared in this scope
helloworld.cpp:29: error: ‘cvLoadImage’ was not declared in this scope
helloworld.cpp:40: error: expected primary-expression before ‘)’ token
helloworld.cpp:40: error: expected `;' before ‘img’
helloworld.cpp:44: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
helloworld.cpp:44: error: ‘cvNamedWindow’ was not declared in this scope
helloworld.cpp:45: error: ‘cvMoveWindow’ was not declared in this scope
helloworld.cpp:52: error: ‘cvShowImage’ was not declared in this scope
helloworld.cpp:55: error: ‘cvWaitKey’ was not declared in this scope
helloworld.cpp:58: error: ‘cvReleaseImage’ was not declared in this scope
Jesse:testing jessebikman$ g++ helloworld.cpp 
helloworld.cpp:12:16: error: cv.h: No such file or directory
helloworld.cpp:13:21: error: highgui.h: No such file or directory
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:18: error: ‘IplImage’ was not declared in this scope
helloworld.cpp:18: error: ‘img’ was not declared in this scope
helloworld.cpp:20: error: ‘uchar’ was not declared in this scope
helloworld.cpp:20: error: ‘data’ was not declared in this scope
helloworld.cpp:29: error: ‘cvLoadImage’ was not declared in this scope
helloworld.cpp:40: error: expected primary-expression before ‘)’ token
helloworld.cpp:40: error: expected `;' before ‘img’
helloworld.cpp:44: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
helloworld.cpp:44: error: ‘cvNamedWindow’ was not declared in this scope
helloworld.cpp:45: error: ‘cvMoveWindow’ was not declared in this scope
helloworld.cpp:52: error: ‘cvShowImage’ was not declared in this scope
helloworld.cpp:55: error: ‘cvWaitKey’ was not declared in this scope
helloworld.cpp:58: error: ‘cvReleaseImage’ was not declared in this scope

似乎我的问题是安装的libs,但我不确定在哪里找到它们考虑到我的平台不是Linux,而是OS X,我没有使用Macports或Home Brew,我用过推荐的安装方法,CMake。你知道如何使用CMake使用的位置在我的mac上设置PKG_CONFIG_PATH吗?安装说明非常混乱,似乎我不能使用CMake卸载OpenCV,这也很混乱。

1 个答案:

答案 0 :(得分:2)

基本上,你忘了在cmd-line上添加所有内容! headers目录,libs目录和与适当库的链接:

g++ helloworld.cpp -o helloworld -I/usr/local/include/opencv -I/usr/local/include  -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann