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. Review the Supported Operating Systems article for more information.
This tutorial focuses on Ubuntu 22.04, the g++ compiler, and %VMS_NAME% version 5.1. For additional information on installing Ubuntu, refer to the Ubuntu Linux OS Installation Guide.
Installing prerequisite packages
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. The following table outlines the compatibility between Server versions and g++ compilers.
Server version | g++ version |
4.0 | g++ -9 |
5.0 | g++ -10 |
5.1 | g++ -12 |
-
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. - Unzip – A package containing ZIP utilities used to extract the contents of the Metadata SDK 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 <= 2.0 - A C/C++ Package Manager. Reference link to conan documentation.
To install the packages:
- Execute the following commands in the shell:
sudo apt update
sudo apt install g++-12 unzip git python3.10 python3-pip
sudo rm /usr/bin/g++
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/g++-12 /usr/bin/g++
sudo ln -s /usr/bin/gcc-12 /usr/bin/gcc - Install cmake.
wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-x86_64.sh
chmod +x cmake-3.28.3-linux-x86_64.sh
sudo ./cmake-3.28.3-linux-x86_64.sh --prefix=/opt/cmake/
sudo ln -s /opt/cmake/cmake-3.28.3-linux-x86_64/bin/cmake /usr/bin/cmake
sudo apt updateInstall cmake - Install conan.
sudo pip3 install conan==1.62
- Confirm that the package indexes are updated.
In addition, we need the OpenCV framework, which is downloaded and installed automatically by CMake and the Conan package manager during the build process.
Further details are provided in the Installing and linking OpenCV framework section.
Note: Make sure the version of OpenCV that Ubuntu provides is not installed.
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 article.
- Download a Ubuntu Beta version of the VMS
- 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 SDK that matches the VMS downloaded
- 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
In this tutorial, instead of accessing a physical camera, we will use Testcamera. Testcamera is a service that emulates a video file as an IP camera.
Save this sample video file locally. The sample video is needed to demonstrate object detection and tracking within the tutorial.
Review the Testcamera: IP Camera Emulator article and establish a testcamera instance before continuing.
Starting from a template
To speed up the plugin development, we will use a template-plugin called "sample_analytics_plugin" located in the following location:
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 will build the plugin using cmake in the command line interface. To do this, we must pass the build directory, source code directory, and the path to the Metadata SDK source code in the metadataSdkDir cmake variable with the following method:
mkdir build
cmake -DmetadataSdkDir=./metadata_sdk -B ./build opencv_object_detection_analytics_plugin
cmake --build ./build --config Release -- -j
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=%VMS_LIN_PATH%
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.
You have managed to load and enable the sample plugin!
Comments
0 comments
Article is closed for comments.