You are on page 1of 7

TechnicalNotes

UsingOpenCV2.4.1withMicrosoftVisualStudio2010

SunuWibirama

ElectronicSystemLaboratory
DepartmentofElectricalEngineeringand
InformationTechnology
GadjahMadaUniversity,INDONESIA

HamamotoLaboratory
GraduateSchoolofScienceandTechnology
TokaiUniversity,Tokyo,JAPAN

2012

1.DownloadOpenCV2.4.1fromSourceforge.Netandextractthezipfiletoyourfolder.Iextractedto
ProgramFilesdirectory,sothatmyOpenCV2.4.1installationfolderis:C:\ProgramFiles\opencv2.4.1

2.DownloadIntelThreadingBuildingBlocksforWindows(TBBLibrary).
Access:http://threadingbuildingblocks.org/ver.php?fid=171
Extractandcopybothtbb.dllandtbb_debug.dllto
C:\ProgramFiles\opencv2.4.1\build\x86\vc10\bin

3.AddpathinWindowsXPEnvironmentVariables.
StartMyComputerPropertiesAdvancedEnvironmentVariables

Createpathinuservariableswiththeseparameters:
Variablename

Value

OPENCV_DIR

C:\ProgramFiles\opencv2.4.1\build\x86\vc10

Path

%OPENCV_DIR%\bin

ThispathsettingwillbeusedbyWindowsXPtoaccess*.DLLfilesofOpenCV2.Restartthecomputer
after creating system path for OpenCV2. Remember, your operating system will access OpenCV 2.4.1
andbinfolder.So,dontremoveordeletethespecifiedfolderbeforeyoudereferencingtheinstallation
pathandrestartingyourcomputer.

5.Now,wewillproceedtoconfigurationofenvironmentvariablesinMicrosoftVisualStudio2010.
Onceweconfiguretheenvironmentvariables,wecanproceedtocreateOpenCV2.4.1program.There
aretwowaysofconfiguration:globalandlocal.

Globalconfiguration:
thisconfigurationisusedwhenwedevelopwithoneversionofOpenCVonly.Furthermore,weassume
thatallprojectsinVS2010includesOpenCV2.4.1.Globalconfigurationallowsdevelopertosavetime
sinceonetimeconfigurationisusedforallprojects.
Localconfiguration:
thisconfigurationisusedwhenwedevelopmorethanoneprojectwithdifferentversionofOpenCV.
Configurationdependsoneachproject.Itallowsdevelopertosetwiderrangeofapplication,however
manualconfigurationmustbedoneforeachproject.
(a) GlobalConfiguration
InVS2010,openPropertyManagerwindowbyaccessing:ViewPropertyManager.
ChooseinyourDebugProject(ifyouareworkingunderDebugMode),andrightclick
Microsoft.Cpp.Win32.user.OpenPropertiesoption.

InthePropertiesoption,proceedtoVC++DirectoriesIncludeDirectories.
Addyourincludedirectory:C:\ProgramFiles\opencv2.4.1\build\include

Next,includeproceedtoVC++DirectoriesLibraryDirectories.
Addyourlibrarydirectory:C:\ProgramFiles\opencv2.4.1\build\x86\vc10\lib

Next,definealllibraries(*.libfiles).Inthisproject,Iusedebuglibraries.Ifyouareworking
underReleasemode,youshouldincludereleaselibraries.Youcaneasilydifferentiatethe
nameofdebugandreleaselibrariesbynotinga_dendingfordebuglibraries.
ProceedtoLinkerInputAdditionalDependencies

Next,copyandpastealloftheselibrariesnames:

opencv_calib3d241d.lib
opencv_contrib241d.lib
opencv_core241d.lib
opencv_features2d241d.lib
opencv_flann241d.lib
opencv_gpu241d.lib
opencv_haartraining_engined.lib
opencv_highgui241d.lib
opencv_imgproc241d.lib
opencv_legacy241d.lib
opencv_ml241d.lib
opencv_nonfree241d.lib
opencv_objdetect241d.lib
opencv_photo241d.lib
opencv_stitching241d.lib
opencv_ts241d.lib
opencv_video241d.lib
opencv_videostab241d.lib

ClickApplyandOK.Now,youareworkingunderglobalconfiguration.
AllprojectcreatedusingVS2010willincludeOpenCV2.4.1libraries.

(b) LocalConfiguration
Basically,theconfigurationstepissameasglobalconfiguration,exceptyoumustselecteach
projectpropertiesinsteadofglobalproperties.Toselecteachprojectproperties,selectthe
projectnameandrightclick.Proceedtoitsproperties.Next,followinstructioninglobal
configurationtoaddincludedirectory,librarydirectory,andlibrariesnames.

6.TestyourOpenCV2.4.1instalationbyexecutingthispieceofcode
(pleaseprovideyourowntestimage):
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>

intmain(){

//readanimage
cv::Matimage=cv::imread("testimage.jpg");
//createlargewindownamed"MyImage"
cv::namedWindow("MyImage");
//showtheimageonwindow
cv::imshow("MyImage",image);
//waitkeytobepressedfor5000ms
cv::waitKey(5000);

return1;

You might also like