Before continuing, read the commented source code of the sample plugin.
Renaming in CMakeLists.txt
Modify the names in CMakeLists.txt to match our plugin:
- Open CMakeLists.txt
- Use the Find/Replace panel.
Note: The most important rename is the one of the target_compile_definitions - it produces the resulting library with the new name.
- Replace sample with opencv_object_detection
- Replace SAMPLE with OPENCV_OBJECT_DETECTION
- Save CMakeLists.txt.
- The project name has changed to opencv_object_detection_analytics_plugin.
- Rebuild the project
- Confirm that the resulting binary file name has changed as well with the command:
- We should see libopencv_object_detection_analytics_plugin.so
As it was mentioned in the Plugin control flow section, the analytics plugin consists of three helper classes:
Plugin- implemented in plugin.cpp and plugin.h.
Engine- implemented in engine.cpp and engine.h.
DeviceAgent- implemented in device_agent.cpp and device_agent.h.
Each of those classes contains the
manifestString() method which returns the corresponding manifest. Manifests are the
std::string that happen to be JSON with a particular structure. It defines the attributes of a plugin, its settings, the input and output of the plugin.
You can always look at the
- src/nx/sdk/analytics/manifests.md of Metadata SDK for all the available manifest options;
- src/nx/sdk/settings_model.md of metadata SKD for all the available settings model options;
- stub_atalytics_plugin of Metadata SDK for an example of the manifest implementation (see samples/stub_analytics_plugin/).
Adjusting a plugin titles in the manifest
Adjust the plugin manifest to make our plugin have the appropriate name show up in the Desktop Client:
- Open the plugin.cpp file
- Find the
- Update the manifest with the code below (the modified elements are in bold):
std::string Plugin::manifestString() const
return /*suppress newline*/ 1 + R"json(
"name": "OpenCV object detection",
"This plugin is for object detection and tracking. It's based on OpenCV."R"json(",
"vendor": "Sample Inc."
The manifest utilizes raw string literals since JSON contains quotes. Note that the description string in the plugin manifest does not fit into one C++ line, so we close the raw string literal, concatenate it with the string literal containing the description, and then reopen it.
You can find details on the manifest parameters we renamed by reading the comments inside plugin.cpp.
We have made some changes, let’s rebuild the plugin. Because of the changes in "CMakeLists.txt", the plugin library now has the name "libopencv_object_detection_analytics_plugin.so". Remove the previous version of the plugin and copy the new one:
sudo rm $SERVER_DIR/bin/plugins/libsample_analytics_plugin.so
sudo cp $BUILD_DIR/libopencv_object_detection_analytics_plugin.so $SERVER_DIR/bin/plugins/
Now we restart the Server and the Desktop Client to notice the changes. After opening the camera settings, we see that the plugin is successfully loaded and has a new name.