How To Build Applications With OpenCV Inside The Microsoft Visual Studio - OpenCV v2.4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

crosoft 10/10/12 Visual Studio OpenCV v2.4.

2 document

How to build applications with OpenCV inside the Microsoft Visual Studio
Everything I describe here will apply to the C\C++ interface of OpenCV. I start out from the assumption that you have read and completed with success the Installation in Windows tutorial. Therefore, before you go any further make sure you have an OpenCV directory that contains the OpenCV header files plus binaries and you have set the environment variables as described here.

The OpenCV libraries, distributed by us, on the Microsoft Windows operating system are in a Dynamic Linked Libraries (DLL). These have the advantage that all the content of the library are loaded only at runtime, on demand, and that countless programs may use the same library file. This means that if you have ten applications using the OpenCV library, no need to have around a version for each one of them. Of course you need to have the dll of the OpenCV on all systems where you want to run your application. Another approach is to use static libraries that have lib extensions. You may build these by using our source files as described in the Installation in Windows tutorial. When you use this the library will be built-in inside your exe file. So there is no chance that the user deletes them, for some reason. As a drawback your application will be larger one and as, it will take more time to load it during its startup. To build an application with OpenCV you need to do two things: Tell to the compiler how the OpenCV library looks. You do this by showing it the header files. Tell to the linker from where to get the functions or data structures of OpenCV, when they are needed. If you use the lib system you must set the path where the library files are and specify in which one of them to look. During the build the linker will look into these libraries and add the definitions and implementation of all used functions and data structures to the executable file. If you use the DLL system you must again specify all this, however now for a different reason. This is a Microsoft OS specific stuff. It seems that the linker needs to know that where in the DLL to search for the data structure or function at the runtime. This information is stored inside lib files. Nevertheless, they arent static libraries. They are so called import libraries. This is why when you make some DLLs in Windows you will also end up with some lib extension libraries. The good part is that at runtime only the DLL is required. To pass on all this information to the Visual Studio IDE you can either do it globally (so all your future projects will get these information) or locally (so only for you current project). The advantage of the global one is that you only need to do it once; however, it may be undesirable to clump all your projects all the time with all these information. In case of the global one how you do it depends on the Microsoft Visual Studio you use. There is a 2008 and previous versions and a 2010 way of doing it. Inside the global section of this tutorial Ill show what the main differences are. The base item of a project in Visual Studio is a solution. A solution may contain multiple projects. Projects are the building blocks of an application. Every project will realize something and you will have a main project in which you can put together this project puzzle. In case of the many simple applications (like many of the tutorials will be) you do not need to break down the application into modules. In these cases your main project will be the only existing one. Now go create a new solution inside Visual studio by going through the File New Project menu selection. Choose Win32 Console Application as type. Enter its name and select the path where to create it. Then in the upcoming dialog make sure you create an empty project.

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document

The local method


Every project is built separately from the others. Due to this every project has its own rule package. Inside this rule packages are stored all the information the IDE needs to know to build your project. For any application there are at least two build modes: a Release and a Debug one. The Debug has many features that exist so you can find and resolve easier bugs inside your application. In contrast the Release is an optimized version, where the goal is to make the application run as fast as possible or to be as small as possible. You may figure that these modes also require different rules to use during build. Therefore, there exist different rule packages for each of your build modes. These rule packages are called inside the IDE as project properties and you can view and modify them by using the Property Manger. You can bring up this with View Property Pages. Expand it and you can see the existing rule packages (called Proporty Sheets).

The really useful stuff of these is that you may create a rule package once and you can later just add it to your new projects. Create it once and reuse it later. We want to create a new Property Sheet that will contain all the rules that the compiler and linker needs to know. Of course we will need a separate one for the Debug and the Release Builds. Start up with the Debug one as shown in the image below:

Use for example the OpenCV_Debug name. Then by selecting the sheet Right Click Properties. In the following I will show to set the OpenCV rules locally, as I find unnecessary to pollute projects with custom rules that I do not use it. Go the C++ groups General entry and under the Additional Include Directories add the path to your OpenCV include. If you dont have C/C++ group, you should add any .c/.cpp file to the project.
$ ( O P E N C V _ D I R ) \ i n c l u d e

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

2/8

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document

When adding third party libraries settings it is generally a good idea to use the power behind the environment variables. The full location of the OpenCV library may change on each system. Moreover, you may even end up yourself with moving the install directory for some reason. If you would give explicit paths inside your property sheet your project will end up not working when you pass it further to someone else who has a different OpenCV install path. Moreover, fixing this would require to manually modifying every explicit path. A more elegant solution is to use the environment variables. Anything that you put inside a parenthesis started with a dollar sign will be replaced at runtime with the current environment variables value. Here comes in play the environment variable setting we already made in our previous tutorial. Next go to the Linker General and under the Additional Library Directories add the libs directory:
$ ( O P E N C V _ D I R ) \ l i b s

Then you need to specify the libraries in which the linker should look into. To do this go to the Linker Input and under the Additional Dependencies entry add the name of all modules which you want to use:

The names of the libraries are as follow:


o p e n c v _ ( T h eN a m eo ft h em o d u l e ) ( T h ev e r s i o nN u m b e ro ft h el i b r a r yy o uu s e ) d . l i b

A full list, for the currently latest trunk version would contain:
o p e n c v _ c o r e 2 3 1 d . l i b o p e n c v _ i m g p r o c 2 3 1 d . l i b o p e n c v _ h i g h g u i 2 3 1 d . l i b o p e n c v _ m l 2 3 1 d . l i b o p e n c v _ v i d e o 2 3 1 d . l i b o p e n c v _ f e a t u r e s 2 d 2 3 1 d . l i b o p e n c v _ c a l i b 3 d 2 3 1 d . l i b o p e n c v _ o b j d e t e c t 2 3 1 d . l i b o p e n c v _ c o n t r i b 2 3 1 d . l i b o p e n c v _ l e g a c y 2 3 1 d . l i b o p e n c v _ f l a n n 2 3 1 d . l i b

The letter d at the end just indicates that these are the libraries required for the debug. Now click ok to save and do the same with a new property inside the Release rule section. Make sure to omit the d letters from the library names and to save the property sheets with the save icon above them.

You can find your property sheets inside your projects directory. At this point it is a wise decision to back them up into some special directory, to always have them at hand in the future, whenever you create an OpenCV project. Note that for Visual Studio 2010 the file extension is props, while for 2008 this is vsprops.
docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html 3/8

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document

Next time when you make a new OpenCV project just use the Add Existing Property Sheet... menu entry inside the Property Manager to easily add the OpenCV build rules.

The global method


In case you find to troublesome to add the property pages to each and every one of your projects you can also add this rules to a global property page. However, this applies only to the additional include and library directories. The name of the libraries to use you still need to specify manually by using for instance: a Property page. In Visual Studio 2008 you can find this under the: Tools Options Projects and Solutions VC++ Directories.

In Visual Studio 2010 this has been moved to a global property sheet which is automatically added to every project you create:

The process is the same as described in case of the local approach. Just add the include directories by using the environment variable OPENCV_DIR.

Test it!
Now to try this out download our little test s o u r c ec o d eor get it from the sample code folder of the OpenCV sources. Add this to your project and build it. Heres its content:
/ /V i d e oI m a g eP S N Ra n dS S I M # i n c l u d e< i o s t r e a m >/ /f o rs t a n d a r dI / O # i n c l u d e< s t r i n g > / /f o rs t r i n g s # i n c l u d e< i o m a n i p > / /f o rc o n t r o l l i n gf l o a tp r i n tp r e c i s i o n # i n c l u d e< s s t r e a m > / /s t r i n gt on u m b e rc o n v e r s i o n # i n c l u d e< o p e n c v 2 / i m g p r o c / i m g p r o c . h p p > / /G a u s s i a nB l u r # i n c l u d e< o p e n c v 2 / c o r e / c o r e . h p p > / /B a s i cO p e n C Vs t r u c t u r e s( c v : : M a t ,S c a l a r ) # i n c l u d e< o p e n c v 2 / h i g h g u i / h i g h g u i . h p p > / /O p e n C Vw i n d o wI / O u s i n gn a m e s p a c es t d ; u s i n gn a m e s p a c ec v ; d o u b l eg e t P S N R(c o n s tM a t &I 1 ,c o n s tM a t &I 2 ) ; S c a l a rg e t M S S I M (c o n s tM a t &I 1 ,c o n s tM a t &I 2 ) ; 4/8

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 v o i dh e l p ( ) { c o u t < <" \ n "< <e n d l < <" T h i sp r o g r a ms h o w sh o wt or e a dav i d e of i l ew i t hO p e n C V .I na d d i t i o n ,i tt e s t st h e " < <"s i m i l a r i t yo ft w oi n p u tv i d e o sf i r s tw i t hP S N R ,a n df o rt h ef r a m e sb e l o waP S N R" < <e n d l < <" t r i g g e rv a l u e ,a l s ow i t hM S S I M . " < <e n d l < <" U s a g e : " < <e n d l < <" . / v i d e o s o u r c er e f e r e n c e V i d e ou s e C a s e T e s t V i d e oP S N R _ T r i g g e r _ V a l u eW a i t _ B e t w e e n _ F r a m e s"< <e n d l < <" " < <e n d l < <e n d l ; } i n tm a i n ( i n ta r g c ,c h a r* a r g v [ ] ,c h a r* w i n d o w _ n a m e ) { h e l p ( ) ; i f( a r g c! =5 ) { c o u t< <" N o te n o u g hp a r a m e t e r s "< <e n d l ; r e t u r n1 ; } s t r i n g s t r e a mc o n v ; c o n s ts t r i n gs o u r c e R e f e r e n c e=a r g v [ 1 ] , s o u r c e C o m p a r e W i t h=a r g v [ 2 ] ; i n tp s n r T r i g g e r V a l u e ,d e l a y ; c o n v< <a r g v [ 3 ]< <a r g v [ 4 ] ; / /p u ti nt h es t r i n g s c o n v> >p s n r T r i g g e r V a l u e> >d e l a y ; / /t a k eo u tt h en u m b e r s c h a rc ; i n tf r a m e N u m=1 ; / /F r a m ec o u n t e r

V i d e o C a p t u r ec a p t R e f r n c ( s o u r c e R e f e r e n c e ) , c a p t U n d T s t ( s o u r c e C o m p a r e W i t h ) ; i f(! c a p t R e f r n c . i s O p e n e d ( ) ) { c o u t < <" C o u l dn o to p e nr e f e r e n c e"< <s o u r c e R e f e r e n c e< <e n d l ; r e t u r n1 ; } i f (! c a p t U n d T s t . i s O p e n e d ( ) ) { c o u t < <" C o u l dn o to p e nc a s et e s t"< <s o u r c e C o m p a r e W i t h< <e n d l ; r e t u r n1 ; } S i z er e f S=S i z e ( ( i n t )c a p t R e f r n c . g e t ( C V _ C A P _ P R O P _ F R A M E _ W I D T H ) , ( i n t )c a p t R e f r n c . g e t ( C V _ C A P _ P R O P _ F R A M E _ H E I G H T ) ) , u T S i=S i z e ( ( i n t )c a p t U n d T s t . g e t ( C V _ C A P _ P R O P _ F R A M E _ W I D T H ) , ( i n t )c a p t U n d T s t . g e t ( C V _ C A P _ P R O P _ F R A M E _ H E I G H T ) ) ; i f( r e f S! =u T S i ) { c o u t< <" I n p u t sh a v ed i f f e r e n ts i z e ! ! !C l o s i n g . "< <e n d l ; r e t u r n1 ; } c o n s tc h a r *W I N _ U T=" U n d e rT e s t " ; c o n s tc h a r *W I N _ R F=" R e f e r e n c e " ; / /W i n d o w s n a m e d W i n d o w ( W I N _ R F ,C V _ W I N D O W _ A U T O S I Z E) ; n a m e d W i n d o w ( W I N _ U T ,C V _ W I N D O W _ A U T O S I Z E) ; c v M o v e W i n d o w ( W I N _ R F ,4 0 0 , c v M o v e W i n d o w ( W I N _ U T ,r e f S . w i d t h ,

0 ) ; 0 ) ;

/ / 7 5 0 , 2( b e r n a t= 0 ) / / 1 5 0 0 ,2

c o u t< <" F r a m er e s o l u t i o n :W i d t h = "< <r e f S . w i d t h< <" H e i g h t = "< <r e f S . h e i g h t < <"o fn r # :"< <c a p t R e f r n c . g e t ( C V _ C A P _ P R O P _ F R A M E _ C O U N T )< <e n d l ; c o u t< <" P S N Rt r i g g e rv a l u e"< < s e t i o s f l a g s ( i o s : : f i x e d )< <s e t p r e c i s i o n ( 3 )< <p s n r T r i g g e r V a l u e< <e n d l ; M a tf r a m e R e f e r e n c e ,f r a m e U n d e r T e s t ; d o u b l ep s n r V ; S c a l a rm s s i m V ; w h i l e (t r u e )/ / S h o wt h ei m a g ec a p t u r e di nt h ew i n d o wa n dr e p e a t { c a p t R e f r n c> >f r a m e R e f e r e n c e ; c a p t U n d T s t> >f r a m e U n d e r T e s t ; i f (f r a m e R e f e r e n c e . e m p t y ( ) | |f r a m e U n d e r T e s t . e m p t y ( ) ) { c o u t< <"<<< G a m eo v e r ! >>>" ; 5/8

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document 1 0 0 1 0 1 1 0 2 1 0 3 1 0 4 1 0 5 1 0 6 1 0 7 1 0 8 1 0 9 1 1 0 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 2 0 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 3 0 1 3 1 1 3 2 1 3 3 1 3 4 1 3 5 1 3 6 1 3 7 1 3 8 1 3 9 1 4 0 1 4 1 1 4 2 1 4 3 1 4 4 1 4 5 1 4 6 1 4 7 1 4 8 1 4 9 1 5 0 1 5 1 1 5 2 1 5 3 1 5 4 1 5 5 1 5 6 1 5 7 1 5 8 1 5 9 1 6 0 1 6 1 1 6 2 1 6 3 1 6 4 1 6 5 1 6 6 1 6 7 1 6 8 1 6 9 1 7 0 1 7 1 1 7 2 1 7 3 1 7 4 1 7 5 1 7 6 1 7 7 1 7 8 1 7 9 1 8 0 1 8 1 1 8 2 1 8 3 b r e a k ; } + + f r a m e N u m ; c o u t< < " F r a m e : "< <f r a m e N u m ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /P S N R/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / p s n r V=g e t P S N R ( f r a m e R e f e r e n c e , f r a m e U n d e r T e s t ) ; / / g e tP S N R c o u t< <s e t i o s f l a g s ( i o s : : f i x e d )< <s e t p r e c i s i o n ( 3 )< <p s n r V< <" d B " ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /M S S I M/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / i f( p s n r V<p s n r T r i g g e r V a l u e ) { m s s i m V=g e t M S S I M ( f r a m e R e f e r e n c e , f r a m e U n d e r T e s t ) ; c o u t< <"M S S I M :" < <" R "< <s e t i o s f l a g s ( i o s : : f i x e d )< <s e t p r e c i s i o n ( 3 )< <m s s i m V . v a l [ 2 ]*1 0 0 < <" G "< <s e t i o s f l a g s ( i o s : : f i x e d )< <s e t p r e c i s i o n ( 3 )< <m s s i m V . v a l [ 1 ]*1 0 0 < <" B "< <s e t i o s f l a g s ( i o s : : f i x e d )< <s e t p r e c i s i o n ( 3 )< <m s s i m V . v a l [ 0 ]*1 0 0 ; } c o u t< <e n d l ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /S h o wI m a g e/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / i m s h o w (W I N _ R F ,f r a m e R e f e r e n c e ) ; i m s h o w (W I N _ U T ,f r a m e U n d e r T e s t ) ; c=c v W a i t K e y ( d e l a y ) ; i f( c= =2 7 )b r e a k ; } r e t u r n0 ; } d o u b l eg e t P S N R ( c o n s tM a t &I 1 ,c o n s tM a t &I 2 ) { M a ts 1 ; a b s d i f f ( I 1 ,I 2 ,s 1 ) ; / /| I 1-I 2 | s 1 . c o n v e r t T o ( s 1 ,C V _ 3 2 F ) ; / /c a n n o tm a k eas q u a r eo n8b i t s s 1=s 1 . m u l ( s 1 ) ; / /| I 1-I 2 | ^ 2 S c a l a rs=s u m ( s 1 ) ; / /s u me l e m e n t sp e rc h a n n e l

d o u b l es s e=s . v a l [ 0 ]+s . v a l [ 1 ]+s . v a l [ 2 ] ;/ /s u mc h a n n e l s i f (s s e< =1 e 1 0 )/ /f o rs m a l lv a l u e sr e t u r nz e r o r e t u r n0 ; e l s e { d o u b l e m s e= s s e/ ( d o u b l e ) ( I 1 . c h a n n e l s ( )*I 1 . t o t a l ( ) ) ; d o u b l ep s n r=1 0 . 0 * l o g 1 0 ( ( 2 5 5 * 2 5 5 ) / m s e ) ; r e t u r np s n r ; } } S c a l a rg e t M S S I M (c o n s tM a t &i 1 ,c o n s tM a t &i 2 ) { c o n s td o u b l eC 1=6 . 5 0 2 5 ,C 2=5 8 . 5 2 2 5 ; / * * * * * * * * * * * * * * * * * * * * * * * * * * * * *I N I T S* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / i n td =C V _ 3 2 F ; M a tI 1 ,I 2 ; i 1 . c o n v e r t T o ( I 1 ,d ) ; i 2 . c o n v e r t T o ( I 2 ,d ) ; M a tI 2 _ 2 =I 2 . m u l ( I 2 ) ; M a tI 1 _ 2 =I 1 . m u l ( I 1 ) ; M a tI 1 _ I 2 =I 1 . m u l ( I 2 ) ; / /c a n n o tc a l c u l a t eo no n eb y t el a r g ev a l u e s / /I 2 ^ 2 / /I 1 ^ 2 / /I 1*I 2

/ * * * * * * * * * * * * * * * * * * * * * * * * * * *E N DI N I T S* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / M a tm u 1 ,m u 2 ; / /P R E L I M I N A R YC O M P U T I N G G a u s s i a n B l u r ( I 1 ,m u 1 ,S i z e ( 1 1 ,1 1 ) ,1 . 5 ) ; G a u s s i a n B l u r ( I 2 ,m u 2 ,S i z e ( 1 1 ,1 1 ) ,1 . 5 ) ; M a tm u 1 _ 2 = M a tm u 2 _ 2 = M a tm u 1 _ m u 2= m u 1 . m u l ( m u 1 ) ; m u 2 . m u l ( m u 2 ) ; m u 1 . m u l ( m u 2 ) ;

M a ts i g m a 1 _ 2 ,s i g m a 2 _ 2 ,s i g m a 1 2 ; G a u s s i a n B l u r ( I 1 _ 2 ,s i g m a 1 _ 2 ,S i z e ( 1 1 ,1 1 ) ,1 . 5 ) ; s i g m a 1 _ 2=m u 1 _ 2 ; 6/8

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document 1 8 4 1 8 5 1 8 6 1 8 7 1 8 8 1 8 9 1 9 0 1 9 1 1 9 2 1 9 3 1 9 4 1 9 5 1 9 6 1 9 7 1 9 8 1 9 9 2 0 0 2 0 1 2 0 2 2 0 3 2 0 4 2 0 5 2 0 6 } G a u s s i a n B l u r ( I 2 _ 2 ,s i g m a 2 _ 2 ,S i z e ( 1 1 ,1 1 ) ,1 . 5 ) ; s i g m a 2 _ 2=m u 2 _ 2 ; G a u s s i a n B l u r ( I 1 _ I 2 ,s i g m a 1 2 ,S i z e ( 1 1 ,1 1 ) ,1 . 5 ) ; s i g m a 1 2=m u 1 _ m u 2 ; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /F O R M U L A/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / M a tt 1 ,t 2 ,t 3 ; t 1=2*m u 1 _ m u 2+C 1 ; t 2=2*s i g m a 1 2+C 2 ; t 3=t 1 . m u l ( t 2 ) ;

/ /t 3=( ( 2 * m u 1 _ m u 2+C 1 ) . * ( 2 * s i g m a 1 2+C 2 ) )

t 1=m u 1 _ 2+m u 2 _ 2+C 1 ; t 2=s i g m a 1 _ 2+s i g m a 2 _ 2+C 2 ; t 1=t 1 . m u l ( t 2 ) ; / /t 1= ( ( m u 1 _ 2+m u 2 _ 2+C 1 ) . * ( s i g m a 1 _ 2+s i g m a 2 _ 2+C 2 ) ) M a ts s i m _ m a p ; d i v i d e ( t 3 ,t 1 ,s s i m _ m a p ) ; / /s s i m _ m a p= t 3 . / t 1 ;

S c a l a rm s s i m=m e a n (s s i m _ m a p) ;/ /m s s i m=a v e r a g eo fs s i mm a p r e t u r nm s s i m ;

You can start a Visual Studio build from two places. Either inside from the IDE (keyboard combination: C o n t r o l F 5 ) or by navigating to your build directory and start the application with a double click. The catch is that these two arent the same. When you start it from the IDE its current working directory is the projects directory, while otherwise it is the folder where the application file currently is (so usually your build directory). Moreover, in case of starting from the IDE the console window will not close once finished. It will wait for a keystroke of yours. This is important to remember when you code inside the code open and save commands. Youre resources will be saved ( and queried for at opening!!!) relatively to your working directory. This is unless you give a full, explicit path as parameter for the I/O functions. In the code above we open t h i sO p e n C Vl o g o . Before starting up the application make sure you place the image file in your current working directory. Modify the image file name inside the code to try it out on other images too. Run it and voil:

Command line arguments with Visual Studio


Throughout some of our future tutorials youll see that the programs main input method will be by giving a runtime argument. To do this you can just start up a commmand windows ( c m d+E n t e rin the start menu), navigate to your executable file and start it with an argument. So for example in case of my upper project this would look like:
1 2 3 D : C DO p e n C V \ M y S o l u t i o n N a m e \ R e l e a s e M y S o l u t i o n N a m e . e x ee x a m p l e I m a g e . j p g

Here I first changed my drive (if your project isnt on the OS local drive), navigated to my project and start it with an example image argument. While under Linux system it is common to fiddle around with the console window on the Microsoft Windows many people come to use it almost never. Besides, adding the same argument again and again while you are testing your application is, somewhat, a cumbersome task. Luckily, in the Visual Studio there is a menu to automate all this:

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

7/8

crosoft 10/10/12 Visual Studio OpenCV v2.4.2 document

Specify here the name of the inputs and while you start your application from the Visual Studio enviroment you have automatic argument passing. In the next introductionary tutorial youll see an in-depth explanation of the upper source code: Load and Display an Image.

Help and Feedback


You did not find what you were looking for? Ask a question in the user group/mailing list. If you think something is missing or wrong in the documentation, please file a bug report.

docs.opencv.org/doc/tutorials/introduction//windows_visual_studio_Opencv.html

8/8

You might also like