How A Plugin Which Listen Metadata Able Push Metadata Packet To Specific Camera

Answered

Comments

5 comments

  • Avatar
    Ichiro

    Hi Sir,

    Thanks for the post, but we might need some more explanations to the “ The problem is, I can not use my plugin for Camera #2 and so on.”

    What configurations and codes you have implemented?

    Thanks.

    0
    Comment actions Permalink
  • Avatar
    Sales SPI

    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.

    0
    Comment actions Permalink
  • Avatar
    Ichiro

    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-plugin

    The 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.

    0
    Comment actions Permalink
  • Avatar
    Sales SPI

    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.

    0
    Comment actions Permalink
  • Avatar
    Sales SPI

    Hi Sir,

    I have succeeded sent JSON received by HTTP Server within Plugin from Engine level to any DeviceAgent I want based on its deviceId/cameraId, then objectMetadata and bestShot generated from it, and passed to Server.

    Case closed, thanks.

    0
    Comment actions Permalink

Please sign in to leave a comment.