sepdek March 16, 2013
opencv mac installer

Setting up and testing OpenCV in MacOS – tested on Mountain Lion v. 10.8.3
(*) based on the blog notes of Tilo Mitra


  1. Download the latest version of OpenCV from SourceForge: and unzip it. A folder is extracted with various files and folders
  2. Download cmake which is required in order to build and install OpenCV for MacOS. There are 2 alternatives to follow:
  3. Open a terminal window, change directory to where the OpenCV was extracted, create a folder named build and move into it. Then type the following commands:

    cmake -G “Unix Makefiles” ..
    make -j8
    sudo make install

    After successful installation everything should be installed in /usr/local/lib and /usr/local/include

  4. There is a high probability that step 3.b will result in 2 errors! In this case an additional step is needed:
    • Download the latest JUnit from SourceForge:
    • While in the terminal window and inside the “build” directory create a folder named lib:

      mkdir modules/java/test/.build/lib

      and copy the downloaded junit file in this folder with:

      cp ~/Downloads/junit-4.10.jar modules/java/test/.build/lib

    • Then retry the make process, which will most probably result in 100% success. It is suggested to execute a: “make clean” command before rerunning step 3.b

Testing the installation:

  • Start Xcode and create a Command Line Tool project
  • Right-click the project name after created and select “Add files to…”. When finder pops-up type “/” to get the navigation panel and type /usr/local/lib and hit Enter. Select all *opencv*.dylib files and include them in the project. It is suggested to group then into one group i.e. named “OpenCV” for easier management
  • Select the project name again and go to “Build Settings”. Search for “Header Search Paths” and once found input the path: /usr/local/include
  • Open main.cpp file and type in the typical open-save image example shown below

// Example showing how to read and write images

int main(int argc, char** argv)
IplImage * pInpImg = 0;

// Load an image from file – change this based on your image name
pInpImg = cvLoadImage(“my_image.jpg”, CV_LOAD_IMAGE_UNCHANGED);
fprintf(stderr, “failed to load input image\n”);
return -1;

// Write the image to a file with a different name,
// using a different image format — .png instead of .jpg
if( !cvSaveImage(“my_image_copy.png”, pInpImg) )
fprintf(stderr, “failed to write image file\n”);

// Remember to free image memory after using it!

return 0;



Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.