From b6972a86aa4028d0809574abd80f7720d736c633 Mon Sep 17 00:00:00 2001 From: amarflybot Date: Wed, 18 Sep 2024 17:52:35 +0530 Subject: [PATCH 1/3] Add pyBindings for NVDS_TRACKER_OBJ_REID_META --- bindings/docstrings/nvdsmetadoc.h | 4 +++ bindings/docstrings/trackermetadoc.h | 23 +++++++++++++++ bindings/include/bind/bindtrackermeta.hpp | 1 + bindings/src/bindnvdsmeta.cpp | 6 ++++ bindings/src/bindtrackermeta.cpp | 34 +++++++++++++++++++++++ 5 files changed, 68 insertions(+) diff --git a/bindings/docstrings/nvdsmetadoc.h b/bindings/docstrings/nvdsmetadoc.h index bf222a2..eec7866 100644 --- a/bindings/docstrings/nvdsmetadoc.h +++ b/bindings/docstrings/nvdsmetadoc.h @@ -44,6 +44,10 @@ 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_TRACKER_TERMINATED_LIST_META=R"pyds(Information on all terminated Tracks. )pyds"; + constexpr const char* NVDS_TRACKER_SHADOW_LIST_META=R"pyds(Information on all terminated Tracks.)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..97800ab 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); + } } From 42039a9c8d87058b27e147c811581940b3511ce5 Mon Sep 17 00:00:00 2001 From: amarflybot Date: Wed, 18 Sep 2024 17:59:38 +0530 Subject: [PATCH 2/3] Remove other Meta which are not implemented yet --- bindings/docstrings/nvdsmetadoc.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/docstrings/nvdsmetadoc.h b/bindings/docstrings/nvdsmetadoc.h index eec7866..fd8ca05 100644 --- a/bindings/docstrings/nvdsmetadoc.h +++ b/bindings/docstrings/nvdsmetadoc.h @@ -46,8 +46,6 @@ namespace pydsdoc 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_TRACKER_TERMINATED_LIST_META=R"pyds(Information on all terminated Tracks. )pyds"; - constexpr const char* NVDS_TRACKER_SHADOW_LIST_META=R"pyds(Information on all terminated Tracks.)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"; From 7cf277cf55423d5da2fcad313b221cb4ea739dc0 Mon Sep 17 00:00:00 2001 From: amarflybot Date: Wed, 18 Sep 2024 18:01:21 +0530 Subject: [PATCH 3/3] Formatting fixes for doc --- bindings/docstrings/trackermetadoc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/docstrings/trackermetadoc.h b/bindings/docstrings/trackermetadoc.h index 97800ab..bb55732 100644 --- a/bindings/docstrings/trackermetadoc.h +++ b/bindings/docstrings/trackermetadoc.h @@ -135,13 +135,13 @@ namespace pydsdoc 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"; + :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"; + :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"; }