1Using OpenCV with biicode dependency manager {#tutorial_biicode}
2============================================
3
4Goals
5-----
6In this tutorial you will learn how to:
7
8  * Get started with OpenCV using biicode.
9  * Develop your own application in OpenCV with biicode.
10  * Switching between OpenCV versions.
11
12What is biicode?
13----------------
14
15![](images/biicode.png)
16[biicode](http://opencv.org/biicode.html) resolves and keeps track of dependencies and version compatibilities in C/C++ projects.
17Using biicode *hooks feature*, **getting started with OpenCV in C++ and C** is pretty straight-forward. **Just write an include to OpenCV headers** and biicode will retrieve and install OpenCV in your computer and configure your project.
18
19Prerequisites
20-------------
21
22  * biicode. Here is a [link to install it at any OS](http://www.biicode.com/downloads).
23  * Windows users: Any Visual Studio version (Visual Studio 12 preferred).
24
25Explanation
26-----------
27
28### Example: Detect faces in images using the Objdetect module from OpenCV
29
30Once biicode is installed, execute in your terminal/console:
31
32@code{.bash}
33$ bii init mycvproject
34$ cd mycvproject
35$ bii open diego/opencvex
36@endcode
37
38Windows users also execute:
39
40@code{.bash}
41$ bii cpp:configure -G "Visual Studio 12"
42@endcode
43
44Now execute ``bii cpp:build`` to build the project. @note This can take a while, until it downloads and builds OpenCV. However, this is downloaded just once in your machine to your "user/.biicode" folder. If the OpenCV installation process fails, you might simply go there, delete OpenCV files inside "user/.biicode" and repeat.
45
46@code{.bash}
47$ bii cpp:build
48@endcode
49
50Find your binaries in the bin folder:
51
52@code{.bash}
53$ cd bin
54$ ./diego_opencvex_main
55@endcode
56
57![](images/biiapp.png)
58
59@code{.bash}
60$ ./diego_opencvex_mainfaces
61@endcode
62
63![](images/bii_lena.png)
64
65###Developing your own application
66
67**biicode works with include headers in your source-code files**, it reads them and retrieves all the dependencies in its database. So it is as simple as typing:
68
69@code{.cpp}
70    #include "diego/opencv/opencv/cv.h"
71@endcode
72
73in the headers of your ``.cpp`` file.
74
75To start a new project using OpenCV, execute:
76
77@code{.bash}
78$ bii init mycvproject
79$ cd mycvproject
80@endcode
81
82The next line just creates a *myuser/myblock* folder inside "blocks" with a simple "Hello World" *main.cpp* into it. You can also do it manually:
83
84@code{.bash}
85$ bii new myuser/myblock --hello=cpp
86@endcode
87
88Now replace your *main.cpp* contents inside *blocks/myuser/myblock* with **your app code**.
89Put the includes as:
90
91@code{.cpp}
92    #include "diego/opencv/opencv/cv.h
93@endcode
94
95If you type:
96
97@code{.bash}
98$ bii deps
99@endcode
100
101You will check that ``opencv/cv.h`` is an "unresolved" dependency. You can find it with:
102
103@code{.bash}
104$ bii find
105@endcode
106
107Now, you can just `bii cpp:configure` and `bii cpp:build` your project as described above.
108
109**To use regular include directives**, configure them in your **biicode.conf** file. Let your includes be:
110
111@code{.cpp}
112    #include "opencv/cv.h"
113@endcode
114
115And write in your **biicode.conf**:
116
117@code{.cpp}
118    [includes]
119        opencv/cv.h: diego/opencv
120    [requirements]
121        diego/opencv: 0
122@endcode
123
124###Switching OpenCV versions
125
126If you want to try or develop your application against **OpenCV 2.4.10** and also against **3.0-beta**, change it in your **biicode.conf** file, simply alternating track in your `[requirements]`:
127
128@code{.cpp}
129    [requirements]
130        diego/opencv: 0
131@endcode
132
133replace with:
134
135@code{.cpp}
136    [requirements]
137        diego/opencv(beta): 0
138@endcode
139
140@note The first time you switch to 3.0-beta, it will also take a while to download and build the 3.0-beta release. From that point on you can change back and forth between versions just by modifying your *biicode.conf requirements*.
141
142Find the hooks and examples:
143* [OpenCV 2.4.10](http://www.biicode.com/diego/opencv)
144* [OpenCV 3.0 beta](http://www.biicode.com/diego/diego/opencv/beta)
145* [objdetect module from OpenCV](@ref tutorial_table_of_content_objdetect)
146
147This is just an example of how can it be done with biicode python hooks. Probably now that CMake files reuse is possible with biicode, it could be better to implement it with CMake, in order to get more control over the build of OpenCV.
148
149Results and conclusion
150----------------------
151
152Installing OpenCV with biicode is straight forward for any OS.
153
154Run any example like you just did with *objdetect module* from OpenCV, or develop your own application. It only needs a *biicode.conf* file to get OpenCV library working in your computer.
155
156Switching between OpenCV versions is available too and effortless.
157
158For any doubts or further information regarding biicode, suit yourselves at [Stackoverflow](http://stackoverflow.com/questions/tagged/biicode?sort=newest), biicode’s [forum](http://forum.biicode.com/) or [ask biicode](http://web.biicode.com/contact-us/), we will be glad to help you.