Skip to content

Commit 4eef93c

Browse files
committed
Merge branch 'develop' into refactor
2 parents 6056f9f + bcce692 commit 4eef93c

File tree

5 files changed

+65
-68
lines changed

5 files changed

+65
-68
lines changed

src/device_bindings.cpp

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
//std
44
#include <iostream>
55

6+
7+
//depthai-core
8+
#include "depthai/host_capture_command.hpp"
9+
10+
//depthai-shared
11+
#include "depthai-shared/metadata/capture_metadata.hpp"
12+
13+
614
//project
715
#include <pybind11/stl.h>
816
#include <boost/algorithm/string/replace.hpp>
917

1018

1119

20+
1221
// Binding for HostDataPacket
1322
namespace py = pybind11;
1423

@@ -42,45 +51,32 @@ void init_binding_device(pybind11::module& m){
4251
"get_available_streams",
4352
&Device::get_available_streams,
4453
"Returns available streams, that possible to retreive from the device."
45-
);
46-
47-
}
48-
49-
50-
51-
/*
52-
53-
class PyDevice {
54-
public:
55-
56-
PyDevice(std::string a, std::string b){
57-
device = std::make_unique<Device>(a, b);
58-
}
59-
~PyDevice(){
60-
device = nullptr;
61-
}
62-
63-
std::unique_ptr<Device> device;
64-
65-
66-
std::shared_ptr<CNNHostPipeline> create_pipeline(py::dict config){
54+
)
55+
.def(
56+
"request_jpeg",
57+
&Device::request_jpeg,
58+
"Function to request a still JPEG encoded image ('jpeg' stream must be enabled)"
59+
)
60+
.def(
61+
"request_af_trigger",
62+
&Device::request_af_trigger,
63+
"Function to request autofocus trigger"
64+
)
65+
.def(
66+
"request_af_mode",
67+
&Device::request_af_mode,
68+
"Function to request a certain autofocus mode (Check 'AutofocusMode.__members__')"
69+
)
70+
;
6771

68-
// str(dict) for string representation uses ['] , but JSON requires ["]
69-
// fast & dirty solution:
70-
std::string str = py::str(config);
71-
boost::replace_all(str, "\'", "\"");
72-
boost::replace_all(str, "None", "null");
73-
boost::replace_all(str, "True", "true");
74-
boost::replace_all(str, "False", "false");
75-
// TODO: make better json serialization
7672

77-
return device->create_pipeline(str);
78-
}
73+
py::enum_<CaptureMetadata::AutofocusMode>(m, "AutofocusMode")
74+
.value("AF_MODE_AUTO", CaptureMetadata::AutofocusMode::AF_MODE_AUTO)
75+
.value("AF_MODE_MACRO", CaptureMetadata::AutofocusMode::AF_MODE_MACRO)
76+
.value("AF_MODE_CONTINUOUS_VIDEO", CaptureMetadata::AutofocusMode::AF_MODE_CONTINUOUS_VIDEO)
77+
.value("AF_MODE_CONTINUOUS_PICTURE", CaptureMetadata::AutofocusMode::AF_MODE_CONTINUOUS_PICTURE)
78+
.value("AF_MODE_EDOF", CaptureMetadata::AutofocusMode::AF_MODE_EDOF)
79+
;
7980

80-
81-
void create_pipeline(py::dict config){
82-
std::cout << "CNNHostPipeline creationg" << std::endl;
83-
}
81+
}
8482

85-
};
86-
*/

src/host_data_packet_bindings.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
//std
44
#include <iostream>
55

6+
//depthai-shared
7+
#include "depthai-shared/object_tracker/object_tracker.hpp"
8+
69
// Binding for HostDataPacket
710
namespace py = pybind11;
811

912

1013
void init_binding_host_data_packet(pybind11::module& m){
1114

15+
1216
// for PACKET in data_packets:
1317
py::class_<HostDataPacket, std::shared_ptr<HostDataPacket>>(m, "DataPacket")
1418
.def_readonly("stream_name", &HostDataPacket::stream_name)
1519
.def("size", &HostDataPacket::size)
1620
.def("getData", static_cast<py::array* (HostDataPacket::*)()>(&PyHostDataPacket::getPythonNumpyArray), py::return_value_policy::take_ownership)
1721
.def("getDataAsStr", &HostDataPacket::getDataAsString, py::return_value_policy::take_ownership)
1822
.def("getMetadata", &HostDataPacket::getMetadata)
23+
.def("getObjectTracker", &HostDataPacket::getObjectTracker, py::return_value_policy::take_ownership)
1924
;
2025

2126

22-
// FrameMetadata struct binding
27+
// FrameMetadata struct binding
2328
py::class_<FrameMetadata>(m, "FrameMetadata")
2429
.def(py::init<>())
2530
.def("getTimestamp", &FrameMetadata::getTimestamp)
@@ -31,9 +36,28 @@ void init_binding_host_data_packet(pybind11::module& m){
3136
.def("getCategory", &FrameMetadata::getCategory)
3237
.def("getInstanceNum", &FrameMetadata::getInstanceNum)
3338
.def("getSequenceNum", &FrameMetadata::getSequenceNum)
39+
.def("getCameraName", &FrameMetadata::getCameraName)
3440
;
3541

3642

43+
// ObjectTracker struct binding
44+
py::class_<ObjectTracker>(m, "ObjectTracker")
45+
.def(py::init<>())
46+
.def("__len__", &ObjectTracker::getNrTracklets)
47+
.def("getNrTracklets", &ObjectTracker::getNrTracklets)
48+
.def("getTracklet", &ObjectTracker::getTracklet)
49+
;
50+
51+
py::class_<Tracklet>(m, "Tracklet")
52+
.def("getId", &Tracklet::getId)
53+
.def("getLabel", &Tracklet::getLabel)
54+
.def("getStatus", &Tracklet::getStatus)
55+
.def("getLeftCoord", &Tracklet::getLeftCoord)
56+
.def("getTopCoord", &Tracklet::getTopCoord)
57+
.def("getRightCoord", &Tracklet::getRightCoord)
58+
.def("getBottomCoord", &Tracklet::getBottomCoord)
59+
;
60+
3761
}
3862

3963

src/nnet_packet_bindings.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace py = pybind11;
1212

1313
void init_binding_nnet_packet(pybind11::module& m){
1414

15-
15+
1616
// NNET_PACKETS, data_packets = p.get_available_nnet_and_data_packets()
1717
py::class_<std::list<std::shared_ptr<NNetPacket>>>(m, "NNetPacketList")
1818
.def(py::init<>())
@@ -23,14 +23,12 @@ void init_binding_nnet_packet(pybind11::module& m){
2323
}, py::keep_alive<0, 1>()) /* Keep list alive while iterator is used */
2424
;
2525

26-
27-
28-
2926
// for NNET_PACKET in nnet_packets:
3027
py::class_<NNetPacket, std::shared_ptr<NNetPacket>>(m, "NNetPacket")
3128
.def("get_tensor", static_cast<py::array* (NNetPacket::*)(unsigned)>(&PyNNetPacket::getTensor), py::return_value_policy::copy)
3229
.def("get_tensor", static_cast<py::array* (NNetPacket::*)(const std::string&)>(&PyNNetPacket::getTensorByName), py::return_value_policy::copy)
3330
.def("entries", &NNetPacket::getTensorEntryContainer, py::return_value_policy::copy)
31+
.def("getMetadata", &NNetPacket::getMetadata, py::return_value_policy::copy)
3432
;
3533

3634
}
@@ -53,3 +51,4 @@ pybind11::array* PyNNetPacket::getTensorByName(const std::string &name)
5351
return getTensor(it->second);
5452
}
5553
}
54+

src/py_bindings.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,15 @@
1818
// depthai-core
1919
#include "depthai/device.hpp"
2020

21+
// project
2122
#include "host_data_packet_bindings.hpp"
2223
#include "nnet_packet_bindings.hpp"
2324
#include "py_tensor_entry_container_iterator.hpp"
2425
#include "device_bindings.hpp"
2526

26-
/*
27-
#include "device_support_listener.hpp"
28-
#include "host_data_packet.hpp"
29-
#include "host_data_reader.hpp"
30-
#include "nnet/tensor_info.hpp"
31-
#include "nnet/tensor_info_helper.hpp"
32-
#include "nnet/tensor_entry.hpp"
33-
#include "nnet/nnet_packet.hpp"
34-
#include "nnet/tensor_entry_container.hpp"
35-
#include "pipeline/host_pipeline.hpp"
36-
#include "pipeline/host_pipeline_config.hpp"
37-
#include "pipeline/cnn_host_pipeline.hpp"
38-
#include "disparity_stream_post_processor.hpp"
39-
#include "host_json_helper.hpp"
40-
#include "depthai-shared/cnn_info.hpp"
41-
#include "depthai-shared/depthai_constants.hpp"
42-
#include "depthai-shared/json_helper.hpp"
43-
//#include "depthai-shared/version.hpp"
44-
#include "depthai-shared/xlink/xlink_wrapper.hpp"
45-
46-
47-
*/
4827

4928
namespace py = pybind11;
5029

51-
5230
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<HostDataPacket>>);
5331
PYBIND11_MAKE_OPAQUE(std::list<std::shared_ptr<NNetPacket>>);
5432

@@ -127,7 +105,7 @@ PYBIND11_MODULE(depthai,m)
127105
.def("get_available_data_packets", &HostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
128106
;
129107

130-
py::class_<CNNHostPipeline>(m, "CNNPipeline")
108+
py::class_<CNNHostPipeline, std::shared_ptr<CNNHostPipeline>>(m, "CNNPipeline")
131109
.def("get_available_data_packets", &CNNHostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
132110
.def("get_available_nnet_and_data_packets", &CNNHostPipeline::getAvailableNNetAndDataPackets, py::return_value_policy::copy)
133111
;

0 commit comments

Comments
 (0)