Saturday, October 12, 2013

Steps to install OpenCV on Mac OS X for XCode


OpenCV installation steps:
1. Install MacPorts
2. Install CMake by "sudo port install cmake"
3. Get OpenCV source,, and untar it
4. Build OpenCV
   Go to the folder where you untar the OpenCV source to.
   Make a separate folder for building
   . make build
   . cd build
   . cmake -G "Unix Makefiles" ..
   Now make OpenCV
   . make -j8
   . sudo make install
   The OpenCV will be installed to /usr/local
5. Done installing the OpenCV on Mac OS X

Create a sample project on XCode with OpenCV
1. Start a new XCode "Command Line Tool" project with Type C++
2. Add all the libopencv*.dylib (or the ones you need) into the project from /usr/local/lib with "Copy items into destination group's folder (if needed)" checked
3. Add "/usr/local/include" into "Header Search Path" in Build Settings of project
4. Add "/usr/local/lib" into "Library Search Path" in Build Settings of project
5. Either 4.1 or 4.2
   4.1 Select "libstdc++ (GNU C++ standard library)" instead of "libc++ (LLVM C++ standard library with C++11 support)" in "Apple LLVM compiler 4.2 - Language" in Build Settings
   4.2 Select "LLVM GCC 4.2" instead of "Default compiler (Apple LLVM compiler 4.2)" in "Compiler for C/C++/Objective-C" in Build Settings
6. Write some codes to test OpenCV

#include "opencv2/core/core.hpp"

using namespace cv ;

int main(int argc, char** argv)
#if 0
    //get the image from the directed path
    IplImage* img = cvLoadImage("/Users/Howard/Desktop/Codes/OpenCV/CV/Lena_512.bmp", 1);
    //create a window to display the image
    cvNamedWindow("picture", 1);
    //show the image in the window
    cvShowImage("picture", img);
    //wait for the user to hit a key
    //delete the image and window
    Mat img = imread("/Users/Howard/Desktop/Codes/OpenCV/CV/Lena_512.bmp"    CV_LOAD_IMAGE_UNCHANGED);
    if ( == NULL)
        printf("\n Image cannot be loaded") ;
        return -1;
    namedWindow("OrgImage", CV_WINDOW_AUTOSIZE);
    imshow("OrgImage", img);
    waitKey(0) ;


7. That's all

No comments:

Check clients which connect to Mac OS X Wi-Fi Internet Sharing

arp -i bridge100 -a bridge100 may be different on your Mac OSX