diff --git a/bindings/docstrings/nvdsmetadoc.h b/bindings/docstrings/nvdsmetadoc.h index bf222a2..fd8ca05 100644 --- a/bindings/docstrings/nvdsmetadoc.h +++ b/bindings/docstrings/nvdsmetadoc.h @@ -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"; diff --git a/bindings/docstrings/trackermetadoc.h b/bindings/docstrings/trackermetadoc.h index 4a35840..bb55732 100644 --- a/bindings/docstrings/trackermetadoc.h +++ b/bindings/docstrings/trackermetadoc.h @@ -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). + 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). + 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"; + } + } } \ No newline at end of file diff --git a/bindings/include/bind/bindtrackermeta.hpp b/bindings/include/bind/bindtrackermeta.hpp index a57015b..f6c3e22 100644 --- a/bindings/include/bind/bindtrackermeta.hpp +++ b/bindings/include/bind/bindtrackermeta.hpp @@ -20,6 +20,7 @@ #include "../../docstrings/trackermetadoc.h" #include "pyds.hpp" +#include "pybind11/numpy.h" namespace py = pybind11; diff --git a/bindings/src/bindnvdsmeta.cpp b/bindings/src/bindnvdsmeta.cpp index 95b0585..a42a6c6 100644 --- a/bindings/src/bindnvdsmeta.cpp +++ b/bindings/src/bindnvdsmeta.cpp @@ -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, diff --git a/bindings/src/bindtrackermeta.cpp b/bindings/src/bindtrackermeta.cpp index 672e7bb..1c38d6f 100644 --- a/bindings/src/bindtrackermeta.cpp +++ b/bindings/src/bindtrackermeta.cpp @@ -24,6 +24,24 @@ namespace py = pybind11; namespace pydeepstream { + py::array_t get_host_reid_vector(NvDsObjReid& obj_reid) { + // Convert the float* ptr_host to a NumPy array without copying + return py::array_t( + {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 get_dev_reid_vector(NvDsObjReid& obj_reid) { + // Convert the float* ptr_host to a NumPy array without copying + return py::array_t( + {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_(m, "NvDsTargetMiscDataFrame", @@ -115,6 +133,22 @@ namespace pydeepstream { py::keep_alive<0, 1>(), py::return_value_policy::reference, pydsdoc::trackerdoc::NvDsTargetMiscDataBatchDoc::list); + py::class_(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); + } }