To declare object and event types for your integration, you can either define completely customized types or use predefined types from the taxonomy library. This guide walks you through both methods and shows you how to update your C++ namespaces.
Declare custom object types
Follow these steps to define custom object types to detect people, cats, and dogs by replacing the default Hello, World! object.
Open
device_agent.h.Rename the symbol
kHelloWorldObjectTypetokPersonObjectTypeacross your entire project.NOTE: If you are using Qt Creator, you can press Ctrl+Shift+R to find and replace across the project. In
device_agent.h, set the value ofkPersonObjectTypeto"sample.opencv_object_detection.person".Define constants for the cat and dog objects by adding the following code to
device_agent.h:const std::string kCatObjectType = "sample.opencv_object_detection.cat"; const std::string kDogObjectType = "sample.opencv_object_detection.dog";Open
device_agent.cppand update theDeviceAgent::manifestString()method to include the new object types in theobjectTypesarray: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"; }
Declare predefined object types
Predefined types reside in the default_type_library.json file within the Metadata SDK. To learn more about taxonomy, see metadata_sdk/src/nx/sdk/analytics/taxonomy.md.
To use predefined taxonomy types, whitelist them in the supportedTypes section of your manifest:
Open
device_agent.h.Rename the symbol
kHelloWorldObjectTypetokPersonObjectTypeacross your entire project.Define the constants for the predefined types by adding the following code to
device_agent.h:const std::string kPersonObjectType = "nx.base.Person"; const std::string kCatObjectType = "nx.base.Cat"; const std::string kDogObjectType = "nx.base.Dog";Open
device_agent.cppand update theDeviceAgent::manifestString()method with the following changes:Change the
objectTypesarray name tosupportedTypes.Inside the
supportedTypesarray, change theidkeys toobjectTypeId.Remove the
nameattributes, as predefined types include default attributes automatically.
Your updated manifest method should look like this:
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"; }
Update namespaces
Update the C++ namespaces across your integration files to match the new project structure.
Replace the old namespace structure:
namespace nx {
namespace vms_server_plugins {
namespace analytics {
namespace sample {
// ...
} // namespace sample
} // namespace analytics
} // namespace vms_server_plugins
} // namespace nxWith the new namespace structure:
namespace sample {
namespace analytics {
namespace opencv_object_detection {
// ...
} // namespace opencv_object_detection
} // namespace analytics
} // namespace sampleNext steps
After completes these updates, rebuild your integration, copy the new build to the Server, and verify your changes.
Comments
0 comments
Article is closed for comments.