How do i build the opencv_object_detection_analytics plugin

Completed

Comments

16 comments

  • Avatar
    Andrey Terentyev

    Hi m f ,

    Please, use the latest version of MetaVMS and Metadata SDK.

    Here is the right point to start from

    https://support.networkoptix.com/hc/en-us/community/posts/360015851593-Getting-started-with-plugin-development

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    At the moment we don't have a published guide, but we are working on a pretty detailed manual.

    Here is a beginning part of it.

    Step 0. Preparing a workspace

    First of all, we need to prepare our workspace for developing. The Server officially supports Ubuntu and Microsoft Windows. In this tutorial, we focus on Ubuntu, g++ compiler, and Qt Creator IDE. We use Ubuntu 18.04. 

    Thanks to the Ubuntu and Canon communities and, we have everything we need as an installable package.

    We execute in the shell:

    $ sudo apt update
    $ sudo apt install g++ cmake qtcreator unzip git

    First, we make sure that package indexes are updated. Second, we install the g++ compiler. Third, we install CMake, the popular software tool for managing the build process of software. You can write the plugin without it, but we recommend you to use it because it saves your time (the build configuration file that is included into Metadata SDK needs minimal adjustments). Then we install the Qt Creator IDE. We also install unzip (we need it for MetadataSDK archive extraction). Git is needed for cloning the repository with supporting code.

    We also need to install a recent OpenCV. Unfortunately, Ubuntu provides a version, which is not suitable for our plugin.

    We prepared a compiled version of OpenCV (with contrib modules included) and uploaded it to Conan repository: https://bintray.com/networkoptix/nx_open_intergrations/opencv:networkoptix. Conan (https://conan.io/) is the C/C++ Package Manager for Developers. For now, we just need to install it. The instructions on installation can be found here: https://docs.conan.io/en/latest/installation.html.

    Installing MetaVMS

    For this example we need the latest build of  MetaVMS installed on the same machine.

    Let’s sign up for the Meta dev Portal using the steps described in https://support.networkoptix.com/hc/en-us/articles/360046713714-Get-an-Nx-Meta-Build

    Once approved you will be able to download the latest MetaVMS and Metadata SDK here https://meta.nxvms.com/downloads/patches

    Let’s install MetaVMS by running

    $ sudo apt install <path to MetaVMS .deb file>

    Now we go to http://localhost:7001 and just follow the instructions. We set up a new system and set the admin password.

    Downloading Metadata SDK

    First, we create a folder for development:

    $ mkdir -p ~/develop
    $ cd ~/develop

    We can download the latest Metadata SDK from https://meta.nxvms.com/downloads/patches

    Then we extract the zip file:

    $ unzip metavms-metadata_sdk-4.0.0.29798-universal.zip

    This will extract the package to the metadata_sdk folder.

     

    Starting from a template

    To speed up the plugin development, we will 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 open our project in Qt Creator as follows:

    1. Open Qt Creator.
    2. Press "Open Project".
    3. Navigate to ~/develop/opencv_object_detection_analytics_plugin.
    4. Double-click on "CMakeLists.txt".
    5. Select the required kit (most probably called "Desktop").
    6. 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.

    1. Press "Configure Project".

    We see that there are two issues. What happened? The reason for those two issues is that CMake does not know how to build the project: it misses the location of Metadata SDK. Let's help it by setting a cached CMake variable:

    1. Go to the Projects page (the button on the left bar).
    2. Press the "Add" button at the right of the variables.
    3. Press "Directory".
    4. Double-click on the key and write "metadataSdkDir".
    5. Double-click on the value and write "~/develop/metadata_sdk".
    6. Press the Enter key.
    7. Press "Apply Configuration Changes".

    Now we want to build the plugin. For this, we press the "Build" button at the bottom left or go to ”Build”->”Build all” in the menu bar. 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 we have Server installed in $SERVER_DIR, then binary files are located in $SERVER_DIR/bin/. We put plugins enabled by default to $SERVER_DIR/bin/plugins, and plugins that are disabled by default to $SERVER_DIR/bin/plugins_optional.

    To load the plugin, we copy it to the plugins directory. We need to define $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 Server. Here is the command for MetaVMS Server:

    $ sudo systemctl restart networkoptix-metavms-mediaserver

    It is the time to open the Client and enable the plugin for a specific camera:

    1. Open the Client.
    2. Login to the Server.
    3. Right-click on the camera.
    4. Select "Camera Settings...".
    5. Go to the "Plugins" tab. We see the label "Sample analytics plugin" at the left panel and "Enable" slider on the right. 
    6. Enable the plugin, 
    7. Click OK, and see what happens.


    We have managed to load and enable our first plugin!

    Getting the source code of the examples

    For further reading it might be helpful to have the source code of all the examples presented in the current manual.

    We can download the source code for this article from an open source repository.

    Let's clone the repo:

    $ 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

    This folder contains readme.md file. You could have a look at it for further progression.

    MANUAL

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hi,

    i'm stuk on loading and enabling the plugin. When i do

    $ sudo cp $BUILD_DIR/libsample_analytics_plugin.so $SERVER_DIR/bin/plugins/

    i get

    cp: cannot stat '/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug/libsample_analytics_plugin.so': No such file or directory

    this is probably due to the fact that i have installed both NxWitness and NxMeta, and i have in opt folder networkoptix and networkoptix-metavms. Mediaserver folder is only in the networkoptix folder, and not in the -metavms. There is a way to proceed with both system installed or i have to unistall NxWitness ? I have a server running (only for test\play) with NxWitness.

    Thanks

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Matteo,

    The message

    cp: cannot stat '/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug/libsample_analytics_plugin.so': No such file or directory

    means literally, there is no such file "libsample_analytics_plugin.so" in the folder you specified.

    It's just because you are building the "opencv_object_detection_analytics_plugin" but are trying to copy the file of another plugin "sample_analytics_plugin".

    The file name should be "libopencv_object_detection_analytics_plugin.so".

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hi Matteo,

    I see now. I guess, you are in the Step 0 of this guide. In this case, the file name should be "libsample_analytics_plugin.so"

    https://support.networkoptix.com/hc/en-us/articles/360057028954-Step-0-Preparing-a-Workspace

    I just have rechecked the text of the guide and have completed the instruction step by step. It's accurate.

    Make sure the directory "/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug" exist.

    Make sure the directory "/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug" is actually indicated as a build directory in the Debug settings of the project in QtCreator.

    Make sure you have built the debug version of the plugin and not the release.

    When building is completed, try this command:

     ls /home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug 

    Do you see files and the libsample_analytics_plugin.so specifically?

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hi Andrey,

    Thank you for support.

    Your correction in the guide are probably the ones i made wrong (debug and release built).

    I will test asap and back to you.

    Thanks

     
     

     

     

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hi Andrey,

    no can't find the problem.

    I follow the guide in step 0 and i think the problem was related to "Repeat these steps for both Debug and Release configurations." that i don't know exactly what to do. what i have to write for debug and release ? I probably done something wrong in this phase because I add Debug and Release but on the value i write again "~/develop/metadata_sdk" for both.

    In this guide after 1. Press "Configure Project". there isn't "Repeat these steps for both Debug and Release configurations.". I have to do it or not?

    there is not /home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug

    but there is /home/mattelaci/develop/builds-opencv_object_detection_analytics_plugin_Desktop_Debug (there isn't a Builds folder)

    Thanks

     

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hi,

    i restart the procedure,as you can see QT creator show as default /builds-opencv instead of /builds/opencv and at first time didn't see it.

    I correct them and set /builds/opencv. Now i have only to know what means "Repeat these steps for both Debug and Release configurations." 

    Thanks,

     

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello,

    Thank you for your feedback.

    i restart the procedure,as you can see QT creator show as default /builds-opencv instead of /builds/opencv and at first time didn't see it.

    First, build directories for Release and Debug configurations should be different.

    Second, the directories should be created before set in the project configuration dialog.

    Now i have only to know what means "Repeat these steps for both Debug and Release configurations." 

    That means "Set the "metadataSdkDir" variable for both Debug and Release configurations".

    I made corrections, hope the guide will be updated soon after review.

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hello Andrey,

    sorry but can you please details better

    That means "Set the "metadataSdkDir" variable for both Debug and Release configurations".

    I mean, repeat wich steps , 1 to 7 ?

    If yes, when i add a directory, what i have to write in step 4 and step 5?

    thanks,

     

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hi,

    I mean, repeat wich steps , 1 to 7 ?

    Yes, exactly. Repeat these steps.

    1. Go to the Projects page (the button on the left bar).
    2. Press the Add button (located to the right of the variables).
    3. Press Directory.
    4. Double-click on the key and write "metadataSdkDir".
    5. Double-click on the value and write "~/develop/metadata_sdk".
    6. Press the Enter key.
    7. Press Apply Configuration Changes.

    If yes, when i add a directory, what i have to write in step 4 and step 5?

    In step 4, you should write this text "metadataSdkDir" as the name of the variable.

    In step 5, you should wite the path to the directory which you have extracted Metadata SDK to.

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    :) thanks for your patience, 

    I meant, what i have to write for debug and release repetition. metadataSdkDir and path to metadataSDK folder is for the "first pass", then for the second (debug) and the third (release) what wirte in the key\value added? 

    or you are telling to set 3 times the same value ?

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hello

    ok i solve, now i have debug and release folder in builds folder.

    after

    sudo cp $BUILD_DIR/libsample_analytics_plugin.so $SERVER_DIR/bin/plugins/

    I still get this error

    cp: cannot create regular file '/opt/networkoptix-metavms/mediaserver/bin/plugins/': No such file or directory

    and i confirm there is no mediaserver folder in networkoptix-metavms folder.

    Make sure the directory "/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug" exist.

    Confirmed.

    Make sure the directory "/home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug" is actually indicated as a build directory in the Debug settings of the project in QtCreator.

    Make sure you have built the debug version of the plugin and not the release.

    Seems ok.

    When building is completed, try this command:

     ls /home/mattelaci/develop/builds/opencv_object_detection_analytics_plugin_debug 

    Do you see files and the libsample_analytics_plugin.so specifically?

    Yes, some files and libsample_analytics_plugin.so is present.

     

    Thanks a lot,

    MAtteo

     

     

     

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    using

    $ SERVER_DIR=/opt/networkoptix/mediaserver

    seems working, mediaserver was already installed for Nx Witness. It can work ? (except for the following problem).

    now i have a problem of server incompatible but its due to beta-test we are performing for adding realsense camera and its an ongoing work.

    Do you know if i can install 2 Nx server simultaneously by adding a new NxMeta server (on the same machine) ?

    Thanks

     

    0
    Comment actions Permalink
  • Avatar
    matteo lacirignola

    Hello Andrey,

    start again from step0, installed a new server (is on port 7011 instead 7001), able to do all step0 (except cant download the video, i put my video for testcamera, it's shown). It run but when i enable plug-in there is nothing on the screen (no boundig box with hello world!).

    i perform step1. everything seems fine, i see the pulg-in (with new name and description) but i can't enable it. It's grey.

    Stuck on step2. Following the guide at the end when i rebuilt

    libopencv_object_detection_analytics_plugin.so

    dissapears from

    /develop/builds/opencv_object_detection_analytics_plugin_debug

    and can't go on.

    Any idea ?

    Thanks

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Matteo,

    Could you please provide the output of the building process?

    0
    Comment actions Permalink

Please sign in to leave a comment.