Skip to content

Commit e83f12b

Browse files
committed
Fixed bindings
1 parent 4eef93c commit e83f12b

12 files changed

+70
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build*/*
77
shared/version.hpp
88

99
#pybind11
10+
pybind11-2.5.0/
1011
build/
1112
dist/
1213
_build/

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include("cmake/HunterGate.cmake")
1010
HunterGate(
1111
URL "https://github.com/cpp-pm/hunter/archive/v0.23.253.tar.gz"
1212
SHA1 "88ea6d37c897a81a080eb9ae0f69d7807bbb3c73"
13-
FILEPATH ${CMAKE_CURRENT_LIST_DIR}/depthai-core/cmake/Hunter/config.cmake # Add depthai-cpp config (hunter limitation)
13+
FILEPATH ${CMAKE_CURRENT_LIST_DIR}/depthai-core/cmake/Hunter/config.cmake # Add depthai-core config (hunter limitation)
1414
)
1515

1616
# Move binary dir if windows, to shorten the path

src/device_bindings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ void init_binding_device(pybind11::module& m){
6767
&Device::request_af_mode,
6868
"Function to request a certain autofocus mode (Check 'AutofocusMode.__members__')"
6969
)
70+
.def(
71+
"get_nn_to_depth_bbox_mapping",
72+
&Device::get_nn_to_depth_bbox_mapping,
73+
"Returns NN bounding-box to depth mapping as a dict of coords: off_x, off_y, max_w, max_h."
74+
)
75+
76+
77+
7078
;
7179

7280

src/device_bindings.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
//pybind11
4+
#include "pybind11_common.hpp"
5+
46
#include <pybind11/pybind11.h>
57
#include <pybind11/numpy.h>
68

src/host_data_packet_bindings.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
#include "depthai-shared/object_tracker/object_tracker.hpp"
88

99
// Binding for HostDataPacket
10+
#include "pybind11/stl.h" // bindings for boost::optional
1011
namespace py = pybind11;
1112

13+
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<HostDataPacket>>);
1214

1315
void init_binding_host_data_packet(pybind11::module& m){
1416

15-
17+
1618
// for PACKET in data_packets:
1719
py::class_<HostDataPacket, std::shared_ptr<HostDataPacket>>(m, "DataPacket")
1820
.def_readonly("stream_name", &HostDataPacket::stream_name)
@@ -24,6 +26,17 @@ void init_binding_host_data_packet(pybind11::module& m){
2426
;
2527

2628

29+
// DataPacketList
30+
py::class_<std::list<std::shared_ptr<HostDataPacket>>>(m, "DataPacketList")
31+
.def(py::init<>())
32+
.def("__len__", [](const std::list<std::shared_ptr<HostDataPacket>> &v) { return v.size(); })
33+
.def("__iter__", [](std::list<std::shared_ptr<HostDataPacket>> &v)
34+
{
35+
return py::make_iterator(v.begin(), v.end());
36+
}, py::keep_alive<0, 1>()) /* Keep list alive while iterator is used */
37+
;
38+
39+
2740
// FrameMetadata struct binding
2841
py::class_<FrameMetadata>(m, "FrameMetadata")
2942
.def(py::init<>())

src/host_data_packet_bindings.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
//pybind11
4+
#include "pybind11_common.hpp"
5+
46
#include <pybind11/pybind11.h>
57
#include <pybind11/numpy.h>
68

src/nnet_packet_bindings.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
//project
99
#include "host_data_packet_bindings.hpp"
1010

11+
#include "pybind11/stl.h" // bindings for boost::optional
1112
namespace py = pybind11;
1213

14+
15+
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<NNetPacket>>);
16+
1317
void init_binding_nnet_packet(pybind11::module& m){
1418

15-
16-
// NNET_PACKETS, data_packets = p.get_available_nnet_and_data_packets()
19+
// NNET_PACKETS, data_packets = p.get_available_nnet_and_data_packets()
1720
py::class_<std::list<std::shared_ptr<NNetPacket>>>(m, "NNetPacketList")
1821
.def(py::init<>())
1922
.def("__len__", [](const std::list<std::shared_ptr<NNetPacket>> &v) { return v.size(); })
@@ -23,6 +26,7 @@ void init_binding_nnet_packet(pybind11::module& m){
2326
}, py::keep_alive<0, 1>()) /* Keep list alive while iterator is used */
2427
;
2528

29+
2630
// for NNET_PACKET in nnet_packets:
2731
py::class_<NNetPacket, std::shared_ptr<NNetPacket>>(m, "NNetPacket")
2832
.def("get_tensor", static_cast<py::array* (NNetPacket::*)(unsigned)>(&PyNNetPacket::getTensor), py::return_value_policy::copy)

src/nnet_packet_bindings.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
//pybind11
4+
#include "pybind11_common.hpp"
5+
46
#include <pybind11/pybind11.h>
57
#include <pybind11/numpy.h>
68

src/py_bindings.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <string>
77
#include <vector>
88

9+
#include "pybind11_common.hpp"
10+
11+
912
#ifdef _MSC_VER
1013
#define HAVE_SNPRINTF
1114
#endif
@@ -25,12 +28,9 @@
2528
#include "device_bindings.hpp"
2629

2730

28-
namespace py = pybind11;
29-
30-
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<HostDataPacket>>);
31-
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<NNetPacket>>);
3231

3332

33+
namespace py = pybind11;
3434
PYBIND11_MODULE(depthai,m)
3535
{
3636

@@ -47,18 +47,6 @@ PYBIND11_MODULE(depthai,m)
4747
m.attr("__dev_version__") = "badf00d";
4848

4949

50-
// nnet_packets, DATA_PACKETS = p.get_available_nnet_and_data_packets()
51-
py::class_<std::list<std::shared_ptr<HostDataPacket>>>(m, "DataPacketList")
52-
.def(py::init<>())
53-
.def("__len__", [](const std::list<std::shared_ptr<HostDataPacket>> &v) { return v.size(); })
54-
.def("__iter__", [](std::list<std::shared_ptr<HostDataPacket>> &v)
55-
{
56-
return py::make_iterator(v.begin(), v.end());
57-
}, py::keep_alive<0, 1>()) /* Keep list alive while iterator is used */
58-
;
59-
60-
61-
6250
// for te in nnet_packet.ENTRIES()
6351
py::class_<TensorEntryContainer, std::shared_ptr<TensorEntryContainer>>(m, "TensorEntryContainer")
6452
.def("__len__", &TensorEntryContainer::size)
@@ -102,12 +90,12 @@ PYBIND11_MODULE(depthai,m)
10290

10391

10492
py::class_<HostPipeline>(m, "Pipeline")
105-
.def("get_available_data_packets", &HostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
93+
.def("get_available_data_packets", &HostPipeline::getAvailableDataPackets, py::arg("blocking") = false, py::return_value_policy::copy)
10694
;
10795

10896
py::class_<CNNHostPipeline, std::shared_ptr<CNNHostPipeline>>(m, "CNNPipeline")
109-
.def("get_available_data_packets", &CNNHostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
110-
.def("get_available_nnet_and_data_packets", &CNNHostPipeline::getAvailableNNetAndDataPackets, py::return_value_policy::copy)
97+
.def("get_available_data_packets", &CNNHostPipeline::getAvailableDataPackets, py::arg("blocking") = false, py::return_value_policy::copy)
98+
.def("get_available_nnet_and_data_packets", &CNNHostPipeline::getAvailableNNetAndDataPackets, py::arg("blocking") = false, py::return_value_policy::copy)
11199
;
112100

113101

0 commit comments

Comments
 (0)