Monday, 12 September 2011

Linux Like Installation of OpenCV 2.3.0 on Windows

So you have been using Linux for opencv programming lately and now, for some reason, have no other option then to work on Windows. I too have to go through the same situation when I had nothing but Windows on my desktop and I was been too lazy to install Linux or maybe I wanted Windows for gaming.

Well this is your lucky day then, because I will be guiding you through 'Linux-Like-Installation' of OpenCV 2.3.0 on Windows. This guide will use minimum possible Linux System installation , hence it wont take much time to setup except for OpenCV compilation which takes sometime (and hey we all need sometime to relax)
First step is to download all the packages required for setup. Here are the direct links to the packages. You can also google these packages if, for some reason, you can not download them from here.
  1. Minimalist GNU for Windows: TDM-MinGW-4.5.2
  2. Cmake 2.8.4: cmake-2.8.4-win32-x86
  3. MSYS 1.0.10: MSYS-1.0.10
  4. OpenCV 2.3.0 Source: OpenCV 2.3.0



Ok, now install 1-3 just like I have guided in my first tutorial. There is not much into it except setting System Path Variable to point to the installations.

If you are having problem with this step or do not know how to set System Path Variable then check my tutorial for OpenCV 2.0 here: http://seevisionc.blogspot.com/2011/05/setting-up-opencv20-with-mingw-in.html

After installation of basic softwares, extract OpenCV 2.3.0 source to a convenient location e.g C:\OpenCV-2.3.0. Now follow the steps below, I assume that you have extracted the source to C:\OpenCV-2.3.0 folder. If your location is different from this then you should make necessary changes to the steps below.



First of all open CMake, and Browse Source to the location where you extracted your OpenCV 2.3.0 source. Enter where you want to build the files in the space next to Browse Build(c:\OpenCV-2.3.0MinGW).

 Now click Configure and accept if it asks to create build directory.

Select MSYS as generator and specify native compilers, then click Next


Specify or Bowse to the location containing gcc.exe and g++.exe within the MinGW folder and click Finish
( c:\MinGW32\bin\gcc.exe and c:\MinGW32\bin\g++.exe )



CMake will then show some fields, all in red. Write Debug in the value field for CMAKE_BUILD_TYPE

If you want to make any additional changes, do that now and again click Configure until all fields change to White color.

Now click Generate, after that close CMake window

In Command Prompt go to OpenCV build folder (c:\OpenCV-2.3.0MinGW) and enter Make. It will take a few minutes depending on your system specs. After that is done successfully, enter Make Install to install the compiled libraries in the C:\OpenCV-2.3.0MinGW\Install folder.



Now add the folder C:\OpenCV-2.3.0MinGW\Install\bin to the System Variable Path as we did earlier.

Finally, test your compiled libraries using the following helloCV code (paste a jpeg in the same folder as compiled exe and change "image.jpg" to your file name):
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
IplImage *frame;
cvNamedWindow("Example");
frame = cvLoadImage("image.jpg");
cvShowImage("Example",frame);
while(1)
{
char c = cvWaitKey(3);
if(c == 27break;
}
cvReleaseImage(&frame);
cvDestroyWindow("Example");
return 1;
}
For compiling and Linking through MinGw use the following commands from Command Prompt:
for compiling: 
g++ -Ic:\OpenCv-2.3.0MingW\install\include\opencv -Ic:\OpenCv-2.3.0MingW\install\include -oo -g3 -Wall -c -otemp.o %filee%.cpp
 for linking
g++ -LC:\OpenCV-2.3.0MinGW\install\lib -o%filee%.exe temp.o -llibopencv_contrib230d -llibopencv_core230d -llibopencv_highgui230d -llibopencv_imgproc230d  -llibopencv_ml230d
Depending on the library you are using in your code, you will have to add one or more libraries from the lib path.
Use your own file's name and location at filename field.

If all is working, you wont get any error, and the compiled executable will display your image in a new window.

I will be posting a much easier method for compiling and linking with this setup, just like I did earlier, will be making a batch script to compile, link and execute the code in just one click.

Thats all folks, if this has helped you, please subscribe or just leave a comment.

No comments:

Post a Comment