Create your own processing units

Back to Tutorials

15. Video Exporter 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16



ViiM's architecture enables you to create your own processing units, extending ViiM's classes. There are two possible ways in which one can do this: i) one is by extending a class named ViiMUnitProcess and ii) the other is by extending ViiM's processing units directly.

ViiMUnitProcess is the unit process super class, which handles the data so each ViiM's processing unit can easily access their own information and process it separately from the other units. To better understand how ViiMUnitProcess relates to the other units, take a look at the on-line reference guide.

In this tutorial our sample does exactly that, extends the ViiMUnitProcess class. The idea is to create an addon processing unit that computes the histogram of the depth image. This processing unit declaration is in the file "ViiMAddonUnitHistogram.h". Let us take at look at this file, starting at line 9, where we declare the class.

Notice that the new class descend from "ViiMUnitProcess" and be aware not to forget to include it, as is done in line 3:

The only requirements that the new processing unit should have are two specific methods: i) init and ii) process. Those methods are used by the ViiM's kernel when managing all the data. The init method should contain the desired initializations and will run only once after the unit is registered with ViiM. Inside the process method you should include all the per-frame processing. ViiM's kernel will call this method at every frame, managing all the information the unit needs to work.

The private functions and variables implemented in our new processing unit are the following: Lines 57 and 59 refer to functions that actually compute the histograms, one with 256 bins and another with N bins. The number of bins used can be modified as we'll will see in a while. We use one variable for the depth image, two for the histograms and one to define the number of bins used to compute the histogram. Please refer to the file "ViiMAddonUnitHistogram.cpp" to check the actual implementation of the functions.

The reason to create processing units as addons for ViiM is organization and simplicity. The code becomes clearly modular and organized. Being able to register your processing unit with the ViiM's kernel, as if it was originally a ViiM's processing unit, also enables your unit to use all ViiM's kernel methods and not to worry about its internal management.

In our example we used this new processing unit in an application, in order to output the computed histogram to the console window. The declaration of the application class is in the file "UseHistogram.h" and is as follows: Notice in line 23 the declaration of a variable of type "ViiMAddonUnitHistogram", the class (ViiM's processing unit) just created. Now we are ready to use it, just have to register it and start using the methods created.

In line 26 of the implementation file, the "UseHistogram.cpp", we registered the unit: Registering the unit makes ViiM start its process, running the "init" method once and them the "process" method at every frame.

Now one can use it to get the computed histograms, as follows in the draw method:

Please note that this example serves only to explain how to implement your own processing units and that we do not intend to convince you that this is the best way to compute the depth image histograms. But imagine that you wanted just that. After implementing this specific processing unit you can easily start computing the depth histogram just by registering the unit. Then, to get the depth histogram, you just have to call the correspondent method. The code becomes really simple and organized.

Depending on the type of processing unit one intends to create it could be preferable to extend another particular unit. Imagine that one needs to create a unit to classify human body poses. In that case it would be useful to extend ViiMUnitSkeleton because you'll have access to all the skeleton information directly in your own unit. We hope you start imagining the potential offered by the creation of processing units inside ViiM and in the future we expect do develop it even further, offering more functionalities and probably defining a specific structure to implement addons like these.

If you have not done that before we also advice you to read the tutorial about ViiMUnitProcess in order to better understand the possibilities.

Now that you know how to use ViiM's awesome features, let's see if your creative brain is at the same level :D Good luck, CoVii

15. Video Exporter 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16

Back to Tutorials