Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

前端 未结 5 697
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 03:50

Can anyone provide me some detailed guide how to compile OpenCV 2.3.1 on OS X Lion with Xcode?

I\'m getting mad about this … I got the source, used cmake to create t

5条回答
  •  悲哀的现实
    2020-11-30 04:20

    With small changes to @moosgummi answer below steps worked with Xcode 4.6 on Mac OSX 10.7 TEST code is included below.

    Installation of OpenCV :

    Get the current Version of MacPorts here.

    Don't forget to add "/opt/local/(s)bin" to your environment PATH

    export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    

    Keep your MacPorts up-2-date:

    sudo port -v selfupdate
    

    Install OpenCV with mac ports

    sudo port install opencv
    

    Configuring Xcode for using OpenCV

    1. Create a new XCode project using the Command Line Utility/Standard Tool template. Name it and select C++

    2. Select Project -> Edit Project Settings. Select the Build tab. Set Configuration to All Configurations

    3. In the Architectures section, double-click Valid Architectures and remove all the PPC architectures if any.

    4. Compiler for C/C++/Objective-C > Apple LLVM compiler 4.2 Language" > "C++ Standard Library", and select "libstdc++ (GNU C++ standard library)"

    5. In the Search Paths section set Header Search Paths to /opt/local/include/
      Please choose non-recursive as an option while adding that search path

    6. Close the Project Info window

    7. Select Project -> New Group and create a group called OpenCV Frameworks With the new group selected, select Project -> Add files to 'Your Project Name'

    8. Press the "/" key to get the Go to the folder prompt. Enter /opt/local/lib Select libopencv_core.dylib, libopencv_highgui.dylib (you may need to add other library files from this folder to run other code.)

    9. Uncheck Copy Items… and click Add

    TEST CODE

    Copy this code into your main.cpp file. It should open up a small window that is half shaded.

    #include 
    #include 
    
    int main(int argc, char *argv[])
    {
        // Open the file.
    
        IplImage *img = cvCreateImage( cvSize(100,200), IPL_DEPTH_8U, 3); //if (!img) {
    
        //    printf("Error: Couldn't open the image file.\n");
        //    return 1;
        //}
    
        // Display the image.
        cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
        cvShowImage("Image:", img);
    
        // Wait for the user to press a key in the GUI window.
        cvWaitKey(0);
        // Free the resources.
        cvDestroyWindow("Image:");
        cvReleaseImage(&img);
    
        return 0;
    }
    

提交回复
热议问题