Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (88 sloc) 4.23 KB

OpenCV

OpenCV (Open Source Computer Vision Library) is a great open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products.

The versions of OpenCV library at biicode are:

Both versions are available at biicode using the :ref:`hooks feature <hooks_conf>` generated from this github repo.

In this example we'll show how to get started with OpenCV using two features: showing an image and detecting faces with the object detection module.

Showing an image and detecting faces

In this example we'll show how to get started with OpenCV using two features: showing an image and detecting faces with the object detection module.

Creating a new project

Create a project and place the source files and images inside:

$ bii init opencv_sample -L
$ cd opencv_sample
$ # copy all following files inside
  • Showing an image:

main.cpp

.. literalinclude:: /_static/code/cpp/examples/opencv/main.cpp
   :language: cpp
   :linenos:

Download file: :download:`bii.png </_static/img/c++/examples/bii.png>`.

  • Object detection example uses a CascadeClasifier class and a xml file with the algorithm to detect faces.

mainface.cpp

.. literalinclude:: /_static/code/cpp/examples/opencv/mainface.cpp
   :language: cpp
   :linenos:

Download files: :download:`hugh.png </_static/img/c++/examples/hugh.png>`, :download:`haarcascade_eye_tree_eyeglasses.xml </_static/code/cpp/examples/opencv/haarcascade_eye_tree_eyeglasses.xml>`, :download:`haarcascade_frontalface_alt.xml </_static/code/cpp/examples/opencv/haarcascade_frontalface_alt.xml>`.

Manage your dependencies

Check the dependencies of the project with bii deps:

$ bii deps
INFO: Processing changes...
examples/mycvproject depends on:
      system:
         iostream
         stdio.h
      unresolved:
         opencv/cv.h
         opencv/highgui.h
         opencv2/highgui/highgui.hpp
         opencv2/imgproc/imgproc.hpp
         opencv2/objdetect/objdetect.hpp

Edit biicode.conf file generated in the project folder. Add your [requirements] depending on the version you want and map your [includes] and your [data]:

[requirements]
    diego/opencv: 2

[includes]
   opencv/*: diego/opencv
   opencv2/*: diego/opencv

[data]
   main.cpp + bii.png
   mainface.cpp + haarcascade_frontalface_alt.xml haarcascade_eye_tree_eyeglasses.xml hugh.png

Now, checking bii deps, your dependencies are resolved.

Build the project

Now execute bii build to build the project.

Windows users need Visual Studio. Execute:

$ bii configure -G "Visual Studio 12"
$ bii build

Go to bin directory and execute the binaries:

$ cd bin
$./youruser_opencv_sample_main

/_static/img/c++/examples/opencv_bii.png

$./youruser_opencv_sample_mainface

/_static/img/c++/examples/opencv_hugh.png

Open and build

This example is already in biicode at examples/opencv_sample, so you can give it a try.

Create a new project and open the block:

$ bii init mycvproject
$ cd mycvproject
$ bii open examples/opencv_sample

Just build and run both examples:

$ bii build
$./youruser_opencv_sample_main
$./youruser_opencv_sample_mainface

Got any doubts? Do not hesitate to contact us visit our forum and feel free to ask any questions.