How to make rectangle coordinates in NX plugin?

Answered

Comments

5 comments

  • Avatar
    Sergey Yuldashev

    Hello Akshay,

    Please follow the formulas below:

    • x2 = x1 + width
    • y2 = y1 + height
    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Sergey,
    Thanks for the response. Apart from this I have one more similar query.

    I have tried following:

    1. Calling rect function multiple times before return statement
    2. Calling rect and add function multiple times before return statement

    Both are not working

    How to draw multiple objects (rectangles) in single frame?

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Mohamed,

    In order to make several objects to be passed in one frame your should implement pullMetadataPackets , which makes possible to manipulated a vector of pointers to IMetadataPacket objects.

    For more details see documentation and example in device_agent.cpp of stub_analytics_plugin.

    0
    Comment actions Permalink
  • Avatar
    akshay thoughtclan

    Hello Sergey,

         Using the suggested formulae, I am able to get proper rectangles. 

     

    Hello Andrey,

         I have followed your suggestion, this is how my functions look like.

     

    |pullMetadataPackets|

     

    bool DeviceAgent::pullMetadataPackets(std::vector<IMetadataPacket*>* metadataPackets)
    {

    if((m_frameIndex%3)==0){

    *metadataPackets = cookSomeObjects();
    m_lastVideoFrameTimestampUs = 0;
    nx::kit::utils::format("generated %d metadata packet(s)", metadataPackets->size());

    // metadataPackets->push_back(generateObjectMetadataPacket().releasePtr());
    }


    return true; //< There were no errors while filling metadataPackets.
    }

     

     

    |cookSomeObjects|

     

    std::vector<IMetadataPacket*> DeviceAgent::cookSomeObjects()
    {

    std::vector<IMetadataPacket*> result;
    const auto metadataTimestampUs = m_frameTimestampUsQueue.front();
    auto objectMetadataPacket = makePtr<ObjectMetadataPacket>();
    objectMetadataPacket->setTimestampUs(metadataTimestampUs);
    objectMetadataPacket->setDurationUs(0);

    CURL *curl;
    CURLcode res;
    std::string readBuffer;
    std::string body = "path=/var/www/html/images/"+std::to_string(m_lastVideoFrameTimestampUs)+".jpg";

    curl = curl_easy_init();
    if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "localhost:5000/process");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    }

    auto j = json::parse(readBuffer);

    for (auto const& i : j) {

    // ObjectMetadata contains information about an object on the frame.
    const auto objectMetadata = makePtr<ObjectMetadata>();
    // Set all required fields.
    objectMetadata->setTypeId(kHelloWorldObjectType);
    objectMetadata->setTrackId(m_trackId);


    float a = i["coordinates"][0];
    float b = i["coordinates"][1];
    float c = i["coordinates"][2];
    float d = i["coordinates"][3];

    objectMetadata->setBoundingBox(Rect(a, b, c, d));
    objectMetadataPacket->addItem(objectMetadata.get());
    }

    result.push_back(objectMetadataPacket.releasePtr());

    return result;

    }

     

    I am not getting any bounding boxes on Client Application. I have a feeling that implementation is not done properly. 

    Can you help me in that? 

    0
    Comment actions Permalink

Please sign in to leave a comment.