1 Using OpenCV with biicode dependency manager {#tutorial_biicode} 2 ============================================ 3 4 Goals 5 ----- 6 In 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 12 What is biicode? 13 ---------------- 14 15  16 [biicode](http://opencv.org/biicode.html) resolves and keeps track of dependencies and version compatibilities in C/C++ projects. 17 Using 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 19 Prerequisites 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 25 Explanation 26 ----------- 27 28 ### Example: Detect faces in images using the Objdetect module from OpenCV 29 30 Once 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 38 Windows users also execute: 39 40 @code{.bash} 41 $ bii cpp:configure -G "Visual Studio 12" 42 @endcode 43 44 Now 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 50 Find your binaries in the bin folder: 51 52 @code{.bash} 53 $ cd bin 54 $ ./diego_opencvex_main 55 @endcode 56 57  58 59 @code{.bash} 60 $ ./diego_opencvex_mainfaces 61 @endcode 62 63  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 73 in the headers of your ``.cpp`` file. 74 75 To start a new project using OpenCV, execute: 76 77 @code{.bash} 78 $ bii init mycvproject 79 $ cd mycvproject 80 @endcode 81 82 The 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 88 Now replace your *main.cpp* contents inside *blocks/myuser/myblock* with **your app code**. 89 Put the includes as: 90 91 @code{.cpp} 92 #include "diego/opencv/opencv/cv.h 93 @endcode 94 95 If you type: 96 97 @code{.bash} 98 $ bii deps 99 @endcode 100 101 You 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 107 Now, 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 115 And 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 126 If 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 133 replace 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 142 Find 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 147 This 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 149 Results and conclusion 150 ---------------------- 151 152 Installing OpenCV with biicode is straight forward for any OS. 153 154 Run 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 156 Switching between OpenCV versions is available too and effortless. 157 158 For any doubts or further information regarding biicode, suit yourselves at [Stackoverflow](http://stackoverflow.com/questions/tagged/biicode?sort=newest), biicodes [forum](http://forum.biicode.com/) or [ask biicode](http://web.biicode.com/contact-us/), we will be glad to help you.