Pages

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:
cls
@ECHO OFF
e:
cd\cvprog

:St
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!!
%filee%.exe
set/p "in=>"
if %in%==q goto exita
if %in%==Q goto exita
goto St
:exita

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