Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

image.data won't load

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.

image.data won't load

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

#include "opencv2\core\core.hpp"

"opencv2\core\core.hpp" #include "opencv2\highgui\highgui.hpp"

"opencv2\highgui\highgui.hpp" #include "iostream"

"iostream" using namespace cv;

cv; using namespace std;

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.