【问题标题】:Trying to run the sample MacOSX FaceTracker program in XCode using OpenCV-2.3.1 installed via cmake尝试使用通过 cmake 安装的 OpenCV-2.3.1 在 XCode 中运行示例 MacOSX FaceTracker 程序
【发布时间】:2012-01-19 22:56:31
【问题描述】:

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

我创建了一个“构建”文件夹。我使用 cmake 生成了“Unix Makefiles”。我运行了 make -j8 和 sudo make install。一切都应该在它需要的地方,对吧?错误的。我打开 FaceTracker.xcodeproj 文件,点击“运行”,得到的结果如下:

运行目标 My Mac 64 位不适用于运行方案“FaceTracker”。

方案“FaceTracker”不包含可以为运行目标 My Mac 64 位支持的 SDK 构建的可构建项目。确保您的目标都指定了 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

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

【问题讨论】:

标签: c xcode macos opencv osx-lion


【解决方案1】:

基本上,您忘记在命令行中添加所有内容! 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

【讨论】:

  • 现在我得到这个:架构 x86_64 的未定义符号:“std::ios_base::Init::Init()”,引用自:__static_initialization_and_destruction_0(int, int)in ccHgPC7D.o“std: :ios_base::Init::~Init()”,引用自:ccHgPC7D.o 中的 ___tcf_1 ld:未找到架构 x86_64 collect2 的符号:ld 返回 1 个退出状态
  • 我按照你的错误使用了gcc,而我应该使用g++。毕竟是CPP文件对吧?!好吧,答案已更新以反映此问题。
  • 另外,如果我的答案对您有帮助,请不要忘记投票,或者选择它作为问题的官方答案,以便将来帮助其他人。要选择官方答案,请单击答案附近的复选框。让我知道这是否有效。
  • 正确!太糟糕了,我无法在 Xcode 中编译,但至少我知道这些库位于正确的位置。谢谢 Karl,这让我有了一个良好的开端。
猜你喜欢
  • 1970-01-01
  • 2020-08-19
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-21
相关资源
最近更新 更多