Ask Your Question

imread does not load jpg on osx

asked 2013-10-01 23:34:11 -0500

I am having trouble with imread not loading a .jpg using the image loading tutorial.

image.jpg is in the same location as my code. I've loaded the libraries in my project and linked the header files properly.

I checked my build information using cout << cv::getBuildInformation() << endl; and confirmed jpg support.

Here is the code i'm using:

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

using namespace cv;
using namespace std;

int main( int argc, char** argv )
    Mat image;
    image = imread("image.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file

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

    namedWindow( "Display window", CV_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;

The if(! ) statement evaluates to true.

Does anyone have any ideas what I could be doing wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-02 21:07:38 -0500

gbabic gravatar image

I have seen this issue before, can you try to use an absolute path to your image instead of just the name. e.g /Users/langues/path/to/your/image.jpg

Hope that helps :)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-10-01 23:34:11 -0500

Seen: 1,976 times

Last updated: Oct 02 '13