0

I am using OpenCV 2.4.9 in Visual Studio 2010 and am trying to run simple source code provided on a tutorial website:

#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 << argv[1] << std::endl;
        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;
}

However, when I try to run the executable (and comment out that if statement) I get: Assertion failed (size.width>0 && size.height>0) in cv::imshow ......(file path)

I have looked at just about every related thread I have found on here. The file path is not wrong, I have printed it out and even moved the executable and jpg to the same folder.

Furthermore, this sample code from another tutorial does the exact same thing flawlessly, so I doubt it's a project configuration error but not sure:

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    IplImage *img = cvLoadImage("C:\\Users\\bomoon\\Documents\\Koala.jpg", 1);

    cvNamedWindow("test");
    cvShowImage("test", img);
    cvWaitKey(0);

    cvReleaseImage(&img);
    cvDestroyWindow("test");
    return 0;
}

Can anyone explain why the second program works but not the first, and how I can fix the first one?

P.S.: It's not that I need to find a workaround to accomplish something, I'm trying to run sample code to verify the installation works, but it apparently doesn't if one sample program runs but not the other.

Booley
  • 819
  • 1
  • 9
  • 25
  • I should specify, this is in the Debug version with the Debug libraries; the bug (which was reintroduced in 2.4.8, so not sure if resolved yet) exists only for the Release version, but the Debug version does not have this bug. – Booley Jun 12 '14 at 17:29
  • You might also check out [these](http://stackoverflow.com/q/19315729/1601291) [related](http://stackoverflow.com/q/2584273/1601291) [questions](http://stackoverflow.com/q/18200893/1601291). You likely are linking to the wrong dlls. – Aurelius Jun 12 '14 at 17:34
  • I've read all of those posts, they concern the mixing of Release libraries in the Debug mode when building the solution. I have verified in my property sheet that all the include and library directories and additional dependencies are debug versions. – Booley Jun 12 '14 at 17:53
  • Have you verified you are using the correct 32- or 64-bit versions? That could be another factor. – Aurelius Jun 12 '14 at 18:04
  • Yes, I compiled the OpenCV library using CMake under the Visual Studio 10 64bit native compiler. I also am running the code in x64 debug mode (on Windows 7 64bit). I've checked all of my paths, but I'm still miffed as to why some code works and other code does not. – Booley Jun 12 '14 at 18:21

0 Answers0