There are several options for declaring object and event types.
- Declaring completely customized types.
- Declaring types predefined in the taxonomy library.
We will explore both options hereafter.
Declaring new detectable object types
We want to detect people and pets (to be precise, cats and dogs). For that we need to define the corresponding object types. Let's just replace "Hello, World!" object with the "Person" object and add two more types:
- Open device_agent.h
- Rename the symbol kHelloWorldObjectType to kPersonObjectType everywhere in the project.
Note: Qt Creator provides a handy shortcut for that action (Ctrl+Shift+R). - Change the value of kPersonObjectType to "sample.opencv_object_detection.person". The definition is located in the device_agent.h.
- Change the name value from "Hello, World!" to "Person" in the objectTypes array of
DeviceAgent::manifestString()
. - Define the "Cat" and "Dog" objects by adding two constants in device_agent.h to reuse them in code later:
const std::string kCatObjectType = "sample.opencv_object_detection.cat";
const std::string kDogObjectType = "sample.opencv_object_detection.dog"; - Finally, we change DeviceAgent manifest (located in the device_agent.cpp):
std::string DeviceAgent::manifestString() const
{
return /*suppress newline*/1 + R"json(
{
"typeLibrary" : {
"eventTypes": [
{
"id": ")json" + kNewTrackEventType + R"json(",
"name": "New track started"
}
],
"objectTypes": [
{
"id": ")json" + kPersonObjectType + R"json(",
"name": "Person"
},
{
"id": ")json" + kCatObjectType + R"json(",
"name": "Cat"
},
{
"id": ")json" + kDogObjectType + R"json(",
"name": "Dog"
}
]
}
}
)json";
}
Declaring new detectable object types in version 5.0
In version 5.0 a new feature is introduced called taxonomy, which implies using predefined object types either directly, or via inheriting and extending. You can read more about taxonomy in the Metadata SDK( see metadata_sdk/src/nx/sdk/analytics/taxonomy.md).
Predefined types can be found in the default_type_library.json file in the Metadata SDK. Object types to be supported by the plugin can be whitelisted in the "supported types" section of the manifest.
- Open device_agent.h
- Rename the symbol kHelloWorldObjectType to kPersonObjectType everywhere in the project.
Note: Qt Creator provides a handy shortcut for that action (Ctrl+Shift+R). - Change the value of kPersonObjectType to "nx.base.Person". The definition is located in the device_agent.h.
- Use three predefined types by adding constants in device_agent.h to reuse them in the code later:
const std::string kPersonObjectType = "nx.base.Person";
const std::string kCatObjectType = "nx.base.Cat";
const std::string kDogObjectType = "nx.base.Dog"; - Change the DeviceAgent manifest (located in the device_agent.cpp). In version 5.0, object types are enumerated in the “supportedTypes” section. Rename the "objectTypes” to “supportedTypes”.
-
Remove the name attribute from the supportedTypes array of the
DeviceAgent::manifestString()
, since predefined types have implicit default attributes. - In the "supportedTypes" array, rename “id ” to "objectTypeId”. Make sure there is no comma at the end of the line.
std::string DeviceAgent::manifestString() const
{
return /*suppress newline*/ 1 + R"json(
{
"typeLibrary" : {
"eventTypes": [
{
"id": ")json" + kNewTrackEventType + R"json(",
"name": "New track started"
}
]
},
"supportedTypes": [
{
"objectTypeId": ")json" + kPersonObjectType + R"json("
},
{
"objectTypeId": ")json" + kCatObjectType + R"json("
},
{
"objectTypeId": ")json" + kDogObjectType + R"json("
}
]
}
)json";
}
Renaming namespaces
As we know, using namespaces in C++ is always a good idea, that is why we have them in our sample plugin. We want to replace them in all files.
We replace:
namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace sample {
…
} // namespace sample
} // namespace analytics
} // namespace vms_server_plugins
} // namespace nx
With:
namespace sample {
namespace analytics {
namespace opencv_object_detection {
...
} // namespace opencv_object_detection
} // namespace analytics
} // namespace sample
It's time to rebuild the plugin, copy a new version to the Server, and observe the result.
Comments
0 comments
Article is closed for comments.