How A Plugin Which Listen Metadata Able Push Metadata Packet To Specific Camera
AnsweredHi,
I am new to NX Meta, so is to C++, only familiar with PHP and a little portion of JavaScript.
But, after strugle and pain, I am able to build my plugin, a .dll file for NX Meta in Windows, learned from samples of plugin in the NX Metadata C++ SDK. And works as good as expected for 1 Camera.
A little story, my plugin works as listener, receiving data from my PHP application, which act as middleware holding analytics metadata packet (id, timestamp, etc, including bounding box, base64 image) sent by ALPR/ANPR IP Camera. Since the Cameras has different Firmware, I must use middleware to translate the different data keys before send to my plugin, and push to NX Meta Server, or NX Meta Server pull them, both method tried and success. And later I will decide to use the frame from CompressedFrame (use this now) for best shot or from image stored in my PHP application using url.
I use NX Meta Server, Version 6.0.1.39873. NX Meta Client, Version 6.0.1.39873. Both installed and run in my laptop, Windows 10.
As I mentioned above, my plugin works, but only for 1 Camera. Its capabilities is deviceDependent, like I read in the tutorial of make plugin for Smart IP Camera.
The problem is, I can not use my plugin for Camera #2 and so on.
I tried to make different endpoints for each Camera using cameraId, failed, seems my knowledge of C++ library use for build the my plugin limited.
I tried also get the cameraId from DeviceInfo, and match it with the data received using logic, then pushMetadataPacket to the specific Camera by its Id, also failed.
I need advise, and maybe guidance if possible, please help.
I got idea to make several listeners in my plugin, will use different tcp port for each Camera, but I think not recommended, because took big resource if the number of Cameras many.
Thank you, hope to hear reply from you guys as the expert.
-
Hi Sir,
Thanks for your reply.
I am not using any configuration on event rule of camera for my plugin, all in the codes of it.
These informations below hope can help to explain what I want to achieve.
The data flow:
The json data:
{
"deviceId": "97d1ef1c-29bf-e8fd-d3bc-91582a3bdf7b",
"typeId": "nx.base.Vehicle",
"trackId": "f2f8ac39-5ba5-21d7-4597-505a16ff9640",
"attributes": {
"Color": "White",
"Brand": "Toyota",
"Model": "2109"
},
"boundingBox": {
"x": 1,
"y": 1,
"width": 1,
"height": 1
}
}
}
The codes to choose the deviceId to be push with metadata:
DeviceAgent::DeviceAgent(const nx::sdk::IDeviceInfo* deviceInfo) : ConsumingDeviceAgent(deviceInfo, true), m_deviceId(deviceInfo->id())
{
// -- using external library for listen incoming json data -- //
onDataReceived(jsonData);
}
void DeviceAgent::onDataReceived(const std::string& jsonData)
{
// -- using external library to parse json data -- //
for (auto& item : parsedData)
{
if (item.contains("deviceId") && item["deviceId"].is_string())
{
std::string deviceId = item["deviceId"].get<std::string>();
if (deviceId == m_deviceId)
{
auto objectMetadataPacket = generateObjectMetadataPacket(parsedData);
if (objectMetadataPacket)
{
pushMetadataPacket(objectMetadataPacket.releasePtr());
}
}
}
}
}
Plugin snapshot:
Result:
I tried to change the deviceId in json data with deviceId of camera #2, or #3 and so on, hoping the metadata works with camera who own the deviceId, but it just not work, only camera #1 works (with the correct deviceId). I think I have wrong understanding about where the logic to match the deviceId should be run (now in device_agent.cpp, or is it must in engine.cpp or maybe must in plugin.cpp).
Hope to hear your advise.
Thank you.
-
Hi ,
It looks likes you may have misunderstandings on the plugin subsystem of Nx Witness and its architecture.
If you have not read the plugin subsystem introduction, I highly recommend you can study the plugin subsystem first before you start to develop.Here is the introduction:
https://meta.nxvms.com/docs/developers/knowledgebase/200-introduction-to-creating-a-video-analytics-pluginThe engine.cpp is a factory of device agent. That being said - each of camera will have a dedicated deviceAgent instance for it which was created by the engine. As a result, it is likely incorrect to hack or manipulate the deviceId in the device agent.
Also, I am not sure where did you get the JSON, but within device agent (i.e MetaSDK), it should be object metadata, and you are asked to follow the proper flow. It might not be an ideal way, as it is overlaid and duplicated work for such tasks.
So, we sincerely you study the document first and try to follow the sample to understand the plugin system first before you start to implement the features.
Thanks.
-
Hi Sir,
Yes, I have misunderstanding, I already mentioned in my previous reply, that is why I am not in the right way, and need your advise.
The JSON comes from Middleware, and in my plugin I have http server capture the JSON, and send to DeviceAgent, it works to the rest of the flow, but only 1 camera.
I did study all the links you have given before build my plugin. But, wrong way, I don't know where to hack or manipulate the deviceId in order to send the metadata object to which camera I want based on the deviceId
Right now, after I read your advise, you gave me idea, I will try it in the engine.cpp, correct?
If still wrong, please, give me a clue.
Thanks.
Please sign in to leave a comment.
Comments
5 comments