compiling opencv 2.4 on a 64 bit mac in Xcode

前端 未结 1 1107
夕颜
夕颜 2020-12-29 13:57

I have an opencv project that I\'ve been developing under ubuntu 12.04, on a parellels VM on a mac which has an x86_64 architecture. There have been many screen switching p

相关标签:
1条回答
  • 2020-12-29 14:22

    steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1 EDIT: successfully tested with opencv 2.4.5 on mac os x mountain lion 10.8.3 and Xcode 4.5

    Having the right tools

    1. download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
    2. download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
    3. i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
    4. go to xcode preferences to download and install the Command Line Tools so you have g++ etc.

    Use cmake to compile opencv

    1. go to the extracted opencv folder
    2. create a build directory

      mkdir build
      cd build
      cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" ..
      make -j8
      sudo make install
      
    3. from the build folder, go to bin/ and run one of the tests

      ./opencv-test-photo
      

    Create your own c++ opencv xcode project

    1. fire up xcode and create a new xcode project
    2. select Command Line Tool for the type of project under os x
    3. open your project's build settings
    4. under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
    5. under Build Options, set Compiler for C/C++ to Default Compiler
    6. under Search Paths, set Header Search Paths to /usr/local/include
    7. also under Search Paths, set Library Search Paths to /usr/local/lib
    8. under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++ (With OpenCV 2.4.6, Xcode 5, LLVM 5.0, and 10.8.5, set both language dialect and std library to "Compiler Default" instead)

    Add the compiled opencv libraries to your project

    1. go the the Build Phases tab next to Build Settings tab you were in
    2. inside Link Binary With Libraries, click on the + sign and choose Add Other
    3. hit the front slash / on your keyboard and enter /usr/local/lib
    4. hit enter and select the libraries you want to use in your project
    5. make sure you always select libopencv_core.2.4.4.dylib
    6. hit enter and you will see the selected dylibs under your project

    write some code

    1. first lets organize the files, right click on your project blueprint icon and select New Group
    2. name the new group opencv or whatever
    3. drag the dylibs and drop them in that group
    4. open main.cpp
    5. copy code from any of the sample tests that came with opencv and paste it here
    6. make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps

      • libopencv_core.2.4.4.dylib
      • libopencv_highgui.2.4.4.dylib
      • libopencv_stitching.2.4.4.dylib

    Cheers.

    0 讨论(0)
提交回复
热议问题