0

Possible Duplicate:
Getting started with OpenCV 2.4 and MinGW on Windows 7

I installed the MinGW compiler and OpenCV2.4.0 in Windows 7. I wrote some C++ code, compiled it and ran it, but it can't display the image:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv; 
using namespace std;
{
Mat im = imread("baboon.jpg
if (im.empty()) {
      cout << "Cannot open image!" << endl;
      return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}

After compiling, everything is ok. The moment you run loadimg.exe, there's a black dialog box that pops up, but it does not display images, and then loadimg.exe stops working. I know it is a problem with MinGW. I checked my GCC with gcc -v, the version is 4.6.2. I can compile other c++ source and run it Ok, so I don't know what happened and how to fix it.

Community
  • 1
  • 1

1 Answers1

-1

==================

How to setup CodeBlocks for OpenCV

MinGW and codeblocd

In this tutorial i will be using OpenCV v2.4.2 and Code Blocks v10.05 with GNU compiler on Windows 7 operating system. Using OpenCV v2.4.2? Then you can check this post "Setup OpenCV 2.4.2 in codeblocks"

To work on OpenCV with Code Blocks you just need to add some libraries. Following are some simple steps that I followed.

1.First of all i assume you have downloaded the OpenCV package and installed in your system. ( Not exactly install, just extract ) http://sourceforge.net/projects/opencvlibrary/files/opencv-win/, you'd better select the v2.4.2

2.Make sure the environment variable PATH is set. This could be done during the installation procedure itself. It will prompt you with this question. If you missed that then you have to manually add it.

3.Considering you have the OpenCV installed in your C drive, I continue with the method。Open Code Blocks.Goto menu Settings > Compiler and Debugger > Search Directories.There goto Add and add the directory C:\OpenCV\include\opencv

4.In the Linker tab add the directory C:\OpenCV\build\x86\mingw\lib,Next click on the Linker Settings. Add all the .lib files from C:\OpenCV\build\x86\mingw\lib

5.That's it!! Now you are ready to run your first OpenCV program. I tested a sample program demhist.c