To start things off, we need to prepare our workspace for developing the plugin. The VMS Server officially supports various versions of Ubuntu and Windows, you can see a full list of supported OSs and versions here.
This tutorial focuses on Ubuntu 18.04, g++ compiler, and Qt Creator IDE. Click here for information on installing Ubuntu,
Most of the necessary prerequisites are available as an installable package thanks to the Ubuntu and Conan communities:
- G++ compiler (version ≥ 8) – A compiler in Linux used to compile C++ programs.
- CMake – A popular software tool for managing the build process of software.
Note: You can write the plugin without it, but we recommend using it because it saves time. The CMake build configuration file that is included into Metadata SDK needs only minimal adjustments. - QT Creator – A cross-platform C++, JavaScript and QML integrated development environment.
- Unzip – A package that contains ZIP extraction utilities. We need it to extract the MetadataSDK archive.
- Git – A popular distributed version control system. We need it to clone the repository with supporting code.
- Python version => 3.5 - A popular programming language.
- Conan - the C/C++ Package Manager for Developers. Installation instructions can be found here.
To install the package
- Execute the following commands in the shell:
sudo apt update
sudo apt install g++-8 cmake qtcreator unzip git python3.6
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/g++-8 /usr/bin/g++ - Confirm that the package indexes are updated.
In addition, we need the OpenCV framework. The framework will be downloaded and installed automatically by CMake and Conan package manager during the build process. Details will be covered in the Installing and linking OpenCV framework section.
Note: The version of OpenCV that Ubuntu provides is not suitable for our plugin.
Installing MetaVMS
For this tutorial, we need the latest build of MetaVMS installed on the same computer.
- Sign up for access to the Meta Developer Portal by following the steps described in Get an Nx Meta Build.
- Once approved, download the latest MetaVMS.
- Install MetaVMS by running
sudo apt install <path to MetaVMS .deb file>
- Go to http://localhost:7001 and follow the instructions to create a new system and set the admin password.
Downloading Metadata SDK
- Create a folder for development:
mkdir -p ~/develop
cd ~/develop - Download the latest Metadata SDK.
- Extract the zip file:
unzip <path to Metadata SDK .zip file>
- Confirm that the package successfully extracted to the metadata_sdk folder.
Emulating a camera
Instead of using a physical camera in this tutorial, we will use Testcamera, a special emulator that can turn a video file into an IP camera.
We will use this video for object detection and tracking.
Starting from a template
To speed up the plugin development, we are going to use a template-plugin called "sample_analytics_plugin". It is located in "metadata_sdk/samples/sample_analytics_plugin”.
Copy the plugin to the “~/develop” directory:
cp -a metadata_sdk/samples/sample_analytics_plugin opencv_object_detection_analytics_plugin
The sample plugin is like "Hello, World!" for programming languages - it is the simplest working plugin that shows only one object, that moves from top left to bottom right corner with the name "Hello, World!", and generates the "New track started" events.
We need two build directories for our project. Let's create them.
mkdir -p ~/develop/builds/opencv_object_detection_analytics_plugin_release
mkdir -p ~/develop/builds/opencv_object_detection_analytics_plugin_debug
Open the project in Qt Creator as follows:
- Open Qt Creator.
- Press Open Project.
- Navigate to
~/develop/opencv_object_detection_analytics_plugin
- Double-click on CMakeLists.txt.
- Select the required kit (probably called "Desktop").
- Select Debug and Release builds.
For Debug build select~/develop/builds/opencv_object_detection_analytics_plugin_debug
For Release choose~/develop/builds/opencv_object_detection_analytics_plugin_release
- Press Configure Project.
At this point, you have probably received a “Configuration Failed” error. What happened? The reason for this is that CMake does not know how to build the project, it’s missing the location of Metadata SDK. Let's resolve this issue by setting the "metadataSdkDir" cached CMake variable:
- Go to the Projects page (the button on the left bar).
- Press the Add button (located to the right of the variables).
- Press Directory.
- Double-click on the key and write "metadataSdkDir".
- Double-click on the value and write "~/develop/metadata_sdk".
- Press the Enter key.
- Press Apply Configuration Changes.
Set the "metadataSdkDir" variable for both Debug and Release configurations.
Now we will build the plugin by pressing the Build button at the bottom left (or Menu Bar > Build > Build All). After this, we see that we got the following file among other files in the build directory: libsample_analytics_plugin.so.
Loading and enabling the plugin
If the Server is installed in $SERVER_DIR, then the binary files are located in $SERVER_DIR/bin/. Plugins enabled by default are in $SERVER_DIR/bin/plugins and plugins that are disabled by default are in $SERVER_DIR/bin/plugins_optional.
To load the plugin, copy it to the plugins directory. We need to define the $BUILD_DIR and $SERVER_DIR variables accordingly.
BUILD_DIR=~/develop/builds/opencv_object_detection_analytics_plugin_debug
SERVER_DIR=/opt/networkoptix-metavms/mediaserver
sudo cp $BUILD_DIR/libsample_analytics_plugin.so $SERVER_DIR/bin/plugins/
Now we can restart the MetaVMS Server:
sudo systemctl restart networkoptix-metavms-mediaserver
It is the time to open the Desktop client and enable the plugin for a specific camera:
- Open the Desktop client.
- Login to the Server.
- Right-click on the camera.
- Select Camera Settings.
- Go to the Plugins tab.
- Enable the plugin. (Use the Enable slider from the Sample analytics plugin)
- Click OK.
We have managed to load and enable our first plugin!
Getting the source code of the examples
For reading several sections, it’s necessary to have the source code of all the examples for version 5.0 presented in the current manual. Download the source code specific to version 5.0 from a branch of the open source repository by cloning it with git:
cd ~/develop
git clone https://github.com/networkoptix/nx_open_integrations.git
cd nx_open_integrations/cpp/vms_server_plugins/opencv_object_detection_analytics_plugin
Comments
0 comments
Article is closed for comments.