Saturday, 21 May 2011

Easily Compile and Build OpenCV codes in Windows MinGW Setup

After successfully setting up OpenCV2.0 with MinGW in windows, I started off with my project.

I was really annoyed at copying long string to cmd.exe to compile and link my project and then to execute by opening .exe file.

So I started searching about dos batch and wrote my own script to compile and execute my project in one go.
The script is as follows:

echo Enter the file to compile and link (enter for last file)
set/p "filee=>"

g++ -Ic:\OpenCv2.0MingW\include\opencv -oo -g3 -Wall -c -otemp.o %filee%.cpp
g++ -Lc:\OpenCv2.0MingW\lib -o%filee%.exe temp.o -lcv200d -lcvaux200d -lcxcore200d -lcxts200d -lhighgui200d -lml200d

echo Bazzingaaa!!
set/p "in=>"
if %in%==q goto exita
if %in%==Q goto exita
goto St

I am doing all my coding in the folder e:\cvprog , therefore everytime it runs it goes to that folder first. You can change the folder location to your own project folder.

How to use it? Simple! Copy paste this script in Notepad and save as run.bat on desktop. Open by double clicking run.bat then enter filename excluding the extension (which this script takes as .cpp but can be changed for ones requirement) to compile and execute your code. After first compiling and executing a code, the script loops back to start. Now if you want to compile and execute the same code again, you can just press enter key, the script will automatically take the last entered filename.

Thats all for now, right now I dont have much time to improve this script as I am working on my project. Soon I will be posting about my own project as well. Till then cyaa, happy coding :D

Wednesday, 4 May 2011

Setting up Opencv2.0 with MinGW on Windows

I have been using OpenCV for quite long now, and well I must say it is a very good library for implementing different image processing technique in real time. Previously I was using Ubuntu 10.04 along with OpenCV 2.20, which was very easier to setup as compared to my recent venture.

In order to test my projects on a slower system, I decided to work with OpenCV on my old desktop with Windows Xp. I thought it would be much easier and less time consuming to set up everything as Windows is always considered to be better at interacting with user. However after few hours, I was proven wrong.

Since I previously worked in Linux Envoirnment and my old desktop was slow enough to not smoothly run any IDE software, I wanted to setup something similar to linux terminal and gedit. After googling for few minutes, I successfully found the fastest, or should I say the slowest way, of setting up OpenCV. It involved using MinGW (minimalist gnu for windows) and OpenCV 2.0 precompiled library for MinGW. After installing everything, when I compiled a simple helloCV program, it crashed!