Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add pyBindings for NVDS_TRACKER_OBJ_REID_META #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/docstrings/nvdsmetadoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace pydsdoc
constexpr const char* NVDSINFER_SEGMENTATION_META=R"pyds(metadata type of segmentation model output attached by gst-nvinfer. Refer :class:`NvDsInferSegmentationMeta` for details.)pyds";
constexpr const char* NVDS_CROP_IMAGE_META=R"pyds(Specifies metadata type for JPEG-encoded object crops.See the deepstream-image-meta-test app for details.)pyds";
constexpr const char* NVDS_TRACKER_PAST_FRAME_META=R"pyds(metadata type to be set for tracking previous frames)pyds";
constexpr const char* NVDS_TRACKER_BATCH_REID_META=R"pyds(The ReID vectors for the whole batch generated by tracker. )pyds";
constexpr const char* NVDS_TRACKER_OBJ_REID_META=R"pyds(The ReID information for a single object generated by tracker. )pyds";
constexpr const char* NVDS_AUDIO_BATCH_META=R"pyds(Specifies metadata type for formed audio batch.)pyds";
constexpr const char* NVDS_AUDIO_FRAME_META=R"pyds(Specifies metadata type for audio frame.)pyds";
constexpr const char* NVDS_RESERVED_META=R"pyds(Reserved field)pyds";
Expand Down
23 changes: 23 additions & 0 deletions bindings/docstrings/trackermetadoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,28 @@ namespace pydsdoc
constexpr const char* cast=R"pyds(cast given object/data to :class:`NvDsTargetMiscDataBatch`, call pyds.NvDsTargetMiscDataBatch.cast(data))pyds";
}

namespace NvDsObjReidDoc
{
constexpr const char* descr = R"pyds(
Holds Reid Vector information for an object. See :class:`NvDsObjReid` for example usage.

:ivar featureSize: *int*, ReID vector length.
)pyds";

constexpr const char* get_host_reid_vector =R"pyds(
This function converts the float* ptr_host to a NumPy array (py::array_t<float>).
It constructs a NumPy array with the shape defined by featureSize and the data provided by ptr_host without copying the data. The array uses the float* directly from the C++ struct.

:returns: Returns Host ReID vector as NumPy array)pyds";

constexpr const char* get_dev_reid_vector =R"pyds(
This function converts the float* ptr_dev to a NumPy array (py::array_t<float>).
It constructs a NumPy array with the shape defined by featureSize and the data provided by ptr_dev without copying the data. The array uses the float* directly from the C++ struct.

:returns: Returns Device ReID vector as NumPy array)pyds";

constexpr const char* cast=R"pyds(cast given object/data to :class:`NvDsObjReid`, call pyds.NvDsObjReid.cast(data))pyds";
}

}
}
1 change: 1 addition & 0 deletions bindings/include/bind/bindtrackermeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "../../docstrings/trackermetadoc.h"
#include "pyds.hpp"
#include "pybind11/numpy.h"

namespace py = pybind11;

Expand Down
6 changes: 6 additions & 0 deletions bindings/src/bindnvdsmeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace pydeepstream {
.value("NVDS_TRACKER_PAST_FRAME_META",
NVDS_TRACKER_PAST_FRAME_META,
pydsdoc::nvmeta::MetaTypeDoc::NVDS_TRACKER_PAST_FRAME_META)
.value("NVDS_TRACKER_BATCH_REID_META",
NVDS_TRACKER_BATCH_REID_META,
pydsdoc::nvmeta::MetaTypeDoc::NVDS_TRACKER_BATCH_REID_META)
.value("NVDS_TRACKER_OBJ_REID_META",
NVDS_TRACKER_OBJ_REID_META,
pydsdoc::nvmeta::MetaTypeDoc::NVDS_TRACKER_OBJ_REID_META)
.value("NVDS_AUDIO_BATCH_META", NVDS_AUDIO_BATCH_META,
pydsdoc::nvmeta::MetaTypeDoc::NVDS_AUDIO_BATCH_META)
.value("NVDS_AUDIO_FRAME_META", NVDS_AUDIO_FRAME_META,
Expand Down
34 changes: 34 additions & 0 deletions bindings/src/bindtrackermeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ namespace py = pybind11;

namespace pydeepstream {

py::array_t<float> get_host_reid_vector(NvDsObjReid& obj_reid) {
// Convert the float* ptr_host to a NumPy array without copying
return py::array_t<float>(
{obj_reid.featureSize}, // Shape of the array
{sizeof(float)}, // Stride of the array
obj_reid.ptr_host // Data pointer (ptr_host from C++)
);
}

py::array_t<float> get_dev_reid_vector(NvDsObjReid& obj_reid) {
// Convert the float* ptr_host to a NumPy array without copying
return py::array_t<float>(
{obj_reid.featureSize}, // Shape of the array
{sizeof(float)}, // Stride of the array
obj_reid.ptr_dev // Data pointer (ptr_host from C++)
);
}

void bindtrackermeta(py::module &m) {
/*Start of Bindings for nvds_tracker_meta.h*/
py::class_<NvDsTargetMiscDataFrame>(m, "NvDsTargetMiscDataFrame",
Expand Down Expand Up @@ -115,6 +133,22 @@ namespace pydeepstream {
py::keep_alive<0, 1>(), py::return_value_policy::reference,
pydsdoc::trackerdoc::NvDsTargetMiscDataBatchDoc::list);

py::class_<NvDsObjReid>(m, "NvDsObjReid",
pydsdoc::trackerdoc::NvDsObjReidDoc::descr)
.def(py::init<>())
.def_readwrite("featureSize",
&NvDsObjReid::featureSize)
// Expose a method to get the ReID vector as a NumPy array
.def("get_host_reid_vector", &get_host_reid_vector, "Returns Host ReID vector as NumPy array")
.def("get_dev_reid_vector", &get_dev_reid_vector, "Returns Dev ReID vector as NumPy array")

.def("cast",
[](void *data) {
return (NvDsObjReid *) data;
},
py::return_value_policy::reference,
pydsdoc::trackerdoc::NvDsObjReidDoc::cast);

}

}