Why I get multiple bounding box
AnsweredHI,
I'm trying to draw one bbox on my screen, but I don't know why it comes out several bbox like below.

Here is my code.
Ptr<IMetadataPacket> DeviceAgent::generateObjectMetadataPacket()
{
// ObjectMetadataPacket contains arbitrary number of ObjectMetadata.
const auto objectMetadataPacket = makePtr<ObjectMetadataPacket>();
// Bind the object metadata to the last video frame using a timestamp.
objectMetadataPacket->setTimestampUs(last_video_frame_timestampUs_);
objectMetadataPacket->setDurationUs(0);
//for( size_t i = 0; i < this->object_size_; i++ ){
// const auto object_metadata = makePtr<ObjectMetadata>();
// object_metadata->setTypeId( "nx.sample.helloWorld" );
// auto track_id = nx::sdk::UuidHelper::fromStdString( std::to_string( this->object_list_[i].nObjectID ) );
// //auto track_id = nx::sdk::UuidHelper::randomUuid();
// object_metadata->setTrackId( track_id );
// float x = this->object_list_[i].nX / (float)this->video_width_;
// float y = this->object_list_[i].nY / (float)this->video_height_;
// float width = this->object_list_[i].nWidth / (float)this->video_width_;
// float height = this->object_list_[i].nHeight / (float)this->video_height_;
// object_metadata->setBoundingBox( Rect( x, y, width, height ) );
// objectMetadataPacket->addItem( object_metadata.get() );
// DumpDebugMessage( "x:%f y:%f object id:%d uuid:%d", x, y, this->object_list_[i].nObjectID, track_id );
//}
if( this->object_size_ != 0 ){
int i = 0;
const auto object_metadata = makePtr<ObjectMetadata>();
object_metadata->setTypeId( "nx.sample.helloWorld" );
//auto track_id = nx::sdk::UuidHelper::fromStdString( std::to_string( this->object_list_[i].nObjectID ) );
auto track_id = nx::sdk::UuidHelper::randomUuid();
object_metadata->setTrackId( track_id );
float x = this->object_list_[i].nX / (float)this->video_width_;
float y = this->object_list_[i].nY / (float)this->video_height_;
float width = this->object_list_[i].nWidth / (float)this->video_width_;
float height = this->object_list_[i].nHeight / (float)this->video_height_;
object_metadata->setBoundingBox( Rect( x, y, width, height ) );
objectMetadataPacket->addItem( object_metadata.get() );
}
//// 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);
//// Calculate bounding box coordinates each frame so that it moves from the top left corner
//// to the bottom right corner during kTrackFrameCount frames.
//static constexpr float d = 0.5F / kTrackFrameCount;
//static constexpr float width = 0.5F;
//static constexpr float height = 0.5F;
//const int frameIndexInsideTrack = m_frameIndex % kTrackFrameCount;
//const float x = d * frameIndexInsideTrack;
//const float y = d * frameIndexInsideTrack;
//objectMetadata->setBoundingBox(Rect(x, y, width, height));
//objectMetadataPacket->addItem(objectMetadata.get());
return objectMetadataPacket;
}
There is one more question. Why I can't set my unique trackId as string to uuid in setTrackId? I can't get any result if I use it, but randomUuid is work.
//auto track_id = nx::sdk::UuidHelper::fromStdString( std::to_string( this->object_list_[i].nObjectID ) );
auto track_id = nx::sdk::UuidHelper::randomUuid();
object_metadata->setTrackId( track_id );
0
-
This is likely due to the trackId. - same objects but duplicated tracks.
If you want to generate the UUID - please use nx::sdk::UuidHelper::randomUuid();
nx::sdk::UuidHelper::fromStdString( string );This method is that you have the UUID but in string format, then you use this method to generate/casting uuid-string in UUID type.
0
Please sign in to leave a comment.
Comments
1 comment