forked from luxonis/depthai-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_bindings.cpp
More file actions
88 lines (76 loc) · 3 KB
/
py_bindings.cpp
File metadata and controls
88 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <exception>
#include <fstream>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <vector>
// pybind11
#include "pybind11_common.hpp"
// depthai-core
#include "depthai/build/version.hpp"
// project
#include "depthai/depthai.hpp"
#include "pipeline/AssetManagerBindings.hpp"
#include "pipeline/PipelineBindings.hpp"
#include "pipeline/CommonBindings.hpp"
#include "pipeline/NodeBindings.hpp"
#include "XLinkBindings.hpp"
#include "DeviceBindings.hpp"
#include "CalibrationHandlerBindings.hpp"
#include "DeviceBootloaderBindings.hpp"
#include "DatatypeBindings.hpp"
#include "DataQueueBindings.hpp"
#include "openvino/OpenVINOBindings.hpp"
#include "log/LogBindings.hpp"
PYBIND11_MODULE(depthai, m)
{
// Depthai python version consists of: (depthai-core).(bindings revision)[+bindings hash]
m.attr("__version__") = DEPTHAI_PYTHON_VERSION;
m.attr("__commit__") = DEPTHAI_PYTHON_COMMIT_HASH;
m.attr("__commit_datetime__") = DEPTHAI_PYTHON_COMMIT_DATETIME;
m.attr("__build_datetime__") = DEPTHAI_PYTHON_BUILD_DATETIME;
// Add bindings
std::deque<StackFunction> callstack;
callstack.push_front(&DatatypeBindings::bind);
callstack.push_front(&LogBindings::bind);
callstack.push_front(&DataQueueBindings::bind);
callstack.push_front(&OpenVINOBindings::bind);
callstack.push_front(&AssetManagerBindings::bind);
callstack.push_front(&NodeBindings::bind);
callstack.push_front(&PipelineBindings::bind);
callstack.push_front(&XLinkBindings::bind);
callstack.push_front(&DeviceBindings::bind);
callstack.push_front(&DeviceBootloaderBindings::bind);
callstack.push_front(&CalibrationHandlerBindings::bind);
// end of the callstack
callstack.push_front([](py::module &, void *) {});
Callstack callstackAdapter(callstack);
// Initial call
CommonBindings::bind(m, &callstackAdapter);
// Install signal handler option
bool installSignalHandler = true;
constexpr static const char* signalHandlerKey = "DEPTHAI_INSTALL_SIGNAL_HANDLER";
try {
auto sysModule = py::module_::import("sys");
if(py::hasattr(sysModule, signalHandlerKey)){
installSignalHandler = installSignalHandler && sysModule.attr(signalHandlerKey).cast<bool>();
}
} catch (...) {
// ignore
}
try {
auto builtinsModule = py::module_::import("builtins");
if(py::hasattr(builtinsModule, signalHandlerKey)){
installSignalHandler = installSignalHandler && builtinsModule.attr(signalHandlerKey).cast<bool>();
}
} catch (...){
// ignore
}
// Call dai::initialize on 'import depthai' to initialize asap with additional information to print
try {
dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME, installSignalHandler);
} catch (const std::exception&) {
// ignore, will be initialized later on if possible
}
}