1

Ok. I followed the "Using CMake to build" set of instructions on this site: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

I made a "build" folder. I generated "Unix Makefiles" using cmake. I ran make -j8 and sudo make install. Everything should be where it needs to be, right? Wrong. I opened the FaceTracker.xcodeproj file, clicked "Run", and here's what I got:

The run destination My Mac 64-bit is not valid for Running the scheme 'FaceTracker'.

The scheme 'FaceTracker' contains no buildables that can be built for the SDKs supported by > the run destination My Mac 64-bit. Make sure your targets all specify SDKs that are supported by this version of Xcode.

What should I do to get this to work? I'm scared to use the precompiled OpenCV packages on Lion considered how old they are. I'm also new to Xcode.

Edit: December 14th, 7:05 PM:

I made a helloworld program

////////////////////////////////////////////////////////////////////////
//
// 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;
}

 

I tried compiling it with 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

It seems like my problem is with the installed libs, but I am not really sure where to find them considering that my platform is not Linux, but OS X, and I didn't use Macports or Home Brew, I used the recommended method of installation, CMake. Do you know how I would set up PKG_CONFIG_PATH on my mac using the locations used by CMake? The installation instructions are extremely confusing, and it doesn't seem as though I would be able to use CMake to uninstall OpenCV, which is also quite confusing.

Community
  • 1
  • 1
JesseBikman
  • 632
  • 1
  • 5
  • 22

1 Answers1

2

Basically, you forgot to add everything on the cmd-line! The headers directory, the libs directory and link with the appropriated libraries:

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
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Now I get this: Undefined symbols for architecture x86_64: "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int)in ccHgPC7D.o "std::ios_base::Init::~Init()", referenced from: ___tcf_1 in ccHgPC7D.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status – JesseBikman Dec 15 '11 at 01:16
  • I followed your mistake and used `gcc`when I should be using `g++`. It's a CPP file after all, right?! Well, the answer was updated to reflect this issue. – karlphillip Dec 15 '11 at 01:52
  • Also, don't forget to up vote my answer if it helped you or select it as the official answer to the question so it can help others in the future. To select an answer as the official, click on the checkbox near the answer. Let me know if this worked or not. – karlphillip Dec 15 '11 at 01:55
  • Right on! Too bad I can't compile within Xcode, but at least I know that the libraries are in the right places. Thanks Karl, this gets me off to a good start. – JesseBikman Dec 15 '11 at 21:46