1

Here's my code (the first DisplayImage.cpp code in the OpenCV documentation)

/*
 * DisplayImage.cpp
 *
 *  Created on: Dec 25, 2011
 *      Author: Arcturus */       
 #include <iostream>    
 #include <opencv2\opencv.hpp>

using namespace cv;

using namespace std;

int main(int argc, char** argv){

    Mat image;

    image = imread(argv[1], 1);

    if(argc!=2 || !image.data){

        cout<<"no image data";

        return -1;
    }

    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);

    imshow("Display Image", image);

    waitKey(10000);

    return 0;
}

Build complete, executable generated, binaries generated.

I have my image - blackbuck.bmp- in the DisplayImage Debug folder. To run the code, I go to Run> Run Configurations. Select the DisplayImage Debug exe file, key in blackbuck.bmp (also tried it with absolute path) and run it.

On the top of the console, I get the message : DisplayImage Debug. And it displays no image at all. What could be wrong here?

I am running it on Eclipse, using CDT.

Thank you for your time!

EDIT: Problem solved!!! I had to copy all the dll files from the library folder to the folder in which my executable file was being generated. I still do not understand why, though. After all, the linker was already linking the library folder containing all the dlls. If someone could explain this, it would be of great help for future debugging. Thank you karl and mevotron for your time :)

EDIT 2: From the msdn website: "A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of a separate DLL module. The system terminates processes using load-time dynamic linking if they require a DLL that is not found at process startup and gives an error message to the user. The system does not terminate a process using run-time dynamic linking in this situation, but functions exported by the missing DLL are not available to the program."

I think this answers my question. Perhaps this means eclipse uses load-time dynamic linking.

arcturus611
  • 53
  • 1
  • 5
  • 1) How big is your image? 2) On Windows, I think the complete path must have double slashes like: `C:\\folder\\another_folder\\img.png` – karlphillip Jan 06 '12 at 11:56
  • Hey Karl, It is a 750 kilobytes picture. I tried the absolute path, still no go. I just don't get it. The executable is right there, the binaries are there, why then doesn't the picture show up, I simply cannot fathom. – arcturus611 Jan 07 '12 at 09:05
  • You may have to put the image in the same folder as your source code instead of putting it in the .exe directory if you are running it from inside Eclipse. – karlphillip Jan 07 '12 at 10:40
  • I tried doing that too. Also, when I run it from the command prompt, it says libopencv_highgui231d.dll not found. But it is right there in the library eclipse is pointing to. And it is being built from eclipse, so why should it be any different from hte command line? – arcturus611 Jan 07 '12 at 21:06
  • It makes sense that from the cmd-line it doesn't find OpenCV DLLs. You need to edit a Windows environment variable named PATH and add the location of OpenCV DLLs. Then open a new command prompt and try again. – karlphillip Jan 07 '12 at 22:11

1 Answers1

0

How did you compile OpenCV with MinGW (i.e., what were your BUILD_TYPE and SSE* options set to during the CMake configuration)? The reason I ask, is that there is a known bug with SSE optimizations that will cause highgui operations to crash when using MinGW built versions. See my other SO answer here.

Community
  • 1
  • 1
mevatron
  • 13,911
  • 4
  • 55
  • 72
  • Hi mevatron, my CMAKE_BUILD_TYPE is Debug and my SSE option is checked. And now that you mention it, I also noticed that when I try running it from the command line, using DisplayImage.exe blackbuck.bmp, I get a message saying "The program cannot run as libopencv_highgui231d.dll' is missing from your computer. Try installing...' But this file IS there in the library folder eclipse points to. Thanks a lot! – arcturus611 Jan 07 '12 at 09:01
  • Hey mevatron, I took your suggestion from the other post and disabled SSE. I configured and generated it again from CMake. Will the changes take effect by themselves in Eclipse? Because it still doesn't show me the image. – arcturus611 Jan 07 '12 at 21:13
  • Make sure that either the OpenCV DLLs are in the directory with the executable, or the path to the OpenCV DLLs is in the Path variable. If you have Eclipse open when you set the Path variable you'll need to restart Eclipse for it to use the new environment variable. – mevatron Jan 09 '12 at 03:29