How to make rectangle coordinates in NX plugin?
AnsweredI am using a python request to detect objects in each frame from camera. it returns x1, y1 and x2, y2 to draw rectangles. x1, y1 represent starting point of rectangle and x2, y2 represent ending point of rectangle. This is the common data to draw a rectangle in python.
In network optix, I can see x, y values and height, width. I want to convert my (x1, x2, y1, y2) values to NX supported format (x, y, height, width). How to do this?
Can someone explain x, y, height and width in terms of (x1, y1, x2, y2)?
-
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 statementBoth are not working
How to draw multiple objects (rectangles) in single frame?
-
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.
-
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?
-
The code discussion was transferred to this thread
Please sign in to leave a comment.
Comments
5 comments