Skip to content

Third party library integration

Kynneb edited this page Apr 19, 2018 · 1 revision

In this tutorial we will learn how to add a third party dependency to an ESROCOS component

Prerequisites: Please make sure a camera device with id 0 (video0) is available on your machine. On a VirtualBox system, this is possible with the extension package under the PUEL licence, on a docker image it can be achieved by editing the docker run call.

HINT: If you're using the TASTE-VM with VirtualBox, you'll maybe need the VirtualBox Oracle VM VirtualBox Extension Pack to enable USB 2.2 / USB 3.0 to get a USB camera to work. The VirtualBox Extension Pack is available for Download at the VirtualBox Website.

After installing the Extension Pack, newer USB versions can be enabled in the Virtual Machine's settings. To forward a camera to the virtual machine, select a camera from Devices/Webcams within the main window of the running virtual machine.

Create a Component

If you do not know how to create an ESROCOS component, please have a look into the previous tutorial.

  • Go to the esrocos folder and create a new project esrocos_create_project tutorial-cam_capture
  • When asked for package dependencies, enter types/base and external/static_opencv.
  • Checkout and install dependencies via esrocos_fetch_dependencies

Open the taste GUI via esrocos_edit_project

  • Add a function camera, edit its properties and set the language to cpp
  • Add a sporadically called PI and name it capture

Then leave the gui and generate the code skeletons with esrocos_generate_skeletons

cd into the newly created camera folder and edit the camera.cc file to look like this:

#include "camera.h"
#include <opencv2/opencv.hpp>

using namespace cv;

void camera_startup()
{
    /* Write your initialization code here,
       but do not make any call to a required interface. */
}

void camera_PI_capture()
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
    
    namedWindow("raw",1);
    namedWindow("edges",2);
    
    Mat frame;
    Mat edges;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, COLOR_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("raw", frame);    
    imshow("edges", edges);
    if(waitKey(100) >= 0);
}

Add External Dependency

Adding dependency like external/opencv in the esrocos.yml (either by stating the dependency during project creation or by manually editing the file) results in an entry in the manifest.xml file (generated by esrocos_fetch_dependencies) which in turn tells autoproj to check out and install this dependency. Autoproj is able to handle os-packages as well as manually defined packages. As we need static libraries for opencv and those are commonly not included in the debian packages, we need to compile and install them ourselves. In the package-set "external" autoproj install instructions for the OpenCV library are stored.

For more information on autoproj see the here

Linking and Building External Libraries

To include OpenCV in the build process additional steps are neccesary: The esrocos build process augments the taste-build process, which builds the system as a whole. Therefore all the linking information of all system components and their respective (sub)dependencies have to be collected and provided to the taste build tools. To that end, ESROCOS utilizes pkg-config and cmake: In the project directory you will find a CMakeLists.txt which you have to edit to as follows:

cmake_minimum_required(VERSION 3.2)

project(tutorial-cam_capture)

include($ENV{ESROCOS_CMAKE})

esrocos_init()

esrocos_export_function("cam-capture" "tutorial/cam-capture")

esrocos_export_pkgconfig( VERSION 1.0
                          DESCRIPTION "none"
                          REQUIRES opencv
                        ) 

These commands will export your function to be reused and add an pkg-config file containing the linking information for the builder.

Congratulations, you successfully added an external dependency to an ESROCOS component.

Next tutorial: system integration

Clone this wiki locally