To expose a C-style struct to Python, use the pybind11::class_ method. You must provide the module, the name of the struct, and a docstring.
Step 1: Declare the binding function
Create a header (e.g., include/bind/bindnvdsmeta.hpp) to declare the submodule binding function:
#include "pyds.hpp"
#include "../docstrings/pydocumentation.h"
namespace py = pybind11;
namespace pydeepstream {
void bindnvdsmeta(py::module &m);
}
Step 2: Define the binding function
In the corresponding source file (e.g., src/bindnvdsmeta.cpp), implement the function:
#include "bind_string_property_definitions.h"
#include "bindnvdsmeta.hpp"
namespace py = pybind11;
namespace pydeepstream {
void bindnvdsmeta(py::module &m) {
// Binding code goes here
}
}
Step 3: Bind the struct and its members
Use py::class_ to bind the struct. To expose data members (Plain Old Data types), use .def_readwrite().
void bindnvdsmeta(py::module &m) {
py::class_<NvDsObjectMeta>(m, "NvDsObjectMeta",
pydsdoc::nvmeta::ObjectMetaDoc::descr)
.def(py::init<>()) // Constructor wrapper
.def_readwrite("base_meta", &NvDsObjectMeta::base_meta);
}
Note: If you bind a member that is itself a struct (like base_meta), you will only be able to access its internal members in Python once that specific struct type is also bound.
void bindnvdsmeta(py::module &m) {
py::class_<NvDsObjectMeta>(m, "NvDsObjectMeta",
pydsdoc::nvmeta::ObjectMetaDoc::descr)
.def(py::init<>()); // Constructor wrapper, empty for struct
.def_readwrite("base_meta", &NvDsObjectMeta::base_meta);
}