Ask Your Question
0

image.data won't load

asked 2017-03-10 13:55:58 -0600

yrazin gravatar image

updated 2017-03-10 14:09:35 -0600

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.

edit retag flag offensive close merge delete

Comments

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

yrazin gravatar imageyrazin ( 2017-03-10 13:56:38 -0600 )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 ( 2017-03-10 17:30:49 -0600 )edit

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

closecall gravatar imageclosecall ( 2017-03-14 04:24:38 -0600 )edit

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

yrazin gravatar imageyrazin ( 2017-03-14 19:39:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2017-05-25 23:53:57 -0600

black9 gravatar image

updated 2017-05-25 23:55:54 -0600

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

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

if( argc != 2)

edit flag offensive delete link more

Comments

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

LBerger gravatar imageLBerger ( 2017-05-26 01:28:57 -0600 )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 ( 2017-05-26 01:48:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-10 13:55:58 -0600

Seen: 497 times

Last updated: May 25 '17