Tag Archives: Gstreamer

(self: pyds.NvDsComp_BboxInfo) -> _NvBbox_Coords

Article catalog

Project scenario and Problem Description: Cause Analysis: solution:

Project scenario and Problem Description:

Call Python deepstream API and rewrite deepstream_ test_ 3. Py , the following error is reported:

TypeError: Unable to convert function return value to a Python type! The signature was
(self: pyds.NvDsComp_BboxInfo) -> _NvBbox_Coords

The box system configuration used this time is as follows:


Cause analysis:

Nvdscomp is missing from the current bindings_ Bboxinfo’s bindings, but you can follow this GitHub page https://github.com/mrtj/pyds_ tracker_ Similar steps published in meta create your own bindings.

Solution:

1. Download the file in the above link and unzip
2. Add pyds_ tracker_ Meta.cpp replace with pyds_ bbox_ Meta.cpp , the specific code is as follows:

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "nvdsmeta.h"
#include <iostream>
#include "nvll_osd_struct.h"
#include <pybind11/numpy.h>
using namespace std;
namespace py = pybind11;

PYBIND11_MODULE(pyds_bbox_meta, m) {
    m.doc() = "pybind11 wrapper to access Nvidia DeepStream detector bbox";

#define STRING_CHAR_ARRAY(TYPE, FIELD)                             \
        [](const TYPE &self)->string {                             \
            return string(self.FIELD);                             \
        },                                                         \
        [](TYPE &self, std::string str) {                          \
            int strSize = str.size();                              \
            str.copy(self.FIELD, strSize);                         \
        },                                                         \
        py::return_value_policy::reference

	py::class_<NvDsObjectMeta>(m,"NvDsObjectMeta",py::module_local())
                .def(py::init<>())
                .def_readwrite("base_meta", &NvDsObjectMeta::base_meta)
       
                .def_readwrite("parent", &NvDsObjectMeta::parent)
        
                .def_readwrite("unique_component_id", &NvDsObjectMeta::unique_component_id)
       
                .def_readwrite("class_id", &NvDsObjectMeta::class_id)        
        
                .def_readwrite("object_id", &NvDsObjectMeta::object_id)
        
                .def_readwrite("detector_bbox_info",&NvDsObjectMeta::detector_bbox_info)

                .def_readwrite("tracker_bbox_info",&NvDsObjectMeta::tracker_bbox_info) 
            
                .def_readwrite("confidence", &NvDsObjectMeta::confidence)

                .def_readwrite("tracker_confidence",&NvDsObjectMeta::tracker_confidence)
        
                .def_readwrite("rect_params", &NvDsObjectMeta::rect_params)

                .def_readwrite("mask_params",&NvDsObjectMeta::mask_params)
	
         
                .def_readwrite("text_params", &NvDsObjectMeta::text_params)
                
                .def("cast",[](void *data) {
                        return (NvDsObjectMeta*)data;},
                        py::return_value_policy::reference)
        
                .def_property("obj_label", STRING_CHAR_ARRAY(NvDsObjectMeta, obj_label))
                .def_readwrite("classifier_meta_list", &NvDsObjectMeta::classifier_meta_list)        
     
                .def_readwrite("obj_user_meta_list", &NvDsObjectMeta::obj_user_meta_list)
                .def_property("misc_obj_info",
				[](NvDsObjectMeta &self)->py::array {
					auto dtype=py::dtype(py::format_descriptor<int>::format());
                    auto base=py::array(dtype, {MAX_USER_FIELDS}, {sizeof(int)});
                    return py::array(dtype,{MAX_USER_FIELDS}, {sizeof(int)}, self.misc_obj_info,base);
				}, [](NvDsObjectMeta& self){})
                .def_property("reserved",
				[](NvDsObjectMeta &self)->py::array {
					auto dtype=py::dtype(py::format_descriptor<int>::format());
                    auto base=py::array(dtype, {MAX_RESERVED_FIELDS}, {sizeof(int)});
                    return py::array(dtype,{MAX_RESERVED_FIELDS}, {sizeof(int)}, self.reserved,base);
				}, [](NvDsObjectMeta& self){});

	py::class_<NvOSD_RectParams>(m,"NvOSD_RectParams",py::module_local())
                .def(py::init<>())
                .def_readwrite("left",&NvOSD_RectParams::left)
                .def_readwrite("top",&NvOSD_RectParams::top)
                .def_readwrite("width",&NvOSD_RectParams::width)
                .def_readwrite("height",&NvOSD_RectParams::height)
                .def_readwrite("border_width",&NvOSD_RectParams::border_width)
                .def_readwrite("border_color",&NvOSD_RectParams::border_color)
                .def_readwrite("has_bg_color",&NvOSD_RectParams::has_bg_color)
                .def_readwrite("reserved",&NvOSD_RectParams::reserved)
                .def_readwrite("bg_color",&NvOSD_RectParams::bg_color)
                .def_readwrite("has_color_info",&NvOSD_RectParams::has_color_info)
                .def_readwrite("color_id",&NvOSD_RectParams::color_id);
	py::class_<NvDsComp_BboxInfo>(m,"NvDsComp_BboxInfo",py::module_local())
                .def(py::init<>())

                .def_readwrite("org_bbox_coords",&NvDsComp_BboxInfo::org_bbox_coords);

	 py::class_<NvBbox_Coords>(m,"NvBbox_Coords",py::module_local())
            .def(py::init<>())
            .def_readwrite("left",&NvBbox_Coords::left)
            .def_readwrite("top",&NvBbox_Coords::top)
            .def_readwrite("width",&NvBbox_Coords::width)
            .def_readwrite("height",&NvBbox_Coords::height);
}

3. Change the relevant contents of build. Sh :

4. Change the relevant contents of setup. Py :

5. Run bash./build. Sh
6. Run Python setup. Py install (if necessary, use sudo or python3)
after completion, pyds will be generated_ bbox_ Meta.so file and build folder

7. In the original Python code, Import pyds_ bbox_ Meta , and the original obj_ meta = pyds.NvDsObjectMeta.cast(l_ Obj. Data) changed to obj_ meta = pyds_ bbox_ meta.NvDsObjectMeta.cast(l_ obj.data)

Examples are given below:

import pyds_bbox_meta
...  # add rest of callback code here
obj_meta=pyds_bbox_meta.NvDsObjectMeta.cast(l_obj.data)
det_info_left = obj_meta.detector_bbox_info.org_bbox_coords.left
det_info_top = obj_meta.detector_bbox_info.org_bbox_coords.top

If reading this article is useful to you, please pay attention to it and like the collection
July 23, 2021 17:39:31