I have a question about ROI (metadataSDK)

Answered

Comments

17 comments

  • Avatar
    Andrey Terentyev

    Hello Aqua,

    ROI can be declared in Engine manifest and in Device agent manifest. They are displayed in GUI, when a plugin is enabled on a camera. Once the "Ok" or "Apply" button is pressed in GUI, actual settings values are passed to the Server, which passes values to a plugin.

    There are several ways to redeclare/override plugin setting values (including ROI):

    1. in getManifest of a device agent, when plugin is enabled on a camera;

    Your can "draw" new ROI by specifying new values and even new settings model in your plugin.

    2. in getPluginSideSettings of a device agent, which is called when plugin settings are going to be edited;

    The same as in 1.

    3. in doSetSettings of a device agent, when plugin settings are going to be saved.

    You can evaluated received setting values and recalculate your ROI.

    4. If you don't need to display any ROI, you can just skip declaration of ROI in you manifest files and calculate ROI inside your plugin as it is required by your objective.

    0
    Comment actions Permalink
  • Avatar
    Nx Support

    Regions of interests are supported in 4.1 version. Please, refer to the latest patch here: https://meta.nxvms.com/downloads/patches

    0
    Comment actions Permalink
  • Avatar
    Aqua Hsu

    Hi Andrey,

    Thank you.

    getPluginSideSettings is exactly the method that I want, but it still can’t work well with ROI. I have already tried the following string :

    1. setValue(testPolygon, "{\"figure\":{\"color\":\"#e040fb\",\"points\":[[0.2,0.2],[0.2,0.5],[0.9,0.6]]},\"label\":\"\",\"showOnCamera\":true}" );
    2. setValue(testPolygon, R”json({"figure":{"color":"#7c4dff","points":[[0.2,0.2],[0.2,0.5],[0.9,0.6]]},"label":"","showOnCamera":true})json" );
    0
    Comment actions Permalink
  • Avatar
    Aqua Hsu

    In addition, defaultValue  is work on ROI in the manifestString?

    0
    Comment actions Permalink
  • Avatar
    Aqua Hsu

    Give me some suggestions ヽ(`Д´)ノ 

    Please ( ´•̥̥̥ω•̥̥̥` )

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

     Hello Aqua,

    Let's consider example of using getPluginSideSettings from stub_analytics_plugin.

    void DeviceAgent::getPluginSideSettings(
    Result<constISettingsResponse*>*outResult) const

    {
    const auto response = newSettingsResponse();
    response->setValue("pluginSideTestSpinBox", "100");
    *outResult = response;
    }

    As you can see, the method returns nothing, however initiates and manupulates the SettingsResponse class (see src/nx/sdk/helpers/settings_response.h) the setValue method of that is declared like this:

    void setValue(std::stringkey, std::stringvalue);

    The key parameter should contain a sting with either new setting name or a setting name declared in DeviceAgent manifest.

    The value parameter should contain a string with the value corresponding to the key.

    In your case the testPolygon should be a string, I suppose. Like this

    setValue("testPolygon", ....

     

     

     

    0
    Comment actions Permalink
  • Avatar
    Aqua Hsu

    testPolygon is a string variable in the manifestString that I create:

    {

    "type": "PolygonFigure",

    "name": ")json" + testPolygon + R"json(",

    "caption": "Polygon"

     }

    The problem that bothers me most is I can’t update the ROI value correctly and display it on the camera. Do I set the wrong format on stringvalue, or just it can’t really work with ROI?

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Aqua,

    > testPolygon is a string variable in the manifestString that I create:

    The testPolygon is a NAME of the setting. The setting has several properties which could be changed.

    In order to change the properties of the testPolygon setting,  you should pass the name in quotes - "testPolygon" and properties to be changed as JSON object.

    Try this

    setValue("testPolygon", "{\"figure\":{\"color\":\"#e040fb\",\"points\":[[0.2,0.2],[0.2,0.5],[0.9,0.6]]},\"label\":\"\",\"showOnCamera\":true}" );

     

    0
    Comment actions Permalink
  • Avatar
    Aqua Hsu

    Hi,

    I try that again as you said today, but it always return null from settingValue, and it can't display on camera.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hi Aqua,

    I'm going to create a ticket to request additional details. Please check you email box for messages from our ticket system.

    On resolution the answer will be published in this thread.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    The problem was solved by updating to the latest available build of MetaVMS.

    0
    Comment actions Permalink
  • Avatar
    Luciano Roberto

    Hi Andrey,

    1. I would like to set the ROI when the plugin is enabled on a camera. How to use getManifest() in DeviceAgent in order to do that? Below is what I have tried so far, but without success.

    void DeviceAgent::getManifest(nx::sdk::Result<const nx::sdk::IString*>* outResult) const
    {   
        auto settingsResponse = new SettingsResponse();
        //set default ROI
    settingsResponse->setValue(kRoiSetting, "{\"figure\":{\"color\":\"#e040fb\",\"points\":[[0.0001,0.0001],[0.0001,0.9999],[0.9999,0.9999],[0.9999,0.0001]]},\"label\":\"\",\"showOnCamera\":true}");
    }

    2. Is there a way to directly set a ROI inside the settings model? Something like below.

    {
       "type": "PolygonFigure",
       "name" : "ROI1",
       "minPoints": 4,
       "maxPoints": 8,
       "defaultValue": {"figure":{"color":"#e040fb","points":[[0.0001,0.0001],[0.0001,0.9999],[0.9999,0.9999],[0.9999,0.0001]]},"label":"","showOnCamera":true}"
    }
    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Luciano Roberto ,

    Could you please provide the following info: OS version, VMS build, Metadata SDK version?

    0
    Comment actions Permalink
  • Avatar
    Luciano Roberto

    O.S: Windows 10 Pro (64 bit)
    VMS build (Client & Server): 5.0.0.35745
    Metadata SDK version: 5.0.0.35745

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Thanks for your response.

    Regarding 1.

    The getManifest() method should manipulate *outResult parameter passed.

    Here is an example from the Metadata SDK.

    void ConsumingDeviceAgent::getManifest(Result<const IString*>* outResult) const
    {
        *outResult = new String(manifestString());
    }

    Pay your attention, the outResult it's of type Result<const IString*>* not a SettingResponse class.

    Regarding 2.

    Yes, see the answer to question 1. You can manipulate manifest string.

    I'd recommend you using getPluginSideSettings method, where you could use SettingResponse class for manipulating values, which is more convenient.

    In addition, I'd suggest you seeing the roi section of the strub_analytics_plugin source code in the Metadata SDK.

    0
    Comment actions Permalink
  • Avatar
    Luciano Roberto

    Thanks for your response.

    Using getPluginSideSettings() method is really convenient. The only problem is that it will always "reset" the ROI to whatever value you set inside this method, even though you change it from the UI.

    But the ideia is to set the ROI to a default value when the plugin is enabled on a camera by using the getManifest() method in DeviceAgent class. Again, assuming that I have the following manifest string: 

    std::string kDeviceAgentSettingsModel = 1 + R"json(
    {
        {
           "type": "GroupBox",
         "caption": "ROI Settings",
           "items":
           [
              {   
                 "type": "GroupBox",
                 "caption": "ROI1",
                 "items":
                 [   
                    {
                       "type": "PolygonFigure",
                     "name": "ROI1",
                     "minPoints": 3,
                       "maxPoints": 8
                    }
                ]
             }                                                          
          ]
       }                    
    }
    )json";

    how to manipulate the outResult string in order to achieve what i mentioned?

    void DeviceAgent::getManifest(Result<const IString*>* outResult) const
    {
        //attempt #1:  won't work
        *outResult = new String(manifestString()); 
        
        //attempt #2:  won't work
        //*outResult = new String(kDeviceAgentSettingsModel); 
       
        //attempt #3: won't work
        /*
        const auto response = new SettingsResponse();
        nx::kit::Json::array jsonPoints{
            nx::kit::Json::array{0.138, 0.551},
            nx::kit::Json::array{0.775, 0.429},
            nx::kit::Json::array{0.748, 0.844}};
        nx::kit::Json::object jsonFigure;
        jsonFigure.insert(std::make_pair("points", jsonPoints));
        nx::kit::Json::object jsonResult;
        jsonResult.insert(std::make_pair("figure", jsonFigure));
        response->setValue("ROI1", nx::kit::Json(jsonResult).dump());
        *outResult = new String(kDeviceAgentSettingsModel); 
        */
    }
    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello,

    But the ideia is to set the ROI to a default value when the plugin is enabled on a camera by using the getManifest() method in DeviceAgent class. 

    It's a bad idea resetting value to defaults when a plugin is enabled/disabled on a camera.

    Technically, enabling/disabling a plugin means creating/destroying an instance of the DeviceAgent class.

    I'll give an example. When a camera fails over to another Server, DeviceAgent instance is destroyed on one server and created on another server. This would reset plugin settings on a camera. I guess, it's not what you would expect.

    There are better options, I'd recommend, for achieving what you want.

    In v5.0, you could create a checkbox control named "Reset values", for instance, in the settings model.

    When you check this control in the GUI and click the "Apply" button, the value would be sent to the plugin and can be analyzed in the settingsReceived() method, which could return default hardcoded values to the Server.

    In v5.1, you could create an active control. A special button for resetting values. For more details on active controls see the metadata_sdk/src/nx/sdk/settings_model.md file of the Metadata SDK 5.1.0.35837 R2 available here https://meta.nxvms.com/downloads/betas

    0
    Comment actions Permalink

Please sign in to leave a comment.