1

I followed steps in this SO link to compile a sample program using OpenCV2.4.0 in windows. I made a setup both in DEVC++ and NetBeans with Mingw. My sample Program is getting Compiled properly, but when I run the exe the application get crashes.

But In same machine I used opencv2.1.0 and the same sample program gets compiled and there is no crash while running it.

The below is the Sample Code I tried to execute:

#include "highgui.h"
using namespace std;
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Water lilies.jpg" );
cvNamedWindow( "Sample", CV_WINDOW_AUTOSIZE );
cvShowImage( "Sample", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Sample" );
} 

UPDATE :

I follwed as the steps as moskito-x link to build the opencv and when I press "configure", I get the following error. And my make file is also 35kb in size. Any suggestions to solve this? enter image description here

Community
  • 1
  • 1
2vision2
  • 4,933
  • 16
  • 83
  • 164

3 Answers3

2

Using the libs in "...\opencv\build\x86\mingw\bin" and "...\opencv\build\x86\mingw\lib

You can not use the libraries that come with OpenCV-2.4.x.exe.

As some developers in forums and I find out. On some systems, the precompiled libs of "opencv 2.4.x" can not be used.
To compile your own programs, works, but it crashed if you try to run them. Until there are not functioning precompiled libs of "opencv 2.4.x , you have to compile opencv yourself.

Ignore so the folder "...\opencv\build\x86\mingw\bin" and "...\opencv\build\x86\mingw\lib" completely.

Community
  • 1
  • 1
moskito-x
  • 11,832
  • 5
  • 47
  • 60
  • Hi thanks for your answer. I tried the steps in your link and I get an error. I have updated my question regarding this. Please help... – 2vision2 Oct 25 '12 at 13:35
  • you have not run `mingw-get-inst-20120426.exe` with `Use : Download latest repository` and select `MinGW Developer Toolkit`. There must be `C:\mingw\bin\libgmp-10.dll` and `C:\mingw\var\cache\mingw-get\packages\libgmp-5.0.1-1-mingw32-dll-10.tar.lzma`. Dont't forget to put 'C:\mingw\bin' to your `PATH Environment` Variable. – moskito-x Oct 25 '12 at 14:09
  • Ya i have dowloaded from the latest repository only and both the files you have mentioned is there in mingw folder. Path is also properly set, and my PATH variable looks as below : C:\mingw\bin;C:\msys\1.0\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; – 2vision2 Oct 25 '12 at 14:25
  • And Am trying to build opencv2.4.0. – 2vision2 Oct 25 '12 at 14:32
  • How far have you got with the comp. of openCV. If the file `C:\mingw\bin\libgmp-10.dll`is in the directory, Cmake should find these. After a shutdown and restart all the PATH changes are then known to all programs. – moskito-x Oct 26 '12 at 14:41
  • Thanks for the follow up. you answer helped really! – 2vision2 May 09 '13 at 05:50
1

As already pointed out you can't rely on precompiled binaries. I also had a lot of problems and finally ended up with compiling my own binaries. My setup was for Windows7, Eclipse CDT (Juno) and MinGW. You can check my post on Stackoverflow here

Community
  • 1
  • 1
Nenad Bulatović
  • 7,238
  • 14
  • 83
  • 113
0

I guess this is an error related to memory management. Maybe because your'e releasing the window before the image. But anyhow you should use the OpenCV C++ interface, as this does a lot of stuff automagically. With the C++ Interface your code would look like this:

    #include <opencv.hpp>

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

            cv::Mat img = cv::imread("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Water lilies.jpg");

            cv::imshow("Sample", img);
            cv::waitKey(0);

            return 0
    }
AD-530
  • 1,059
  • 9
  • 9