index.html 29.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Tutorials - OpenBR</title>
  

  <link rel="shortcut icon" href="../docs/img/openbr.ico">
   

  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> OpenBR</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
      <ul class="current">
    
        
            <li class="toctree-l0 ">
            <a class="" href="..">Home</a>
            
            </li>
        
    
        
            <li class="toctree-l0 ">
            <a class="" href="../install/">Install</a>
            
            </li>
        
    
        
            <li class="toctree-l0 current">
            <a class="current" href="./">Tutorials</a>
            
                <ul>
                    
                        
                            <li class="toctree-l1"><a href="#quick-start">Quick Start</a></li>
                        
                            <li class="toctree-l1"><a href="#algorithms-in-openbr">Algorithms in OpenBR</a></li>
                        
                            <li class="toctree-l1"><a href="#training-algorithms">Training Algorithms</a></li>
                        
                            <li class="toctree-l1"><a href="#face-recognition">Face Recognition</a></li>
                        
                            <li class="toctree-l1"><a href="#age-estimation">Age Estimation</a></li>
                        
                            <li class="toctree-l1"><a href="#gender-estimation">Gender Estimation</a></li>
                        
                    
                </ul>
            
            </li>
        
    
        
            <li class="toctree-l0 ">
            <a class="" href="../technical/">Technical Overviews</a>
            
            </li>
        
    
        
            <li class="toctree-l0 ">
            <a class="" href="../contribute/">Contribute</a>
            
            </li>
        
    
        
            <li class="toctree-l0 ">
            <a class="" href="../papers/">Publications</a>
            
            </li>
        
    
        
            <span>API Docs</span>
            
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/c_api/">C API</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/cpp_api/">C++ Plugin API</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/cl_api/">Command Line API</a>
            
            </li>
        
    
        
    
        
            <span>Plugin Docs</span>
            
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/classification/">Classification</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/cluster/">Cluster</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/core/">Core</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/distance/">Distance</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/format/">Format</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/gallery/">Gallery</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/gui/">GUI</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/imgproc/">Image Processing</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/io/">I/O</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/metadata/">Metadata</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/output/">Output</a>
            
            </li>
        
    
        
            <li class="toctree-l1 ">
            <a class="" href="../api_docs/plugins/video/">Video</a>
            
            </li>
        
    
        
    
</ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">OpenBR</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>Tutorials</li>
    <li class="wy-breadcrumbs-aside">
      
        
          <a href="https://github.com/biometrics/openbr" class="icon icon-github"> Edit on GitHub</a>
        
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <p>Welcome to OpenBR! Here we have a series of tutorials designed to get you up to speed on what OpenBR is, how it works, its command line interface, and the C API. These tutorials aren't meant to be completed in a specific order so feel free to hop around. If you need help, feel free to <a href="..#help">contact us</a>.</p>
<hr />
<h1 id="quick-start">Quick Start</h1>
<p>This tutorial is meant to familiarize you with the ideas, objects and motivations behind OpenBR using some fun examples. <strong>Note:</strong> parts of this tutorial require a webcam.</p>
<p>OpenBR is a C++ library built on top of QT and OpenCV. It can either be used from the command line using the <strong>br</strong> application, or from interfacing with the <a href="../api_docs/c_api/">C API</a>. The command line is the easiest and fastest way to get started and this tutorial will use it for all of the examples.</p>
<p>First, make sure that OpenBR has been installed on your system using the steps described in the <a href="../install/">installation section</a>. Then open up your terminal or command prompt and enter:</p>
<pre><code>$ br -gui -algorithm "Show(false)" -enroll 0.webcam
</code></pre>
<p>If everything goes well your webcam should have opened up and is streaming. Look you are using OpenBR! Let's talk about what's happening in this command. OpenBR expects flags to be prepended by a <em>-</em> and arguments to follow the flags and be separated by spaces. Flags normally require a specific number of flags. All of the possible flags and their values are <a href="../api_docs/cl_api/">documented here</a>. Let's step through the individual arguments and values. <strong>-gui</strong> is the flag that tells OpenBR to open up a GUI window. Take a look at the <a href="../api_docs/plugins/gui/">GUI plugins</a> for other plugins that require the <strong>-gui</strong> flag. <strong>-algorithm</strong> is one of the most important flags in OpenBR. It expects one argument called the <em>algorithm string</em>. This string determines the pipeline that images and metadata propagate through. Finally, <strong>-enroll</strong> reads files from disk and <em>enrolls</em> them into the image pipeline. It takes one input argument (0.webcam in our example) and an optional output argument. OpenBR has a range of formats that can be enrolled into algorithms, some examples include .jpg, .png, .csv, and .xml. .webcam tells OpenBR to enroll frames from the computers webcam.</p>
<p>Let's try a slightly more complicated example, after all OpenBR can do way more then just open webcams! Fire up the terminal again and enter:</p>
<pre><code>$ br -gui -algorithm "Cvt(Gray)+Show(false)" -enroll 0.webcam
</code></pre>
<p>Hey what happened? We took our normal BGR (OpenCV's alternative to RGB) image and converted it to a grayscale image. How did we do that? Simple, by adding "Cvt(Gray)" to the algorithm string. <a href="../api_docs/plugins/imgproc/#cvttransform">Cvt</a>, short for convert, is an example of an OpenBR <em>plugin</em>. <a href="../api_docs/plugins/gui/#showtransform">Show</a> is a plugin as well. Every algorithm string in OpenBR is just a series of plugins joined together into a pipeline. In fact the <strong>+</strong> symbol is shorthand for a <a href="../api_docs/plugins/core/#pipetransform">Pipe</a>, another kind of OpenBR plugin. We specify <strong>Gray</strong> to <a href="../api_docs/plugins/imgproc/#cvttransform">Cvt</a> as a runtime parameter to tell the plugin which color space to convert the image to. We also could have written <strong>Cvt(HSV)</strong> if we wanted to convert to the HSV color space or <strong>Cvt(Luv)</strong> if we wanted to convert to Luv. The arguments inside of the plugins are runtime parameters that can adjust the functionality. They can be provided as key-value pairs, <strong>Cvt(Gray)</strong> is equivalent to <strong>Cvt(ColorSpace=Gray)</strong>, or as keyless values. Make sure you are supplying parameters in the proper order if you are not using keys! Try and run the code with <strong>Show(true)</strong> and see how changing the parameters effect the output of the command (<strong>Hint:</strong> hit a key to cycle through the images).</p>
<p>Let's make this example a little bit more exciting and relevant to OpenBR's biometric roots. Face detection is normally the first step in a <a href="#face-recognition">face recognition</a> algorithm. Let's do face detection in OpenBR. Back in the terminal enter:</p>
<pre><code>$ br -gui -algorithm "Cvt(Gray)+Cascade(FrontalFace)+Draw(lineThickness=3)+Show(false)" -enroll 0.webcam
</code></pre>
<p>You're webcam should be open again but this time a box should have appeared around your face! We added two new plugins to our string, <a href="../api_docs/plugins/metadata/#cascadetransform">Cascade</a> and <a href="../api_docs/plugins/gui/#drawtransform">Draw</a>. Let's walk through this plugin by plugin and see how it works:</p>
<ol>
<li><a href="../api_docs/plugins/imgproc/#cvttransform">Cvt(Gray)</a>: Convert the image from BGR to grayscale. Grayscale is required for <a href="../api_docs/plugins/metadata/#cascadetransform">Cascade</a> to work properly.</li>
<li><a href="../api_docs/plugins/metadata/#cascadetransform">Cascade(FrontalFace)</a>: This is a wrapper on the OpenCV <a href="http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html">Cascade Classification</a> framework. It detects frontal faces using the <strong>FrontalFace</strong> model.</li>
<li><a href="../api_docs/plugins/gui/#drawtransform">Draw(lineThickness=3)</a>: Take the rects detected by <a href="../api_docs/plugins/metadata/#cascadetransform">Cascade</a> and draw them onto the frame from the webcam. <strong>lineThickness</strong> determines the thickness of the drawn rect.</li>
<li><a href="../api_docs/plugins/gui/#showtransform">Show(false)</a>: Show the image in a GUI window. <strong>false</strong> indicates the images should be shown in succession without waiting for a key press.</li>
</ol>
<p>Pretty straightforward right? Each plugin completes one task and the passes the output on to the next plugin. You can pipe together as many plugins as you like as long as the output data from one can be the input data to the next. But wait! Output data? Input data? we haven't talked about data at all yet! How does OpenBR handle data? There are two objects that handle data is OpenBR; <a href="../api_docs/cpp_api/file/file/">Files</a>, which handle metadata, and <a href="../api_docs/cpp_api/template/template/">Templates</a> which are containers for images and <a href="../api_docs/cpp_api/file/file/">Files</a>. Let's talk about <a href="../api_docs/cpp_api/file/file/">Files</a> first. A file consists of file name, which is a path to a file on disk, and metadata which is a map of key-value pairs. The metadata can contain any textual information about the file. In the example above we use it to store the rectangles detected by <a href="../api_docs/plugins/metadata/#cascadetransform">Cascade</a> and pass them along to <a href="../api_docs/plugins/gui/#drawtransform">Draw</a> for drawing. <a href="../api_docs/cpp_api/template/template/">Templates</a> are containers for images, given as OpenCV <a href="http://docs.opencv.org/modules/core/doc/basic_structures.html#mat" title="Mat">Mats</a> and <a href="../api_docs/cpp_api/file/file/">Files</a>. They can contain one image or a list of images. Plugins are either <a href="../api_docs/cpp_api/template/template/">Template</a> in, <a href="../api_docs/cpp_api/template/template/">Template</a> out or <a href="../api_docs/cpp_api/templatelist/templatelist/">TemplateList</a> in, <a href="../api_docs/cpp_api/templatelist/templatelist/">TemplateList</a> out. <a href="../api_docs/cpp_api/templatelist/templatelist/">TemplateLists</a> are, of course, just a list of <a href="../api_docs/cpp_api/template/template/">Templates</a> which a few functions added for your convenience.</p>
<p>And there you go! You have gotten your quick start in OpenBR. We covered the <a href="../api_docs/cl_api/">command line</a>, <a href="../api_docs/cpp_api/">plugins, and the key data structures</a> in OpenBR. If you want to learn more the next few tutorials will cover these fields with more depth. For even more information check out the <a href="../technical/">technical overviews</a> and class documentation!</p>
<hr />
<h1 id="algorithms-in-openbr">Algorithms in OpenBR</h1>
<p>The purpose of OpenBR is to express biometrics algorithms in a consistent and simple way. But what exactly does <em>algorithm</em> mean? In OpenBR an <em>algorithm</em> is a technique for enrolling templates associated with a technique for comparing them. Recall that our ultimate goal is to be able to say how similar two face images are (or two fingerprints, irises, etc.).</p>
<p>Instead of storing the entire raw image for comparison, it is common practice to store an optimized representation, or <em>template</em>, of the image for the task at hand. The process of generating this optimized representation is called <em>template enrollment</em> or <em>template generation</em>. Given two templates, <em>template comparison</em> computes the similarity between them, where the higher values indicate more probable matches and the threshold for determining what constitutes an adequate match is determined operationally. The goal of template generation is to design templates that are small, accurate, and fast to compare.</p>
<p>The only way of creating an algorithm in OpenBR is from a text string that describes it. We call this string the <em>algorithm description</em>. There are several motivations for mandating that algorithms are defined from these strings, here are the most important:</p>
<ol>
<li>It ensures good software development practices by forcibly decoupling the development of each step in an algorithm, facilitating the modification of algorithms and the re-use of individual steps.</li>
<li>It spares the creation and maintenance of a lot of very similar header files that would otherwise be needed for each step in an algorithm, observe the absence of headers in <code>openbr/plugins</code>.</li>
<li>It allows for algorithm parameter tuning without recompiling.</li>
<li>It is completely unambiguous, both the OpenBR interpreter and anyone familiar with the project can understand exactly what your algorithm does just from this description.</li>
</ol>
<p>OpenBR provides a syntax for creating more concise algorithm descriptions. The relevant symbols are:</p>
<table>
<thead>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>PluginName(property1=value1,...propertyN=valueN)</td>
<td>A plugin is described by its name (without the abstraction) and a list of properties and values. Properties of a plugin that are not specified are set to their default values.</td>
</tr>
<tr>
<td>:</td>
<td>Seperates <em>templatelate enrollment</em> from <em>template comparison</em>. Enrollment is on the left and comparison is on the right. This is optional, algorithms without comparisons are called <em>classifiers</em></td>
</tr>
<tr>
<td>+</td>
<td>Pipe. Joins plugins together and projects input through them in series. The output of a plugin to the left of + become the input of the plugin to the right.</td>
</tr>
<tr>
<td>/</td>
<td>Fork. Joins plugins together and projects input through them in parallel. All plugins get the same input and the output is concattenated together.</td>
</tr>
<tr>
<td>{}</td>
<td>Cache. Cache the output of a plugin in memory for quick lookups later on</td>
</tr>
<tr>
<td>&lt;></td>
<td>LoadStore. Plugins inside are stored on disk after training and / or loaded from disk before projection</td>
</tr>
<tr>
<td>()</td>
<td>Order of operations. Change the order of operations using parantheses.</td>
</tr>
</tbody>
</table>
<p>Let's look at some of the important parts of the code base that make this possible!</p>
<p>In <code>AlgorithmCore::init()</code> in <code>openbr/core/core.cpp</code> you can see the code for splitting the algorithm description at the colon.
Shortly thereafter in this function we <em>make</em> the template generation and comparison methods.
These make calls are defined in the public <a href="../api_docs/cpp_api/">C++ plugin API</a> and can also be called from end user code.</p>
<p>Below we discuss some of the source code for <code>Transform::make</code> in <code>openbr/openbr_plugin.cpp</code>.
Note, the make functions for other plugin types are similar in spirit and will not be covered.</p>
<p>One of the first steps when converting the template enrollment description into a <a href="../api_docs/cpp_api/transform/transform/">Transform</a> is to replace the operators, like '+', with their full form:</p>
<pre><code>{ // Check for use of '+' as shorthand for Pipe(...)
     QStringList words = parse(str, '+');
     if (words.size() &gt; 1)
         return make("Pipe([" + words.join(",") + "])", parent);
}
</code></pre>
<p>After operator expansion, the template enrollment description forms a tree, and the transform is constructed from this description starting recursively starting at the root of the tree:</p>
<pre><code>Transform *transform = Factory&lt;Transform&gt;::make("." + str);
</code></pre>
<p>Let's use the algorithm in <code>scripts/helloWorld.sh</code> as an example. The algorithm is:</p>
<pre><code>Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(128,128,0.33,0.45)+CvtFloat+PCA(0.95):Dist(L2)
</code></pre>
<p>So what is happening here? Let's expand this using our new knowledge of OpenBR's algorithm syntax. First, the algorithm will be split into enrollment and comparison portions at the <strong>:</strong>. So enrollment becomes-</p>
<pre><code>Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(128,128,0.33,0.45)+CvtFloat+PCA(0.95)
</code></pre>
<p>and comparison is-</p>
<pre><code>Dist(L2)
</code></pre>
<p>On the enrollment side the <strong>+'s</strong> are converted into a <a href="../api_docs/plugins/core/#pipetransform">PipeTransform</a> with the other plugins as children. Enrollment is transformed to</p>
<pre><code>Pipe(transforms=[Open,Cvt(Gray),Cascade(FrontalFace),ASEFEyes,Affine(128,128,0.33,0.45,CvtFloat,PCA(0.95)])
</code></pre>
<p>If you want all the tedious details about what exactly this algoritm does, then you should read the <a href="../api_docs/cpp_api/transform/functions/#project-1">project</a> function implemented by each of these plugins.
The brief explanation is that it <em>reads the image from disk, converts it to grayscale, runs the face detector, runs the eye detector on any detected faces, uses the eye locations to normalize the face for rotation and scale, converts to floating point format, and then embeds it in a PCA subspaced trained on face images</em>.
If you are familiar with face recognition, you will likely recognize this as the Eigenfaces<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup> algorithm.</p>
<p>As a final note, the Eigenfaces algorithms uses the Euclidean distance (or L2-norm) to compare templates.
Since OpenBR expects <em>similarity</em> values when comparing templates, and not <em>distances</em>, the <a href="../api_docs/plugins/distance/#distdistance">DistDistance</a> will return <em>-log(distance+1)</em> so that larger values indicate more similarity.</p>
<hr />
<h1 id="training-algorithms">Training Algorithms</h1>
<hr />
<h1 id="face-recognition">Face Recognition</h1>
<p>This tutorial gives an example on how to perform face recognition in OpenBR. OpenBR implements the 4SF<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup> algorithm to perform face recognition. Please read the the paper for more specific implementation details.</p>
<p>To start, lets run face recognition from the command line. Open the terminal and enter</p>
<pre><code>$ br -algorithm FaceRecognition \
    -compare ../data/MEDS/img/S354-01-t10_01.jpg ../data/MEDS/img/S354-02-t10_01.jpg \
    -compare ../data/MEDS/img/S354-01-t10_01.jpg ../data/MEDS/img/S386-04-t10_01.jpg
</code></pre>
<p>Easy enough? You should see results printed to terminal that look like</p>
<p>So what is 'FaceRecognition'? It's an abbrieviation to make running the algorithm easier. All of the algorithm abbreviations are located in <code>openbr/plugins/core/algorithms.cpp</code>, please see the previous tutorial for an introduction to OpenBR's algorithm grammar.</p>
<p>It also possible to perform face recognition evaluation (<strong>note:</strong> this requires <a href="http://www.r-project.org/" title="R">R</a> to be installed)-</p>
<pre><code>$ br -algorithm FaceRecognition -path ../data/MEDS/img/ \
    -enroll ../data/MEDS/sigset/MEDS_frontal_target.xml target.gal \
    -enroll ../data/MEDS/sigset/MEDS_frontal_query.xml query.gal \
    -compare target.gal query.gal scores.mtx \
    -makeMask ../data/MEDS/sigset/MEDS_frontal_target.xml ../data/MEDS/sigset/MEDS_frontal_query.xml MEDS.mask \
    -eval scores.mtx MEDS.mask Algorithm_Dataset/FaceRecognition_MEDS.csv \
    -plot Algorithm_Dataset/FaceRecognition_MEDS.csv MEDS
</code></pre>
<p>face recognition search-</p>
<pre><code>$ br -algorithm FaceRecognition -enrollAll -enroll ../data/MEDS/img 'meds.gal;meds.csv[separator=;]'
$ br -algorithm FaceRecognition -compare meds.gal ../data/MEDS/img/S001-01-t10_01.jpg match_scores.csv
</code></pre>
<p>and face recognition training-</p>
<pre><code>$ br -algorithm 'Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(128,128,0.33,0.45)+(Grid(10,10)+SIFTDescriptor(12)+ByRow)/(Blur(1.1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)+LBP(1,2)+RectRegions(8,8,6,6)+Hist(59))+PCA(0.95)+Normalize(L2)+Dup(12)+RndSubspace(0.05,1)+LDA(0.98)+Cat+PCA(0.95)+Normalize(L1)+Quantize:NegativeLogPlusOne(ByteL1)' -train ../data/ATT/img FaceRecognitionATT
</code></pre>
<p>all right from the command line! The entire command line API is documented <a href="../api_docs/cl_api/">here</a>. It is a powerful tool for creating and testing new algorithms. </p>
<p>The command line isn't perfect for all situations however. So OpenBR exposes a <a href="../api_docs/cpp_api/">C++ API</a> that can be embedded pretty much everywhere. Let's step through the example code at <code>app/example/face_recognition.cpp</code> and learn about using OpenBR as a library.</p>
<p>Our main function starts with-</p>
<pre><code>    br::Context::initialize(argc, argv)
</code></pre>
<p>This is the first step in any OpenBR application, it initializes the global context.</p>
<pre><code>QSharedPointer&lt;br::Transform&gt; transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer&lt;br::Distance&gt; distance = br::Distance::fromAlgorithm("FaceRecognition");
</code></pre>
<p>Here, we split our algorithm into <em>enrollment</em> (<a href="../api_docs/cpp_api/transform/transform/">Transform</a>::<a href="../api_docs/cpp_api/transform/statics/#fromalgorithm">fromAlgorithm</a>) and <em>comparison</em> (<a href="../api_docs/cpp_api/distance/distance/">Distance</a>::<a href="../api_docs/cpp_api/distance/statics/#fromalgorithm">fromAlgorithm</a>) </p>
<pre><code>br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
</code></pre>
<p>These lines create our <a href="../api_docs/cpp_api/template/template/">Templates</a> for enrollment. They are just images loaded from disk. For this example queryA is the same person (different picture) as target and queryB is a different person.</p>
<pre><code>queryA &gt;&gt; *transform;
queryB &gt;&gt; *transform;
target &gt;&gt; *transform;
</code></pre>
<p>And now we enroll them! <strong>&gt;&gt;</strong> is a convienience operator for enrolling <a href="../api_docs/cpp_api/template/template/">Templates</a> in <a href="../api_docs/cpp_api/transform/transform/">Transforms</a>. The enrollment is done in-place, which means the output overwrites the input. Our <a href="../api_docs/cpp_api/template/template/">Templates</a> now store the results of enrollment.</p>
<pre><code>float comparisonA = distance-&gt;compare(target, queryA);
float comparisonB = distance-&gt;compare(target, queryB);
</code></pre>
<p>Compare our query <a href="../api_docs/cpp_api/template/template/">Templates</a> against the target <a href="../api_docs/cpp_api/template/template/">Template</a>. The result is a float.</p>
<pre><code>printf("Genuine match score: %.3f\n", comparisonA);
printf("Impostor match score: %.3f\n", comparisonB);
</code></pre>
<p>Print out our results. You can see that comparisonA (between queryA and target) has a higher score then comparisonB, which is exactly what we expect!</p>
<pre><code>br::Context::finalize();
</code></pre>
<p>The last line in any OpenBR application has to be call to finalize. This shuts down OpenBR.</p>
<p>And that's it! Now you can embed face recognition into all of your applications.</p>
<hr />
<h1 id="age-estimation">Age Estimation</h1>
<hr />
<h1 id="gender-estimation">Gender Estimation</h1>
<!-- Links -->

<!-- Contributors -->

<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p><em>Matthew Turk and Alex Pentland.</em>
<strong>Eigenfaces for recognition.</strong> 
Journal of Cognitive Neuroscience, 3(1):71–86, 1991&#160;<a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:2">
<p><em>B. Klare.</em> 
<strong>Spectrally sampled structural subspace features (4SF).</strong> 
In Michigan State University Technical Report, MSUCSE-11-16, 2011&#160;<a class="footnote-backref" href="#fnref:2" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
</ol>
</div>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../technical/" class="btn btn-neutral float-right" title="Technical Overviews"/>Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../install/" class="btn btn-neutral" title="Install"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
    <!-- Copyright etc -->
    </p>
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
	  
        </div>
      </div>

    </section>

  </div>

<div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a class="icon icon-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../install/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../technical/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>


<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="../css/theme.css" type="text/css" />
<link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
<link rel="stylesheet" href="../css/highlight.css">

<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/modernizr-2.8.3.min.js"></script>
<script type="text/javascript" src="../js/highlight.pack.js"></script>
<script src="../js/theme.js"></script>

<!--
MkDocs version      : 0.12.1
Docs Build Date UTC : 2015-04-24 17:55:27.388636
-->
</body>
</html>