imread return a Mat object with no methods

asked 2014-02-05 04:48:34 -0600

q072 gravatar image

I'm trying to change some code from openCV to openCV2 in windows using a Cmake/Mingw compiled openCV248 (on Eclipse). My normal openCV code works fine using cvLoadImage and cvShowImage. But when I try to use imread and imshow I get a Mat from the imread that has no methods and an error from eclipse that tells me that imshow has invalid arguments...

Here is an example code:

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

using namespace std;
using namespace cv;


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

    Mat image = imread("pic.jpg",0);   

    namedWindow( "window", CV_WINDOW_AUTOSIZE );

    imshow("window", image);
    waitKey(10);

    resizeWindow("window", 400, 400);

    waitKey(0);                                         
    return 0;
}

Any help ?

edit retag flag offensive close merge delete

Comments

you mean, that imread returns an empty Mat , and that imshow chokes on that ?

Mat image = imread("pic.jpg",0);   
if ( image.empty() ) 
{
    cerr &lt;&lt; bahh, could not load the image!" &lt;&lt; endl;
    return -1;
}

it's most likely a 'wrong path' problem. try an absolute one, like '/home/me/pic.jpg'

berak gravatar imageberak ( 2014-02-05 08:26:23 -0600 )edit

I think #include <opencv/cv.h> is missing

Pedro Batista gravatar imagePedro Batista ( 2014-02-05 08:26:42 -0600 )edit

but @berak, he says that it works with cvLoadImage so I'm guessing thats not it.

Pedro Batista gravatar imagePedro Batista ( 2014-02-05 08:27:34 -0600 )edit

@Median, if he is swapping to c++ interface, you do not have to specify the cv.h header anymore. I never use it in my programs... I also suggest using imread with only the path for a starter, making it use all default parameters. Also you do not need the waitKey(10) before the resize of the window if you add a waitKey(400) later on.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-05 09:10:48 -0600 )edit

Btw, are you placing the correct header location in additional lib options of your C++ compiler?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-05 09:11:56 -0600 )edit

keghn, please ask your own question ...

berak gravatar imageberak ( 2014-02-05 14:21:26 -0600 )edit

Removed it ... what a complete useless remark ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-06 04:07:22 -0600 )edit