Friday, April 27, 2012

How to configure Code::Blocks for OpenCV 2.3

So many of us always face problems in configuring OpenCV with Code::Blocks, I am also not an exception. I faced a lot of problems in configuring Code::Blocks for OpenCV 2.3. So here is the way how I sorted out this problem.






Requirements:
  1. Code::Blocks with Mingw compiler.
Download the latest release of the Code::Blocks from it's official website.
or
Click the link below to download Code::Block (version 10.05) with MingW compiler from
     
     2. OpenCV (I am using OpenCV 2.3.0), if you don't have it you can get it by clicking the link below
or 
you can select the latest version of the OpenCV on the  
     3. CMake file for creating the binaries for OpenCV, which can be downloaded here


Steps to configure Code::Blocks for OpenCV 2.3.0: 

1. Install the Code::Blocks with Mingw compiler. It will install the required C compiler, C++ compiler and mingw32-make in "C:\Program Files\CodeBlocks\Mingw\bin".

2. Add "C:\Program Files\CodeBlocks\Mingw\bin"in the system path. Check this LINK to see how to edit system path.

3. Install Cmake 2.8. It may ask to add the Cmake to system path variable. If so, select "Do not add to system path variable".

4. Extract "OpenCV-2.3.0-win-src" to "C:\". This will create a new folder "C:\OpenCV-2.3.0".

5. Run Cmake (cmake-gui).

6. Set the Source Code to "C:\OpenCV-2.3.0".

7. Set where to built the binaries. For eg: "C:\OpenCV".

 

8. Press Configure.

9. Let Cmake create the new folder.

10. Specify the Generator: MinGW Makefiles.

11. Select "Specify native compiler"  and click Next.

12. For C set: "C:/Program Files/CodeBlocks/MinGW/bin/gcc.exe".

13. For C++ set: "C:/Program Files/CodeBlocks/MinGW/bin/g++.exe".

14. Click Finish. There should not be any errors and the screen should look like this



15. In the configuration screen type in "RELEASE" (or "DEBUG" if you want to build a debug version) for "CMAKE_BUILD_TYPE". Select BUILD_EXAMPLES if you want.

16. Click Configure again then click Generate cnd close Cmake.

17. Go to the command prompt and inside the folder "C:\OpenCV" type "mingw32-make" and hit enter (takes about 5 to 10 minutes).

18. Then type "mingw32-make install" and hit Enter.

19. After the installation is completed close the command prompt and copy the include  folder from "C:\OpenCV\install"  directory into "C:\OpenCV" folder and let it replace the previously existing include folder in the directory.

20. Open Code::Blocks and now click on the Settings menu on the menu bar and goto "Compiler and Debugger" settings.

21. Click on the "Linker" tab and "Add" all the files from the folder "C:\OpenCV\lib".

 

22. Click on the "Search Directory" tab and under "compiler" tab "Add" the path "C:\OpenCV\include" and "C:\OpenCV\include\opencv"

 

23. Now click on the "linker" and "Add" the path "C:\OpenCV\lib" and hit "OK".



24. Create a new Project. Check "How to create a new project in Code::Blocks".

25. Try to run the following code. This code will load an image of the name "Paris.jpg" onto the screen. You can change the name "Paris.jpg" with your own image name. (Don't forget to putthat image into your project folder).
////////////////////////////////////////////////////////////////////////

#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "cv.h"
#include "highgui.h"


int main(int argc, char *argv[])
{
// declare a new IplImage pointer
IplImage* myimage;

// load an image
myimage = cvLoadImage("Paris.jpg",1); //change the file name with your own image

//create a new window & display the image
cvNamedWindow("Smile", CV_WINDOW_AUTOSIZE);
//cvMoveWindow("Smile", 100, 100);
cvShowImage("Smile", myimage);

//wait for key to close the window
cvWaitKey(0);
cvDestroyWindow( "Smile" );
cvReleaseImage( &myimage );
return 0;
}

////////////////////////////////////////////////////////////////////////////

8 comments:

Apoorv Tiwari said...

sir plz tell something abut openCV .
its use, relations with this micro controller programming
why and how u r preferring openCV on MATLAB.

overall why should we learn openCV

Apoorv Tiwari said...

sir at time of cmake installation process it ask for options for adding path directories for cmake .

so which option is to be selected????

Apoorv Tiwari said...

sir on adding address path (variable) at end cmake on cofiguring showing problem

Ashish Gaur said...

If somebody is working on embedded system and he/she know c language very well then he/she do not have to learn a completely new language to work on image processing as is the case with the MatLab. so you don't have to switch from one language to another and you can use the very familiar C language to process the images as well.


And if you are facing problem with adding the address variable at the end, try adding it in the beginning.

Unknown said...

I followed everything But when I run the program it always gives a console window only!What am I gonna do..I'm trying these for month But each time same result

Ashish Gaur said...

Dear Zabir Al Nazi Nabil,

One possible solution for your problem is that you may not have placed the desired image to be shown in the right folder, in that case you must provide the full path for the image.

Anonymous said...

After configuring in the comd prompt I typed mingw32-make but there error
(make is not recognized as an internal or external command )
In the file where binary is built (C:\OpenCv) no file with this name mingw-make
what did I miss?

tipssoftzone said...

it is a good site for us
http://tipssoftzone.blogspot.com/

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews