Ask Your Question
0

OpenCV on OSX Mavericks in Xcode

asked 2014-02-01 09:54:28 -0600

updated 2014-02-01 11:32:50 -0600

I'm trying to run OpenCV on OSX in Xcode. I have downloaded the code from github. And used cmake to compile it.

Next I created a new Xcode project with the following code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread("img.jpg");   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window

    return 0;
}

Next I've set the header search path to: /usr/local/include

After that I've added the libraries from /usr/local/lib in the "Build Phases" as seen in the screenshot below.

image description

However, when I try to run I get the following error:

ld: library not found for -lopencv_core.3.0.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Did I mis something?

edit:

Looks like i've got to add the library search path too. Now it compiles (doesn't show anything, but it compiles).

edit retag flag offensive close merge delete

Comments

Why don't you use CMake for your project as well? Then you can just automatically generate a properly configured Xcode project.

jensenb gravatar imagejensenb ( 2014-02-02 05:42:39 -0600 )edit

I have no experience with CMake. I found somewhere that I needed it so I did. But that would be a handy feature. However it seem's i've got it working. I had to add the library search path.

Matthijn Dijkstra gravatar imageMatthijn Dijkstra ( 2014-02-03 07:53:16 -0600 )edit

CMake really shines when you have: 1) lots of third party dependencies and 2) when your code should compile and run on multiple platforms. If you only ever target OS X I can understand leaving it out, but if your project's scope grows you may want to reconsider using CMake in the future.

jensenb gravatar imagejensenb ( 2014-02-04 01:51:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-01 12:23:46 -0600

Hi,

you are trying to load the file img.jpg. Make sure this file is in the same folder as the executable file.

Kind regards, Daniel

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-01 09:54:28 -0600

Seen: 1,006 times

Last updated: Feb 01 '14