First time here? Check out the FAQ!

Ask Your Question
0

image.data won't load

asked Mar 10 '17

yrazin gravatar image

updated Mar 10 '17

I'm sure this has been asked before but my basic sample 'load image' code keeps failing.

#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(argv[1],CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        cout << image.size();
        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;
}

This code always errors at at the second test (! image.data). The image.size() returned is [0x0]. I have tried both .jpg and .bmp images that are definitely in the path (same dir as the .exe)

I googled around and cannot find anything. My code compiles fine. I am working in VS2008 (Win32) for various necessary reasons.

Preview: (hide)

Comments

also, how do I get my includes and namespaces into the copy-pasted code box - they get formatted funny?

yrazin gravatar imageyrazin (Mar 10 '17)edit

I don't know what's wrong, but try the OpenCV CommandLineParser. You'll likely at least get more descriptive errors.

Tetragramm gravatar imageTetragramm (Mar 10 '17)edit

Have you tied using a hardcoded static path to your image? What's your input for argv?

closecall gravatar imageclosecall (Mar 14 '17)edit

Yes - I am using a hardcoded static path as my arg

yrazin gravatar imageyrazin (Mar 15 '17)edit

1 answer

Sort by » oldest newest most voted
-1

answered May 26 '17

black9 gravatar image

updated May 26 '17

your problem is with your " argc " in main(int argc, char** argv)

since it is not going to handle====logic====

if( argc != 2)

Preview: (hide)

Comments

Please read the question : "This code always errors at at the second test (! image.data)" problem is not argc

LBerger gravatar imageLBerger (May 26 '17)edit

@LBerger yea ! you may be right. But I don't find any logic in that SYSTEM is compiling and not picking the image. I ran the code and first error i got was from logic "if(argc !=2)" in vs2017

black9 gravatar imageblack9 (May 26 '17)edit

Question Tools

1 follower

Stats

Asked: Mar 10 '17

Seen: 513 times

Last updated: May 25 '17